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(); actionBarDrawerToggle.syncState();
// initialize screen wake lock // 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); final ViewPager viewPager = findViewById(R.id.pager);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@ -189,7 +189,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
} }
public void processPreferenceChange(final EventPreferenceChange ev) { 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(); setWakeLock();
} }

View file

@ -1,6 +1,8 @@
package info.nightscout.androidaps.events package info.nightscout.androidaps.events
import android.content.res.Resources
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.utils.resources.ResourceHelper
class EventPreferenceChange : Event { class EventPreferenceChange : Event {
private var changedKey: String? = null private var changedKey: String? = null
@ -9,11 +11,21 @@ class EventPreferenceChange : Event {
changedKey = key changedKey = key
} }
constructor(resourceID: Int) { constructor(resourceHelper: ResourceHelper, resourceID: Int) {
changedKey = MainApp.gs(resourceID) changedKey = resourceHelper.gs(resourceID)
} }
fun isChanged(id: Int): Boolean { @Deprecated("use injected version")
return changedKey == MainApp.gs(id) 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.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject import javax.inject.Inject
@ -13,10 +14,11 @@ class IobCobStaticCalculatorPlugin @Inject constructor(
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rxBus: RxBusWrapper, rxBus: RxBusWrapper,
sp: SP, sp: SP,
resourceHelper: ResourceHelper,
profileFunction: ProfileFunction, profileFunction: ProfileFunction,
configBuilderPlugin: ConfigBuilderPlugin, configBuilderPlugin: ConfigBuilderPlugin,
treatmentsPlugin: TreatmentsPlugin 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 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.sharedPreferences.SP
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.extensions.plusAssign import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import org.json.JSONArray import org.json.JSONArray
@ -41,6 +42,7 @@ import javax.inject.Singleton
class AutomationPlugin @Inject constructor( class AutomationPlugin @Inject constructor(
private val rxBus: RxBusWrapper, private val rxBus: RxBusWrapper,
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
private val resourceHelper: ResourceHelper,
private val mainApp: MainApp, private val mainApp: MainApp,
private val sp :SP, private val sp :SP,
private val loopPlugin: LoopPlugin private val loopPlugin: LoopPlugin
@ -83,7 +85,7 @@ class AutomationPlugin @Inject constructor(
.toObservable(EventPreferenceChange::class.java) .toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.subscribe({ e -> .subscribe({ e ->
if (e.isChanged(R.string.key_location)) { if (e.isChanged(resourceHelper, R.string.key_location)) {
mainApp.stopService(Intent(mainApp, LocationService::class.java)) mainApp.stopService(Intent(mainApp, LocationService::class.java))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
mainApp.startForegroundService(Intent(mainApp, LocationService::class.java)) mainApp.startForegroundService(Intent(mainApp, LocationService::class.java))

View file

@ -238,7 +238,7 @@ public class NSClientPlugin extends PluginBase {
public void pause(boolean newState) { public void pause(boolean newState) {
SP.putBoolean(R.string.key_nsclientinternal_paused, newState); SP.putBoolean(R.string.key_nsclientinternal_paused, newState);
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() { public UploadQueue queue() {

View file

@ -34,14 +34,14 @@ class NsClientReceiverDelegate {
} }
void onStatusEvent(EventPreferenceChange ev) { void onStatusEvent(EventPreferenceChange ev) {
if (ev.isChanged(R.string.key_ns_wifionly) || if (ev.isChanged(MainApp.resources(), R.string.key_ns_wifionly) ||
ev.isChanged(R.string.key_ns_wifi_ssids) || ev.isChanged(MainApp.resources(), R.string.key_ns_wifi_ssids) ||
ev.isChanged(R.string.key_ns_allowroaming) ev.isChanged(MainApp.resources(), R.string.key_ns_allowroaming)
) { ) {
EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext()); EventNetworkChange event = NetworkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext());
if (event != null) if (event != null)
RxBus.Companion.getINSTANCE().send(event); 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()); EventChargingState event = ChargingStateReceiver.grabChargingState(MainApp.instance().getApplicationContext());
if (event != null) if (event != null)
RxBus.Companion.getINSTANCE().send(event); RxBus.Companion.getINSTANCE().send(event);
@ -70,7 +70,7 @@ class NsClientReceiverDelegate {
boolean newAllowedState = allowedChargingState && allowedNetworkState; boolean newAllowedState = allowedChargingState && allowedNetworkState;
if (newAllowedState != allowed) { if (newAllowedState != allowed) {
allowed = newAllowedState; 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) .toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.subscribe(event -> { .subscribe(event -> {
if (event.isChanged(R.string.key_nsclientinternal_url) || if (event.isChanged(resourceHelper, R.string.key_nsclientinternal_url) ||
event.isChanged(R.string.key_nsclientinternal_api_secret) || event.isChanged(resourceHelper, R.string.key_nsclientinternal_api_secret) ||
event.isChanged(R.string.key_nsclientinternal_paused) event.isChanged(resourceHelper, R.string.key_nsclientinternal_paused)
) { ) {
latestDateInReceivedData = 0; latestDateInReceivedData = 0;
destroy(); destroy();

View file

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

View file

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

View file

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

View file

@ -117,7 +117,7 @@ class VirtualPumpPlugin @Inject constructor(
disposable += rxBus disposable += rxBus
.toObservable(EventPreferenceChange::class.java) .toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io()) .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() refreshConfiguration()
} }

View file

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

View file

@ -9,9 +9,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import java.util.Locale;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
@ -125,7 +127,7 @@ public class FabricPrivacy {
.replace(".net/", ":"); .replace(".net/", ":");
MainApp.getFirebaseAnalytics().setUserProperty("Mode", BuildConfig.APPLICATION_ID + "-" + closedLoopEnabled); 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("Version", BuildConfig.VERSION);
MainApp.getFirebaseAnalytics().setUserProperty("HEAD", BuildConfig.HEAD); MainApp.getFirebaseAnalytics().setUserProperty("HEAD", BuildConfig.HEAD);
MainApp.getFirebaseAnalytics().setUserProperty("Remote", remote); MainApp.getFirebaseAnalytics().setUserProperty("Remote", remote);