diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 0e8f71a3d1..4a1cf1a861 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -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(); } diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventPreferenceChange.kt b/app/src/main/java/info/nightscout/androidaps/events/EventPreferenceChange.kt index d224d75df1..830667c6b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventPreferenceChange.kt +++ b/app/src/main/java/info/nightscout/androidaps/events/EventPreferenceChange.kt @@ -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) } } diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt index a005c32531..4eb7248460 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/IobCobStaticCalculatorPlugin.kt @@ -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 } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index f6cfbbf74a..77150e00d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -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)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java index aa08f79dd6..d756d3e109 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java @@ -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() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java index 2a7791ba17..2b104008c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java @@ -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))); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java index 029836b6f6..3888d52f69 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java @@ -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(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt index 51465d61f2..3ee4ca1028 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt @@ -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) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 423a138ce9..5c75e097a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -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() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt index 8436a25bfc..6153cafd37 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt @@ -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() }, { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java index 3e215b0ea1..226660be17 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java @@ -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) ); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt index cbf87338b0..56b5b65f33 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt @@ -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() } diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java index 668d33dc73..5a80148a85 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java @@ -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; } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.java b/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.java index 560c44c84e..2b0f2d4ac4 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.java @@ -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);