more dependencies removed

This commit is contained in:
Milos Kozak 2020-01-03 10:31:42 +01:00
parent c16131bfc8
commit c88058752f
14 changed files with 63 additions and 45 deletions

View file

@ -101,7 +101,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
actionBarDrawerToggle.syncState();
// initialize screen wake lock
processPreferenceChange(new EventPreferenceChange(R.string.key_keep_screen_on));
processPreferenceChange(new EventPreferenceChange(resourceHelper.gs(R.string.key_keep_screen_on)));
final ViewPager viewPager = findViewById(R.id.pager);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@ -189,7 +189,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
}
public void processPreferenceChange(final EventPreferenceChange ev) {
if (ev.isChanged(R.string.key_keep_screen_on))
if (ev.isChanged(resourceHelper, R.string.key_keep_screen_on))
setWakeLock();
}

View file

@ -1,6 +1,8 @@
package info.nightscout.androidaps.events
import android.content.res.Resources
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.utils.resources.ResourceHelper
class EventPreferenceChange : Event {
private var changedKey: String? = null
@ -9,11 +11,21 @@ class EventPreferenceChange : Event {
changedKey = key
}
constructor(resourceID: Int) {
changedKey = MainApp.gs(resourceID)
constructor(resourceHelper: ResourceHelper, resourceID: Int) {
changedKey = resourceHelper.gs(resourceID)
}
fun isChanged(id: Int): Boolean {
return changedKey == MainApp.gs(id)
@Deprecated("use injected version")
constructor(resources: Resources, id: Int) {
changedKey == resources.getString(id)
}
fun isChanged(resourceHelper: ResourceHelper, id: Int): Boolean {
return changedKey == resourceHelper.gs(id)
}
@Deprecated("use injected version")
fun isChanged(resources: Resources, id: Int): Boolean {
return changedKey == resources.getString(id)
}
}

View file

@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
@ -13,10 +14,11 @@ class IobCobStaticCalculatorPlugin @Inject constructor(
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
sp: SP,
resourceHelper: ResourceHelper,
profileFunction: ProfileFunction,
configBuilderPlugin: ConfigBuilderPlugin,
treatmentsPlugin: TreatmentsPlugin
) : IobCobCalculatorPlugin(aapsLogger, rxBus, sp, profileFunction, configBuilderPlugin, treatmentsPlugin) {
) : IobCobCalculatorPlugin(aapsLogger, rxBus, sp, resourceHelper, profileFunction, configBuilderPlugin, treatmentsPlugin) {
override fun onStart() { // do not attach to rxbus
}
}

View file

@ -28,6 +28,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.json.JSONArray
@ -41,6 +42,7 @@ import javax.inject.Singleton
class AutomationPlugin @Inject constructor(
private val rxBus: RxBusWrapper,
private val aapsLogger: AAPSLogger,
private val resourceHelper: ResourceHelper,
private val mainApp: MainApp,
private val sp :SP,
private val loopPlugin: LoopPlugin
@ -83,7 +85,7 @@ class AutomationPlugin @Inject constructor(
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ e ->
if (e.isChanged(R.string.key_location)) {
if (e.isChanged(resourceHelper, R.string.key_location)) {
mainApp.stopService(Intent(mainApp, LocationService::class.java))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
mainApp.startForegroundService(Intent(mainApp, LocationService::class.java))

View file

@ -238,7 +238,7 @@ public class NSClientPlugin extends PluginBase {
public void pause(boolean newState) {
SP.putBoolean(R.string.key_nsclientinternal_paused, newState);
paused = newState;
RxBus.Companion.getINSTANCE().send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
RxBus.Companion.getINSTANCE().send(new EventPreferenceChange(MainApp.resources(), R.string.key_nsclientinternal_paused));
}
public UploadQueue queue() {

View file

@ -34,14 +34,14 @@ class NsClientReceiverDelegate {
}
void onStatusEvent(EventPreferenceChange ev) {
if (ev.isChanged(R.string.key_ns_wifionly) ||
ev.isChanged(R.string.key_ns_wifi_ssids) ||
ev.isChanged(R.string.key_ns_allowroaming)
if (ev.isChanged(MainApp.resources(), R.string.key_ns_wifionly) ||
ev.isChanged(MainApp.resources(), R.string.key_ns_wifi_ssids) ||
ev.isChanged(MainApp.resources(), R.string.key_ns_allowroaming)
) {
EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext());
if (event != null)
RxBus.Companion.getINSTANCE().send(event);
} else if (ev.isChanged(R.string.key_ns_chargingonly)) {
} else if (ev.isChanged(MainApp.resources(), R.string.key_ns_chargingonly)) {
EventChargingState event = ChargingStateReceiver.grabChargingState(MainApp.instance().getApplicationContext());
if (event != null)
RxBus.Companion.getINSTANCE().send(event);
@ -70,7 +70,7 @@ class NsClientReceiverDelegate {
boolean newAllowedState = allowedChargingState && allowedNetworkState;
if (newAllowedState != allowed) {
allowed = newAllowedState;
RxBus.Companion.getINSTANCE().send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
RxBus.Companion.getINSTANCE().send(new EventPreferenceChange(MainApp.gs(R.string.key_nsclientinternal_paused)));
}
}

View file

@ -157,9 +157,9 @@ public class NSClientService extends DaggerService {
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
if (event.isChanged(R.string.key_nsclientinternal_url) ||
event.isChanged(R.string.key_nsclientinternal_api_secret) ||
event.isChanged(R.string.key_nsclientinternal_paused)
if (event.isChanged(resourceHelper, R.string.key_nsclientinternal_url) ||
event.isChanged(resourceHelper, R.string.key_nsclientinternal_api_secret) ||
event.isChanged(resourceHelper, R.string.key_nsclientinternal_paused)
) {
latestDateInReceivedData = 0;
destroy();

View file

@ -79,31 +79,31 @@ class PersistentNotificationPlugin @Inject constructor() : PluginBase(PluginDesc
disposable.add(rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventExtendedBolusChange? -> triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
.subscribe({ triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
disposable.add(rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventTempBasalChange? -> triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
.subscribe({ triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
disposable.add(rxBus
.toObservable(EventTreatmentChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventTreatmentChange? -> triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
.subscribe({ triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
disposable.add(rxBus
.toObservable(EventInitializationChanged::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventInitializationChanged? -> triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
.subscribe({ triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
disposable.add(rxBus
.toObservable(EventNewBasalProfile::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventNewBasalProfile? -> triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
.subscribe({ triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventAutosensCalculationFinished? -> triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
.subscribe({ triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
disposable.add(rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventPreferenceChange? -> triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
.subscribe({ triggerNotificationUpdate(false) }) { FabricPrivacy.logException(it) })
triggerNotificationUpdate(true)
}

View file

@ -149,7 +149,7 @@ class SmsCommunicatorPlugin @Inject constructor(
}
private fun processSettings(ev: EventPreferenceChange?) {
if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
if (ev == null || ev.isChanged(resourceHelper, R.string.key_smscommunicator_allowednumbers)) {
val settings = sp.getString(R.string.key_smscommunicator_allowednumbers, "")
allowedNumbers.clear()
val substrings = settings.split(";").toTypedArray()

View file

@ -109,9 +109,9 @@ class TidepoolPlugin @Inject constructor(
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event ->
if (event.isChanged(R.string.key_tidepool_dev_servers)
|| event.isChanged(R.string.key_tidepool_username)
|| event.isChanged(R.string.key_tidepool_password)
if (event.isChanged(resourceHelper, R.string.key_tidepool_dev_servers)
|| event.isChanged(resourceHelper, R.string.key_tidepool_username)
|| event.isChanged(resourceHelper, R.string.key_tidepool_password)
)
tidepoolUploader.resetInstance()
}, {

View file

@ -46,6 +46,7 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@ -57,6 +58,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
private final AAPSLogger aapsLogger;
private final RxBusWrapper rxBus;
private final SP sp;
private final ResourceHelper resourceHelper;
private final ProfileFunction profileFunction;
private final ConfigBuilderPlugin configBuilderPlugin;
private final TreatmentsPlugin treatmentsPlugin;
@ -89,6 +91,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
SP sp,
ResourceHelper resourceHelper,
ProfileFunction profileFunction,
ConfigBuilderPlugin configBuilderPlugin,
TreatmentsPlugin treatmentsPlugin
@ -104,6 +107,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.sp = sp;
this.resourceHelper = resourceHelper;
this.profileFunction = profileFunction;
this.configBuilderPlugin = configBuilderPlugin;
this.treatmentsPlugin = treatmentsPlugin;
@ -158,14 +162,14 @@ public class IobCobCalculatorPlugin extends PluginBase {
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
if (event.isChanged(R.string.key_openapsama_autosens_period) ||
event.isChanged(R.string.key_age) ||
event.isChanged(R.string.key_absorption_maxtime) ||
event.isChanged(R.string.key_openapsama_min_5m_carbimpact) ||
event.isChanged(R.string.key_absorption_cutoff) ||
event.isChanged(R.string.key_openapsama_autosens_max) ||
event.isChanged(R.string.key_openapsama_autosens_min) ||
event.isChanged(R.string.key_insulin_oref_peak)
if (event.isChanged(resourceHelper, R.string.key_openapsama_autosens_period) ||
event.isChanged(resourceHelper, R.string.key_age) ||
event.isChanged(resourceHelper, R.string.key_absorption_maxtime) ||
event.isChanged(resourceHelper, R.string.key_openapsama_min_5m_carbimpact) ||
event.isChanged(resourceHelper, R.string.key_absorption_cutoff) ||
event.isChanged(resourceHelper, R.string.key_openapsama_autosens_max) ||
event.isChanged(resourceHelper, R.string.key_openapsama_autosens_min) ||
event.isChanged(resourceHelper, R.string.key_insulin_oref_peak)
) {
stopCalculation("onEventPreferenceChange");
synchronized (dataLock) {
@ -182,17 +186,13 @@ public class IobCobCalculatorPlugin extends PluginBase {
disposable.add(rxBus
.toObservable(EventAppInitialized.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event);
}, FabricPrivacy::logException)
.subscribe(event -> runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event), FabricPrivacy::logException)
);
// EventNewHistoryData
disposable.add(rxBus
.toObservable(EventNewHistoryData.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
newHistoryData(event);
}, FabricPrivacy::logException)
.subscribe(event -> newHistoryData(event), FabricPrivacy::logException)
);
}

View file

@ -117,7 +117,7 @@ class VirtualPumpPlugin @Inject constructor(
disposable += rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventPreferenceChange -> if (event.isChanged(R.string.key_virtualpump_type)) refreshConfiguration() }) { FabricPrivacy.logException(it) }
.subscribe({ event: EventPreferenceChange -> if (event.isChanged(resourceHelper, R.string.key_virtualpump_type)) refreshConfiguration() }) { FabricPrivacy.logException(it) }
refreshConfiguration()
}

View file

@ -101,7 +101,7 @@ public class SWItem {
public void run() {
if (L.isEnabled(L.CORE))
log.debug("Firing EventPreferenceChange");
RxBus.Companion.getINSTANCE().send(new EventPreferenceChange(preferenceId));
RxBus.Companion.getINSTANCE().send(new EventPreferenceChange(MainApp.resources(), preferenceId));
RxBus.Companion.getINSTANCE().send(new EventSWUpdate(false));
scheduledEventPost = null;
}

View file

@ -9,9 +9,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Locale;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
@ -125,7 +127,7 @@ public class FabricPrivacy {
.replace(".net/", ":");
MainApp.getFirebaseAnalytics().setUserProperty("Mode", BuildConfig.APPLICATION_ID + "-" + closedLoopEnabled);
MainApp.getFirebaseAnalytics().setUserProperty("Language", LocaleHelper.INSTANCE.currentLanguage());
MainApp.getFirebaseAnalytics().setUserProperty("Language", SP.getString(R.string.key_language, Locale.getDefault().getLanguage()));
MainApp.getFirebaseAnalytics().setUserProperty("Version", BuildConfig.VERSION);
MainApp.getFirebaseAnalytics().setUserProperty("HEAD", BuildConfig.HEAD);
MainApp.getFirebaseAnalytics().setUserProperty("Remote", remote);