From f6fe84808e7de155ccbc90ef0a851d769a705b92 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 7 Jan 2020 10:14:12 +0100 Subject: [PATCH] extract interfaces off ConfigBuilder extra functionality --- .../androidaps/activities/SurveyActivity.kt | 6 +- .../dependencyInjection/AppModule.kt | 7 ++ .../interfaces/ActivePluginProvider.java | 23 +++++++ .../interfaces/CommandQueueProvider.java | 11 +++ .../configBuilder/ConfigBuilderPlugin.java | 18 ++--- .../general/automation/triggers/Trigger.kt | 3 +- .../triggers/TriggerPumpLastConnection.kt | 2 +- .../PersistentNotificationPlugin.kt | 5 +- .../smsCommunicator/SmsCommunicatorPlugin.kt | 67 +++++++++---------- .../xdripStatusline/StatusLinePlugin.kt | 6 +- .../profile/local/LocalProfileFragment.kt | 5 +- .../androidaps/receivers/KeepAliveReceiver.kt | 16 +++-- .../androidaps/utils/wizard/BolusWizard.kt | 19 +++--- 13 files changed, 115 insertions(+), 73 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/interfaces/ActivePluginProvider.java create mode 100644 app/src/main/java/info/nightscout/androidaps/interfaces/CommandQueueProvider.java diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt index b840bf4f6b..8f1738f73b 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt @@ -7,9 +7,9 @@ import com.google.firebase.database.FirebaseDatabase import info.nightscout.androidaps.R import info.nightscout.androidaps.data.defaultProfile.DefaultProfile import info.nightscout.androidaps.dialogs.ProfileViewerDialog +import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -21,7 +21,7 @@ import javax.inject.Inject class SurveyActivity : NoSplashAppCompatActivity() { @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin + @Inject lateinit var activePluginProvider: ActivePluginProvider @Inject lateinit var tddCalculator: TddCalculator @Inject lateinit var tirCalculator: TirCalculator @Inject lateinit var profileFunction: ProfileFunction @@ -33,7 +33,7 @@ class SurveyActivity : NoSplashAppCompatActivity() { survey_id.text = InstanceId.instanceId() - val profileStore = configBuilderPlugin.activeProfileInterface.profile + val profileStore = activePluginProvider.activeProfileInterface.profile val profileList = profileStore?.getProfileList() ?: return survey_spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, profileList) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index e16c18cba7..c8157bac31 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -9,6 +9,8 @@ import dagger.android.ContributesAndroidInjector import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.db.BgReading +import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLoggerDebug import info.nightscout.androidaps.logging.AAPSLoggerProduction @@ -138,5 +140,10 @@ open class AppModule { @ContributesAndroidInjector fun loggerQuickWizardEntry(): QuickWizardEntry @Binds fun bindContext(mainApp: MainApp): Context + + @Binds fun bindActivePluginProvider(configBuilderPlugin: ConfigBuilderPlugin) : ActivePluginProvider + @Binds fun bindCommandQueueProvider(configBuilderPlugin: ConfigBuilderPlugin) : CommandQueueProvider + + } } diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/ActivePluginProvider.java b/app/src/main/java/info/nightscout/androidaps/interfaces/ActivePluginProvider.java new file mode 100644 index 0000000000..f8f4edd5f1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ActivePluginProvider.java @@ -0,0 +1,23 @@ +package info.nightscout.androidaps.interfaces; + +import androidx.annotation.Nullable; + +import org.jetbrains.annotations.NotNull; + +/** + * Created by adrian on 2020-01-07. + */ + +public interface ActivePluginProvider { + @Nullable BgSourceInterface getActiveBgSource(); + + @NotNull ProfileInterface getActiveProfileInterface(); + + @Nullable InsulinInterface getActiveInsulin(); + + @Nullable APSInterface getActiveAPS(); + + @Nullable PumpInterface getActivePump(); + + @Nullable SensitivityInterface getActiveSensitivity(); +} diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/CommandQueueProvider.java b/app/src/main/java/info/nightscout/androidaps/interfaces/CommandQueueProvider.java new file mode 100644 index 0000000000..eae24fce70 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/CommandQueueProvider.java @@ -0,0 +1,11 @@ +package info.nightscout.androidaps.interfaces; + +import info.nightscout.androidaps.queue.CommandQueue; + +/** + * Created by adrian on 2020-01-07. + */ + +public interface CommandQueueProvider { + CommandQueue getCommandQueue(); +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java index daa490e75c..bb2ae49bb6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.java @@ -14,7 +14,9 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventAppInitialized; import info.nightscout.androidaps.interfaces.APSInterface; +import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.BgSourceInterface; +import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; @@ -38,7 +40,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; * Created by mike on 05.08.2016. */ @Singleton -public class ConfigBuilderPlugin extends PluginBase { +public class ConfigBuilderPlugin extends PluginBase implements ActivePluginProvider, CommandQueueProvider { private static ConfigBuilderPlugin configBuilderPlugin; private final SP sp; @@ -244,37 +246,37 @@ public class ConfigBuilderPlugin extends PluginBase { } } - public CommandQueue getCommandQueue() { + @Override public CommandQueue getCommandQueue() { return commandQueue; } - @Nullable + @Override @Nullable public BgSourceInterface getActiveBgSource() { return activeBgSource; } - @NotNull + @Override @NotNull public ProfileInterface getActiveProfileInterface() { if (activeProfile != null) return activeProfile; else return localProfilePlugin.get(); } - @Nullable + @Override @Nullable public InsulinInterface getActiveInsulin() { return activeInsulin; } - @Nullable + @Override @Nullable public APSInterface getActiveAPS() { return activeAPS; } - @Nullable + @Override @Nullable public PumpInterface getActivePump() { return activePump; } - @Nullable + @Override @Nullable public SensitivityInterface getActiveSensitivity() { return activeSensitivity; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt index 475254e392..ad21334bd5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt @@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity import com.google.common.base.Optional import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin @@ -37,7 +38,7 @@ abstract class Trigger(val mainApp: MainApp) { @Inject lateinit var sp: SP @Inject lateinit var locationDataContainer: LastLocationDataContainer @Inject lateinit var treatmentsPlugin: TreatmentsPlugin - @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin + @Inject lateinit var activePluginProvider: ActivePluginProvider @Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin init { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt index 4a4e62f2c3..05ba096001 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnection.kt @@ -30,7 +30,7 @@ class TriggerPumpLastConnection(mainApp: MainApp) : Trigger(mainApp) { } override fun shouldRun(): Boolean { - val lastConnection = configBuilderPlugin.activePump?.lastDataTime() ?: return false + val lastConnection = activePluginProvider.activePump?.lastDataTime() ?: return false if (lastConnection == 0L && comparator.value === Comparator.Compare.IS_NOT_AVAILABLE) { aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) return true 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 2bdf8795b8..b1ab314df7 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 @@ -16,6 +16,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.db.DatabaseHelper import info.nightscout.androidaps.events.* +import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType @@ -41,7 +42,7 @@ class PersistentNotificationPlugin @Inject constructor( var resourceHelper: ResourceHelper, var profileFunction: ProfileFunction, var fabricPrivacy: FabricPrivacy, - var configBuilderPlugin: ConfigBuilderPlugin, + var activePlugins: ActivePluginProvider, var treatmentsPlugin: TreatmentsPlugin, var iobCobCalculatorPlugin: IobCobCalculatorPlugin, rxBus: RxBusWrapper, @@ -129,7 +130,7 @@ class PersistentNotificationPlugin @Inject constructor( } private fun updateNotification() { - val pump = configBuilderPlugin.activePump ?: return + val pump = activePlugins.activePump ?: return var line1: String? var line2: String? = null var line3: String? = null 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 78326b4f24..ef088785c1 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 @@ -18,15 +18,11 @@ import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.TempTarget import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.events.EventRefreshOverview -import info.nightscout.androidaps.interfaces.Constraint -import info.nightscout.androidaps.interfaces.PluginBase -import info.nightscout.androidaps.interfaces.PluginDescription -import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.general.nsclient.NSUpload @@ -59,7 +55,8 @@ class SmsCommunicatorPlugin @Inject constructor( rxBus: RxBusWrapper, private val profileFunction: ProfileFunction, private val fabricPrivacy: FabricPrivacy, - private val configBuilderPlugin: ConfigBuilderPlugin, + private val activePluginProvider: ActivePluginProvider, + private val commandQueueProvider: CommandQueueProvider, private val treatmentsPlugin: TreatmentsPlugin, private val loopPlugin: LoopPlugin, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin @@ -200,7 +197,7 @@ class SmsCommunicatorPlugin @Inject constructor( rxBus.send(EventSmsCommunicatorUpdateGui()) return } - val pump = configBuilderPlugin.activePump ?: return + val pump = activePluginProvider.activePump ?: return messages.add(receivedSms) aapsLogger.debug(LTag.SMS, receivedSms.toString()) val splitted = receivedSms.text.split(Regex("\\s+")).toTypedArray() @@ -302,7 +299,7 @@ class SmsCommunicatorPlugin @Inject constructor( "DISABLE", "STOP" -> { if (loopPlugin.isEnabled(PluginType.LOOP)) { loopPlugin.setPluginEnabled(PluginType.LOOP, false) - configBuilderPlugin.commandQueue.cancelTempBasal(true, object : Callback() { + commandQueueProvider.commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { rxBus.send(EventRefreshOverview("SMS_LOOP_STOP")) val replyText = resourceHelper.gs(R.string.smscommunicator_loophasbeendisabled) + " " + @@ -356,7 +353,7 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(this, resourceHelper, receivedSms, reply, passCode, object : SmsAction(duration) { override fun run() { - configBuilderPlugin.commandQueue.cancelTempBasal(true, object : Callback() { + commandQueueProvider.commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { if (result.success) { loopPlugin.suspendTo(System.currentTimeMillis() + anInteger() * 60L * 1000) @@ -367,7 +364,7 @@ class SmsCommunicatorPlugin @Inject constructor( sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcancelfailed) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) } } @@ -414,9 +411,9 @@ class SmsCommunicatorPlugin @Inject constructor( } private fun processPUMP(receivedSms: Sms) { - configBuilderPlugin.commandQueue.readStatus("SMS", object : Callback() { + commandQueueProvider.commandQueue.readStatus("SMS", object : Callback() { override fun run() { - val pump = configBuilderPlugin.activePump + val pump = activePluginProvider.activePump if (result.success) { if (pump != null) { val reply = pump.shortStatus(true) @@ -432,7 +429,7 @@ class SmsCommunicatorPlugin @Inject constructor( } private fun processPROFILE(splitted: Array, receivedSms: Sms) { // load profiles - val anInterface = configBuilderPlugin.activeProfileInterface + val anInterface = activePluginProvider.activeProfileInterface val store = anInterface.profile if (store == null) { sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.notconfigured))) @@ -488,15 +485,15 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(this, resourceHelper, receivedSms, reply, passCode, object : SmsAction() { override fun run() { - configBuilderPlugin.commandQueue.cancelTempBasal(true, object : Callback() { + commandQueueProvider.commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { if (result.success) { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalcancelfailed) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) } } @@ -518,16 +515,16 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(this, resourceHelper, receivedSms, reply, passCode, object : SmsAction(tempBasalPct, duration) { override fun run() { - configBuilderPlugin.commandQueue.tempBasalPercent(anInteger(), secondInteger(), true, profile, object : Callback() { + commandQueueProvider.commandQueue.tempBasalPercent(anInteger(), secondInteger(), true, profile, object : Callback() { override fun run() { if (result.success) { var replyText: String replyText = if (result.isPercent) String.format(resourceHelper.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration) else String.format(resourceHelper.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) } } @@ -550,16 +547,16 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(this, resourceHelper, receivedSms, reply, passCode, object : SmsAction(tempBasal, duration) { override fun run() { - configBuilderPlugin.commandQueue.tempBasalAbsolute(aDouble(), secondInteger(), true, profile, object : Callback() { + commandQueueProvider.commandQueue.tempBasalAbsolute(aDouble(), secondInteger(), true, profile, object : Callback() { override fun run() { if (result.success) { var replyText = if (result.isPercent) String.format(resourceHelper.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration) else String.format(resourceHelper.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_tempbasalfailed) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) } } @@ -577,15 +574,15 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(this, resourceHelper, receivedSms, reply, passCode, object : SmsAction() { override fun run() { - configBuilderPlugin.commandQueue.cancelExtended(object : Callback() { + commandQueueProvider.commandQueue.cancelExtended(object : Callback() { override fun run() { if (result.success) { var replyText = resourceHelper.gs(R.string.smscommunicator_extendedcanceled) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_extendedcancelfailed) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) } } @@ -605,15 +602,15 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(this, resourceHelper, receivedSms, reply, passCode, object : SmsAction(extended, duration) { override fun run() { - configBuilderPlugin.commandQueue.extendedBolus(aDouble(), secondInteger(), object : Callback() { + commandQueueProvider.commandQueue.extendedBolus(aDouble(), secondInteger(), object : Callback() { override fun run() { if (result.success) { var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_extendedset), aDouble, duration) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_extendedfailed) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) } } @@ -642,18 +639,18 @@ class SmsCommunicatorPlugin @Inject constructor( val detailedBolusInfo = DetailedBolusInfo() detailedBolusInfo.insulin = aDouble() detailedBolusInfo.source = Source.USER - configBuilderPlugin.commandQueue.bolus(detailedBolusInfo, object : Callback() { + commandQueueProvider.commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { val resultSuccess = result.success val resultBolusDelivered = result.bolusDelivered - configBuilderPlugin.commandQueue.readStatus("SMS", object : Callback() { + commandQueueProvider.commandQueue.readStatus("SMS", object : Callback() { override fun run() { if (resultSuccess) { var replyText = if (isMeal) String.format(resourceHelper.gs(R.string.smscommunicator_mealbolusdelivered), resultBolusDelivered) else String.format(resourceHelper.gs(R.string.smscommunicator_bolusdelivered), resultBolusDelivered) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) lastRemoteBolusTime = DateUtil.now() if (isMeal) { profileFunction.getProfile()?.let { currentProfile -> @@ -683,7 +680,7 @@ class SmsCommunicatorPlugin @Inject constructor( sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_bolusfailed) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) } } @@ -718,15 +715,15 @@ class SmsCommunicatorPlugin @Inject constructor( val detailedBolusInfo = DetailedBolusInfo() detailedBolusInfo.carbs = anInteger().toDouble() detailedBolusInfo.date = secondLong() - configBuilderPlugin.commandQueue.bolus(detailedBolusInfo, object : Callback() { + commandQueueProvider.commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { if (result.success) { var replyText = String.format(resourceHelper.gs(R.string.smscommunicator_carbsset), anInteger) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText)) } else { var replyText = resourceHelper.gs(R.string.smscommunicator_carbsfailed) - replyText += "\n" + configBuilderPlugin.activePump?.shortStatus(true) + replyText += "\n" + activePluginProvider.activePump?.shortStatus(true) sendSMS(Sms(receivedSms.phoneNumber, replyText)) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt index 0552600d86..f0f3b920fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt @@ -6,13 +6,13 @@ import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.events.* +import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper -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.iob.iobCobCalculator.events.EventAutosensCalculationFinished @@ -34,7 +34,7 @@ class StatusLinePlugin @Inject constructor( private val resourceHelper: ResourceHelper, private val mainApp: MainApp, private val fabricPrivacy: FabricPrivacy, - private val configBuilderPlugin: ConfigBuilderPlugin, + private val activePluginProvider: ActivePluginProvider, private val treatmentsPlugin: TreatmentsPlugin, private val loopPlugin: LoopPlugin, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, @@ -112,7 +112,7 @@ class StatusLinePlugin @Inject constructor( private fun buildStatusString(profile: Profile): String { var status = "" - if (configBuilderPlugin.activePump == null) return "" + if (activePluginProvider.activePump == null) return "" if (!loopPlugin.isEnabled(PluginType.LOOP)) { status += resourceHelper.gs(R.string.disabledloop) + "\n" lastLoopStatus = false diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index c7a7b26a66..2753619418 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -13,6 +13,7 @@ import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.dialogs.ProfileSwitchDialog +import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.Companion.MIN_DIA @@ -29,7 +30,7 @@ import javax.inject.Inject class LocalProfileFragment : DaggerFragment() { @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin + @Inject lateinit var activePluginProvider: ActivePluginProvider @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var localProfilePlugin: LocalProfilePlugin @@ -93,7 +94,7 @@ class LocalProfileFragment : DaggerFragment() { } fun build() { - val pumpDescription = configBuilderPlugin.activePump?.pumpDescription ?: return + val pumpDescription = activePluginProvider.activePump?.pumpDescription ?: return val units = if (localProfilePlugin.currentProfile().mgdl) Constants.MGDL else Constants.MMOL localprofile_name.removeTextChangedListener(textWatch) diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt index 72158e6d42..7e0052b5ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt @@ -11,11 +11,12 @@ import dagger.android.DaggerBroadcastReceiver import info.nightscout.androidaps.Config import info.nightscout.androidaps.db.DatabaseHelper import info.nightscout.androidaps.events.EventProfileNeedsUpdate +import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.queue.commands.Command @@ -29,7 +30,8 @@ import kotlin.math.abs class KeepAliveReceiver : DaggerBroadcastReceiver() { @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBusWrapper - @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin + @Inject lateinit var activePluginProvider: ActivePluginProvider + @Inject lateinit var commandQueueProvider: CommandQueueProvider @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var loopPlugin: LoopPlugin @@ -88,7 +90,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { // if there is no BG available, we have to upload anyway to have correct // IOB displayed in NS private fun checkAPS() { - val usedAPS = configBuilderPlugin.activeAPS + val usedAPS = activePluginProvider.activeAPS var shouldUploadStatus = false if (Config.NSCLIENT) return if (Config.PUMPCONTROL) shouldUploadStatus = true @@ -102,7 +104,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { } private fun checkPump() { - val pump = configBuilderPlugin.activePump ?: return + val pump = activePluginProvider.activePump ?: return val profile = profileFunction.getProfile() ?: return val lastConnection = pump.lastDataTime() val isStatusOutdated = lastConnection + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis() @@ -113,14 +115,14 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { if (lastReadStatus != 0L && lastReadStatus > System.currentTimeMillis() - T.mins(5).msecs()) { LocalAlertUtils.checkPumpUnreachableAlarm(lastConnection, isStatusOutdated, loopPlugin.isDisconnected) } - if (!pump.isThisProfileSet(profile) && !configBuilderPlugin.commandQueue.isRunning(Command.CommandType.BASALPROFILE)) { + if (!pump.isThisProfileSet(profile) && !commandQueueProvider.commandQueue.isRunning(Command.CommandType.BASALPROFILE)) { rxBus.send(EventProfileNeedsUpdate()) } else if (isStatusOutdated && !pump.isBusy) { lastReadStatus = System.currentTimeMillis() - configBuilderPlugin.commandQueue.readStatus("KeepAlive. Status outdated.", null) + commandQueueProvider.commandQueue.readStatus("KeepAlive. Status outdated.", null) } else if (isBasalOutdated && !pump.isBusy) { lastReadStatus = System.currentTimeMillis() - configBuilderPlugin.commandQueue.readStatus("KeepAlive. Basal outdated.", null) + commandQueueProvider.commandQueue.readStatus("KeepAlive. Basal outdated.", null) } if (lastRun != 0L && System.currentTimeMillis() - lastRun > T.mins(10).msecs()) { aapsLogger.error(LTag.CORE, "KeepAlive fail") diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt index d6260f8964..8ee6c0c347 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt @@ -13,15 +13,11 @@ import info.nightscout.androidaps.db.CareportalEvent import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.TempTarget import info.nightscout.androidaps.events.EventRefreshOverview -import info.nightscout.androidaps.interfaces.Constraint -import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.interfaces.PumpDescription -import info.nightscout.androidaps.interfaces.PumpInterface +import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus @@ -50,7 +46,8 @@ class BolusWizard @Inject constructor( @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var treatmentsPlugin: TreatmentsPlugin - @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin + @Inject lateinit var activePluginProvider: ActivePluginProvider + @Inject lateinit var commandQueueProvider: CommandQueueProvider @Inject lateinit var loopPlugin: LoopPlugin @Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin @@ -222,7 +219,7 @@ class BolusWizard @Inject constructor( calculatedTotalInsulin = 0.0 } - val bolusStep = configBuilderPlugin.activePump?.pumpDescription?.bolusStep + val bolusStep = activePluginProvider.activePump?.pumpDescription?.bolusStep ?: 0.1 calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep) @@ -304,7 +301,7 @@ class BolusWizard @Inject constructor( fun confirmAndExecute(context: Context) { val profile = profileFunction.getProfile() ?: return - val pump = configBuilderPlugin.activePump ?: return + val pump = activePluginProvider.activePump ?: return if (calculatedTotalInsulin > 0.0 || carbs > 0.0) { if (accepted) { @@ -324,7 +321,7 @@ class BolusWizard @Inject constructor( } if (pump.pumpDescription?.tempBasalStyle == PumpDescription.ABSOLUTE) { - configBuilderPlugin.commandQueue.tempBasalAbsolute(0.0, 120, true, profile, object : Callback() { + commandQueueProvider.commandQueue.tempBasalAbsolute(0.0, 120, true, profile, object : Callback() { override fun run() { if (!result.success) { val i = Intent(mainApp, ErrorHelperActivity::class.java) @@ -338,7 +335,7 @@ class BolusWizard @Inject constructor( }) } else { - configBuilderPlugin.commandQueue.tempBasalPercent(0, 120, true, profile, object : Callback() { + commandQueueProvider.commandQueue.tempBasalPercent(0, 120, true, profile, object : Callback() { override fun run() { if (!result.success) { val i = Intent(mainApp, ErrorHelperActivity::class.java) @@ -364,7 +361,7 @@ class BolusWizard @Inject constructor( detailedBolusInfo.source = Source.USER detailedBolusInfo.notes = notes if (detailedBolusInfo.insulin > 0 || pump.pumpDescription?.storesCarbInfo == true) { - configBuilderPlugin.commandQueue.bolus(detailedBolusInfo, object : Callback() { + commandQueueProvider.commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { if (!result.success) { val i = Intent(mainApp, ErrorHelperActivity::class.java)