diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6450e854e0..854ed3570b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,7 +79,6 @@ Authorization failed Unable to create profile. Profile is invalid. Don\'t kill my app? - Time to eat!\nRun Bolus wizard and do calculation again. Crash logs upload disabled! Clear filter Cannula diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/BolusTimer.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/BolusTimer.kt deleted file mode 100644 index 2ac46cc560..0000000000 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/BolusTimer.kt +++ /dev/null @@ -1,14 +0,0 @@ -package info.nightscout.interfaces - -interface BolusTimer { - - /** - * Create new Automation event to alarm when is time to bolus - */ - fun scheduleAutomationEventBolusReminder() - - /** - * Remove Automation event - */ - fun removeAutomationEventBolusReminder() -} \ No newline at end of file diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/CarbTimer.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/CarbTimer.kt deleted file mode 100644 index b7c472a775..0000000000 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/CarbTimer.kt +++ /dev/null @@ -1,21 +0,0 @@ -package info.nightscout.interfaces - -interface CarbTimer { - - /** - * Generate reminder via [info.nightscout.androidaps.utils.TimerUtil] - * - * @param seconds seconds to the future - */ - fun scheduleTimeToEatReminder(seconds: Int) - - /** - * Create new Automation event to alarm when is time to eat - */ - fun scheduleAutomationEventEatReminder() - - /** - * Remove Automation event - */ - fun removeAutomationEventEatReminder() -} \ No newline at end of file diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/automation/Automation.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/automation/Automation.kt index 9f26a97cda..4ad566d6c1 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/automation/Automation.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/automation/Automation.kt @@ -1,6 +1,36 @@ package info.nightscout.interfaces.automation interface Automation { + fun userEvents(): List fun processEvent(someEvent: AutomationEvent) + + /** + * Generate reminder via [info.nightscout.interfaces.utils.TimerUtil] + * + */ + fun scheduleAutomationEventBolusReminder() + + /** + * Remove scheduled reminder from automations + * + */ + fun removeAutomationEventBolusReminder() + + /** + * Generate reminder via [info.nightscout.interfaces.utils.TimerUtil] + * + * @param seconds seconds to the future + */ + fun scheduleTimeToEatReminder(seconds: Int) + + /** + * Remove Automation event + */ + fun removeAutomationEventEatReminder() + + /** + * Create new Automation event to alarm when is time to eat + */ + fun scheduleAutomationEventEatReminder() } \ No newline at end of file diff --git a/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt b/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt index 49182208cf..201d36ea78 100644 --- a/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt +++ b/core/main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt @@ -15,10 +15,9 @@ import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.ValueWithUnit -import info.nightscout.interfaces.BolusTimer -import info.nightscout.interfaces.CarbTimer import info.nightscout.interfaces.Config import info.nightscout.interfaces.aps.Loop +import info.nightscout.interfaces.automation.Automation import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.db.PersistenceLayer @@ -69,8 +68,7 @@ class BolusWizard @Inject constructor( @Inject lateinit var dateUtil: DateUtil @Inject lateinit var config: Config @Inject lateinit var uel: UserEntryLogger - @Inject lateinit var carbTimer: CarbTimer - @Inject lateinit var bolusTimer: BolusTimer + @Inject lateinit var automation: Automation @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider @Inject lateinit var uiInteraction: UiInteraction @Inject lateinit var persistenceLayer: PersistenceLayer @@ -361,9 +359,9 @@ class BolusWizard @Inject constructor( } accepted = true if (calculatedTotalInsulin > 0.0) - bolusTimer.removeAutomationEventBolusReminder() + automation.removeAutomationEventBolusReminder() if (carbs > 0.0) - carbTimer.removeAutomationEventEatReminder() + automation.removeAutomationEventEatReminder() if (sp.getBoolean(info.nightscout.core.ui.R.string.key_usebolusadvisor, false) && Profile.toMgdl(bg, profile.units) > 180 && carbs > 0 && carbTime >= 0) OKDialog.showYesNoCancel(ctx, rh.gs(info.nightscout.core.ui.R.string.bolus_advisor), rh.gs(info.nightscout.core.ui.R.string.bolus_advisor_message), { bolusAdvisorProcessing(ctx) }, @@ -402,7 +400,7 @@ class BolusWizard @Inject constructor( if (!result.success) { uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror) } else - carbTimer.scheduleAutomationEventEatReminder() + automation.scheduleAutomationEventEatReminder() } }) } @@ -494,7 +492,7 @@ class BolusWizard @Inject constructor( bolusCalculatorResult?.let { persistenceLayer.insertOrUpdate(it) } } if (useAlarm && carbs > 0 && carbTime > 0) { - carbTimer.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt()) + automation.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt()) } } }) diff --git a/implementation/build.gradle b/implementation/build.gradle index 38a71e9581..a4c72a5c4d 100644 --- a/implementation/build.gradle +++ b/implementation/build.gradle @@ -19,7 +19,6 @@ dependencies { implementation project(':app-wear-shared:shared') implementation project(':database:entities') implementation project(':database:impl') - implementation project(':plugins:automation') implementation project(':core:main') implementation project(':core:graph') implementation project(':core:graphview') diff --git a/implementation/src/main/java/info/nightscout/implementation/BolusTimerImpl.kt b/implementation/src/main/java/info/nightscout/implementation/BolusTimerImpl.kt deleted file mode 100644 index 0e54ea7dbf..0000000000 --- a/implementation/src/main/java/info/nightscout/implementation/BolusTimerImpl.kt +++ /dev/null @@ -1,55 +0,0 @@ -package info.nightscout.implementation - -import dagger.android.HasAndroidInjector -import info.nightscout.automation.AutomationEventObject -import info.nightscout.automation.AutomationPlugin -import info.nightscout.automation.actions.ActionAlarm -import info.nightscout.automation.elements.Comparator -import info.nightscout.automation.elements.InputDelta -import info.nightscout.automation.triggers.TriggerBg -import info.nightscout.automation.triggers.TriggerConnector -import info.nightscout.automation.triggers.TriggerDelta -import info.nightscout.interfaces.BolusTimer -import info.nightscout.interfaces.GlucoseUnit -import info.nightscout.shared.interfaces.ResourceHelper -import java.text.DecimalFormat -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class BolusTimerImpl @Inject constructor( - private val injector: HasAndroidInjector, - private val rh: ResourceHelper, - private val automationPlugin: AutomationPlugin, -) : BolusTimer { - - override fun scheduleAutomationEventBolusReminder() { - val event = AutomationEventObject(injector).apply { - title = rh.gs(info.nightscout.core.ui.R.string.bolus_reminder) - readOnly = true - systemAction = true - autoRemove = true - trigger = TriggerConnector(injector, TriggerConnector.Type.AND).apply { - - // Bg above 70 mgdl and delta positive mgdl - list.add(TriggerBg(injector, 70.0, GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_GREATER)) - list.add( - TriggerDelta( - injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare - .IS_GREATER - ) - ) - } - actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_bolus))) - } - - automationPlugin.addIfNotExists(event) - } - - override fun removeAutomationEventBolusReminder() { - val event = AutomationEventObject(injector).apply { - title = rh.gs(info.nightscout.core.ui.R.string.bolus_reminder) - } - automationPlugin.removeIfExists(event) - } -} \ No newline at end of file diff --git a/implementation/src/main/java/info/nightscout/implementation/CarbTimerImpl.kt b/implementation/src/main/java/info/nightscout/implementation/CarbTimerImpl.kt deleted file mode 100644 index 0ca958cf65..0000000000 --- a/implementation/src/main/java/info/nightscout/implementation/CarbTimerImpl.kt +++ /dev/null @@ -1,102 +0,0 @@ -package info.nightscout.implementation - -import dagger.android.HasAndroidInjector -import info.nightscout.automation.AutomationEventObject -import info.nightscout.automation.AutomationPlugin -import info.nightscout.automation.actions.ActionAlarm -import info.nightscout.automation.elements.Comparator -import info.nightscout.automation.elements.InputDelta -import info.nightscout.automation.triggers.TriggerBg -import info.nightscout.automation.triggers.TriggerConnector -import info.nightscout.automation.triggers.TriggerDelta -import info.nightscout.interfaces.CarbTimer -import info.nightscout.interfaces.GlucoseUnit -import info.nightscout.interfaces.utils.TimerUtil -import info.nightscout.shared.interfaces.ResourceHelper -import java.text.DecimalFormat -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class CarbTimerImpl @Inject constructor( - private val injector: HasAndroidInjector, - private val rh: ResourceHelper, - private val automationPlugin: AutomationPlugin, - private val timerUtil: TimerUtil -) : CarbTimer { - - /** - * Generate reminder via [info.nightscout.androidaps.utils.TimerUtil] - * - * @param seconds seconds to the future - */ - override fun scheduleTimeToEatReminder(seconds: Int) = - timerUtil.scheduleReminder(seconds, rh.gs(R.string.time_to_eat)) - - /** - * Create new Automation event to alarm when is time to eat - */ - override fun scheduleAutomationEventEatReminder() { - val event = AutomationEventObject(injector).apply { - title = rh.gs(info.nightscout.core.ui.R.string.bolus_advisor) - readOnly = true - systemAction = true - autoRemove = true - trigger = TriggerConnector(injector, TriggerConnector.Type.OR).apply { - - // Bg under 180 mgdl and dropping by 15 mgdl - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 180.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(rh, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add( - TriggerDelta( - injector, - InputDelta(rh, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), - GlucoseUnit.MGDL, - Comparator.Compare.IS_EQUAL_OR_LESSER - ) - ) - }) - // Bg under 160 mgdl and dropping by 9 mgdl - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 160.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(rh, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add( - TriggerDelta( - injector, - InputDelta(rh, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), - GlucoseUnit.MGDL, - Comparator.Compare.IS_EQUAL_OR_LESSER - ) - ) - }) - // Bg under 145 mgdl and dropping - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 145.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add( - TriggerDelta( - injector, - InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), - GlucoseUnit.MGDL, - Comparator.Compare.IS_EQUAL_OR_LESSER - ) - ) - }) - } - actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_eat))) - } - - automationPlugin.addIfNotExists(event) - } - - /** - * Remove Automation event - */ - override fun removeAutomationEventEatReminder() { - val event = AutomationEventObject(injector).apply { - title = rh.gs(info.nightscout.core.ui.R.string.bolus_advisor) - } - automationPlugin.removeIfExists(event) - } -} \ No newline at end of file diff --git a/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt b/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt index d230e45523..3fce4b146b 100644 --- a/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt +++ b/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt @@ -4,8 +4,6 @@ import dagger.Binds import dagger.Module import dagger.android.ContributesAndroidInjector import info.nightscout.core.graph.OverviewData -import info.nightscout.implementation.BolusTimerImpl -import info.nightscout.implementation.CarbTimerImpl import info.nightscout.implementation.DefaultValueHelperImpl import info.nightscout.implementation.HardLimitsImpl import info.nightscout.implementation.LocalAlertUtilsImpl @@ -40,8 +38,6 @@ import info.nightscout.implementation.stats.TddCalculatorImpl import info.nightscout.implementation.stats.TirCalculatorImpl import info.nightscout.implementation.storage.FileStorage import info.nightscout.implementation.userEntry.UserEntryPresentationHelperImpl -import info.nightscout.interfaces.BolusTimer -import info.nightscout.interfaces.CarbTimer import info.nightscout.interfaces.LocalAlertUtils import info.nightscout.interfaces.NotificationHolder import info.nightscout.interfaces.Translator @@ -113,8 +109,6 @@ abstract class ImplementationModule { @Binds fun bindDexcomTirCalculatorInterface(dexcomTirCalculator: DexcomTirCalculatorImpl): DexcomTirCalculator @Binds fun bindPumpSyncInterface(pumpSyncImplementation: PumpSyncImplementation): PumpSync @Binds fun bindXDripBroadcastInterface(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast - @Binds fun bindCarbTimerInterface(carbTimer: CarbTimerImpl): CarbTimer - @Binds fun bindBolusTimerInterface(bolusTimer: BolusTimerImpl): BolusTimer @Binds fun bindLocalAlertUtilsInterface(localAlertUtils: LocalAlertUtilsImpl): LocalAlertUtils @Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider @Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder diff --git a/implementation/src/main/res/values/strings.xml b/implementation/src/main/res/values/strings.xml index d89f8e5c41..6df0df72ce 100644 --- a/implementation/src/main/res/values/strings.xml +++ b/implementation/src/main/res/values/strings.xml @@ -5,8 +5,6 @@ BG - Time to eat - Time to bolus!\nRun Bolus wizard and do calculation again. Command is executed right now Basal value below minimum. Profile not set! Permission diff --git a/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt b/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt index 7a19ef89ea..996345a787 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/AutomationPlugin.kt @@ -17,6 +17,8 @@ import info.nightscout.automation.actions.ActionSendSMS import info.nightscout.automation.actions.ActionStartTempTarget import info.nightscout.automation.actions.ActionStopProcessing import info.nightscout.automation.actions.ActionStopTempTarget +import info.nightscout.automation.elements.Comparator +import info.nightscout.automation.elements.InputDelta import info.nightscout.automation.events.EventAutomationDataChanged import info.nightscout.automation.events.EventAutomationUpdateGui import info.nightscout.automation.events.EventLocationChange @@ -41,6 +43,7 @@ import info.nightscout.automation.triggers.TriggerTimeRange import info.nightscout.automation.triggers.TriggerWifiSsid import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.Config +import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.automation.Automation import info.nightscout.interfaces.automation.AutomationEvent @@ -50,6 +53,7 @@ import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.queue.Callback +import info.nightscout.interfaces.utils.TimerUtil import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventBTChange @@ -67,6 +71,7 @@ import io.reactivex.rxjava3.kotlin.plusAssign import org.json.JSONArray import org.json.JSONException import org.json.JSONObject +import java.text.DecimalFormat import java.util.Collections import javax.inject.Inject import javax.inject.Singleton @@ -87,7 +92,8 @@ class AutomationPlugin @Inject constructor( private val config: Config, private val locationServiceHelper: LocationServiceHelper, private val dateUtil: DateUtil, - private val activePlugin: ActivePlugin + private val activePlugin: ActivePlugin, + private val timerUtil: TimerUtil ) : PluginBase( PluginDescription() .mainType(PluginType.GENERAL) @@ -402,4 +408,109 @@ class AutomationPlugin @Inject constructor( TriggerBTDevice(injector), ) } + + /** + * Generate reminder via [info.nightscout.interfaces.utils.TimerUtil] + * + * @param seconds seconds to the future + */ + override fun scheduleTimeToEatReminder(seconds: Int) = + timerUtil.scheduleReminder(seconds, rh.gs(R.string.time_to_eat)) + + /** + * Create new Automation event to alarm when is time to eat + */ + override fun scheduleAutomationEventEatReminder() { + val event = AutomationEventObject(injector).apply { + title = rh.gs(info.nightscout.core.ui.R.string.bolus_advisor) + readOnly = true + systemAction = true + autoRemove = true + trigger = TriggerConnector(injector, TriggerConnector.Type.OR).apply { + + // Bg under 180 mgdl and dropping by 15 mgdl + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 180.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(rh, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add( + TriggerDelta( + injector, + InputDelta(rh, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), + GlucoseUnit.MGDL, + Comparator.Compare.IS_EQUAL_OR_LESSER + ) + ) + }) + // Bg under 160 mgdl and dropping by 9 mgdl + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 160.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(rh, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add( + TriggerDelta( + injector, + InputDelta(rh, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), + GlucoseUnit.MGDL, + Comparator.Compare.IS_EQUAL_OR_LESSER + ) + ) + }) + // Bg under 145 mgdl and dropping + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 145.0, GlucoseUnit.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add( + TriggerDelta( + injector, + InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), + GlucoseUnit.MGDL, + Comparator.Compare.IS_EQUAL_OR_LESSER + ) + ) + }) + } + actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_eat))) + } + + addIfNotExists(event) + } + + /** + * Remove Automation event + */ + override fun removeAutomationEventEatReminder() { + val event = AutomationEventObject(injector).apply { + title = rh.gs(info.nightscout.core.ui.R.string.bolus_advisor) + } + removeIfExists(event) + } + + override fun scheduleAutomationEventBolusReminder() { + val event = AutomationEventObject(injector).apply { + title = rh.gs(info.nightscout.core.ui.R.string.bolus_reminder) + readOnly = true + systemAction = true + autoRemove = true + trigger = TriggerConnector(injector, TriggerConnector.Type.AND).apply { + + // Bg above 70 mgdl and delta positive mgdl + list.add(TriggerBg(injector, 70.0, GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_GREATER)) + list.add( + TriggerDelta( + injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare + .IS_GREATER + ) + ) + } + actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_bolus))) + } + + addIfNotExists(event) + } + + override fun removeAutomationEventBolusReminder() { + val event = AutomationEventObject(injector).apply { + title = rh.gs(info.nightscout.core.ui.R.string.bolus_reminder) + } + removeIfExists(event) + } } diff --git a/plugins/automation/src/main/res/values/strings.xml b/plugins/automation/src/main/res/values/strings.xml index 377a27bc7b..7764be8f19 100644 --- a/plugins/automation/src/main/res/values/strings.xml +++ b/plugins/automation/src/main/res/values/strings.xml @@ -131,4 +131,8 @@ S S + + Time to eat!\nRun Bolus wizard and do calculation again. + Time to bolus!\nRun Bolus wizard and do calculation again. + \ No newline at end of file diff --git a/implementation/src/test/java/info/nightscout/implementation/BolusTimerImplTest.kt b/plugins/automation/src/test/java/info/nightscout/automation/BolusTimerImplTest.kt similarity index 71% rename from implementation/src/test/java/info/nightscout/implementation/BolusTimerImplTest.kt rename to plugins/automation/src/test/java/info/nightscout/automation/BolusTimerImplTest.kt index 8a97bad30a..799a48864d 100644 --- a/implementation/src/test/java/info/nightscout/implementation/BolusTimerImplTest.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/BolusTimerImplTest.kt @@ -1,10 +1,9 @@ -package info.nightscout.implementation +package info.nightscout.automation import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.automation.AutomationPlugin import info.nightscout.automation.services.LocationServiceHelper import info.nightscout.automation.triggers.Trigger import info.nightscout.core.utils.fabric.FabricPrivacy @@ -14,16 +13,17 @@ import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction +import info.nightscout.interfaces.utils.TimerUtil import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil -import org.junit.Assert +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mock -import org.mockito.Mockito.anyInt -import org.mockito.Mockito.`when` +import org.mockito.Mockito class BolusTimerImplTest : TestBase() { @@ -38,6 +38,7 @@ class BolusTimerImplTest : TestBase() { @Mock lateinit var locationServiceHelper: LocationServiceHelper @Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var profileFunction: ProfileFunction + @Mock lateinit var timerUtil: TimerUtil private val injector = HasAndroidInjector { AndroidInjector { @@ -50,23 +51,22 @@ class BolusTimerImplTest : TestBase() { private lateinit var dateUtil: DateUtil private lateinit var automationPlugin: AutomationPlugin - private lateinit var sut: BolusTimerImpl @BeforeEach fun init() { - `when`(rh.gs(anyInt())).thenReturn("") - `when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) + Mockito.`when`(rh.gs(anyInt())).thenReturn("") + Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) dateUtil = DateUtil(context) - automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin) - sut = BolusTimerImpl(injector, rh, automationPlugin) + automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, + activePlugin, timerUtil) } @Test fun doTest() { - Assert.assertEquals(0, automationPlugin.size()) - sut.scheduleAutomationEventBolusReminder() - Assert.assertEquals(1, automationPlugin.size()) - sut.removeAutomationEventBolusReminder() - Assert.assertEquals(0, automationPlugin.size()) + Assertions.assertEquals(0, automationPlugin.size()) + automationPlugin.scheduleAutomationEventBolusReminder() + Assertions.assertEquals(1, automationPlugin.size()) + automationPlugin.removeAutomationEventBolusReminder() + Assertions.assertEquals(0, automationPlugin.size()) } } \ No newline at end of file diff --git a/implementation/src/test/java/info/nightscout/implementation/CarbTimerImplTest.kt b/plugins/automation/src/test/java/info/nightscout/automation/CarbTimerImplTest.kt similarity index 73% rename from implementation/src/test/java/info/nightscout/implementation/CarbTimerImplTest.kt rename to plugins/automation/src/test/java/info/nightscout/automation/CarbTimerImplTest.kt index 87d82e2961..00bb7d4451 100644 --- a/implementation/src/test/java/info/nightscout/implementation/CarbTimerImplTest.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/CarbTimerImplTest.kt @@ -1,10 +1,9 @@ -package info.nightscout.implementation +package info.nightscout.automation import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.automation.AutomationPlugin import info.nightscout.automation.services.LocationServiceHelper import info.nightscout.automation.triggers.Trigger import info.nightscout.core.utils.fabric.FabricPrivacy @@ -19,14 +18,13 @@ import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil -import org.junit.Assert +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.mockito.ArgumentMatchers.any +import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mock import org.mockito.Mockito -import org.mockito.Mockito.any -import org.mockito.Mockito.anyInt -import org.mockito.Mockito.`when` class CarbTimerImplTest : TestBase() { @@ -54,27 +52,26 @@ class CarbTimerImplTest : TestBase() { private lateinit var timerUtil: TimerUtil private lateinit var automationPlugin: AutomationPlugin - private lateinit var sut: CarbTimerImpl @BeforeEach fun init() { - `when`(rh.gs(anyInt())).thenReturn("") - `when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) + Mockito.`when`(rh.gs(anyInt())).thenReturn("") + Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) dateUtil = DateUtil(context) timerUtil = TimerUtil(context) - automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, activePlugin) - sut = CarbTimerImpl(injector, rh, automationPlugin, timerUtil) + automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil, + activePlugin, timerUtil) } @Test fun doTest() { - Assert.assertEquals(0, automationPlugin.size()) - sut.scheduleAutomationEventEatReminder() - Assert.assertEquals(1, automationPlugin.size()) - sut.removeAutomationEventEatReminder() - Assert.assertEquals(0, automationPlugin.size()) + Assertions.assertEquals(0, automationPlugin.size()) + automationPlugin.scheduleAutomationEventEatReminder() + Assertions.assertEquals(1, automationPlugin.size()) + automationPlugin.removeAutomationEventEatReminder() + Assertions.assertEquals(0, automationPlugin.size()) - sut.scheduleTimeToEatReminder(1) + automationPlugin.scheduleTimeToEatReminder(1) Mockito.verify(context, Mockito.times(1)).startActivity(any()) } } \ No newline at end of file diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt index 878f721741..4809067612 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/CarbsDialog.kt @@ -17,12 +17,11 @@ import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction -import info.nightscout.interfaces.BolusTimer -import info.nightscout.interfaces.CarbTimer import info.nightscout.interfaces.Constants.CARBS_FAV1_DEFAULT import info.nightscout.interfaces.Constants.CARBS_FAV2_DEFAULT import info.nightscout.interfaces.Constants.CARBS_FAV3_DEFAULT import info.nightscout.interfaces.GlucoseUnit +import info.nightscout.interfaces.automation.Automation import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.iob.GlucoseStatusProvider @@ -62,8 +61,7 @@ class CarbsDialog : DialogFragmentWithDate() { @Inject lateinit var iobCobCalculator: IobCobCalculator @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider @Inject lateinit var uel: UserEntryLogger - @Inject lateinit var carbTimer: CarbTimer - @Inject lateinit var bolusTimer: BolusTimer + @Inject lateinit var automation: Automation @Inject lateinit var commandQueue: CommandQueue @Inject lateinit var repository: AppRepository @Inject lateinit var protectionCheck: ProtectionCheck @@ -372,16 +370,16 @@ class CarbsDialog : DialogFragmentWithDate() { ValueWithUnit.Hour(duration).takeIf { duration != 0 }) commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { - carbTimer.removeAutomationEventEatReminder() + automation.removeAutomationEventEatReminder() if (!result.success) { uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror) } else if (sp.getBoolean(info.nightscout.core.utils.R.string.key_usebolusreminder, false) && remindBolus) - bolusTimer.scheduleAutomationEventBolusReminder() + automation.scheduleAutomationEventBolusReminder() } }) } if (useAlarm && carbs > 0 && timeOffset > 0) { - carbTimer.scheduleTimeToEatReminder(T.mins(timeOffset.toLong()).secs().toInt()) + automation.scheduleTimeToEatReminder(T.mins(timeOffset.toLong()).secs().toInt()) } }, null) } diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt index 2d8854343b..d60a56e887 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt @@ -16,12 +16,12 @@ import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction -import info.nightscout.interfaces.BolusTimer import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants.INSULIN_PLUS1_DEFAULT import info.nightscout.interfaces.Constants.INSULIN_PLUS2_DEFAULT import info.nightscout.interfaces.Constants.INSULIN_PLUS3_DEFAULT import info.nightscout.interfaces.GlucoseUnit +import info.nightscout.interfaces.automation.Automation import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.db.PersistenceLayer @@ -65,7 +65,7 @@ class InsulinDialog : DialogFragmentWithDate() { @Inject lateinit var ctx: Context @Inject lateinit var repository: AppRepository @Inject lateinit var config: Config - @Inject lateinit var bolusTimer: BolusTimer + @Inject lateinit var automation: Automation @Inject lateinit var uel: UserEntryLogger @Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var uiInteraction: UiInteraction @@ -256,7 +256,7 @@ class InsulinDialog : DialogFragmentWithDate() { ValueWithUnit.Minute(timeOffset).takeIf { timeOffset != 0 }) persistenceLayer.insertOrUpdateBolus(detailedBolusInfo.createBolus()) if (timeOffset == 0) - bolusTimer.removeAutomationEventBolusReminder() + automation.removeAutomationEventBolusReminder() } else { uel.log( UserEntry.Action.BOLUS, UserEntry.Sources.InsulinDialog, @@ -268,7 +268,7 @@ class InsulinDialog : DialogFragmentWithDate() { if (!result.success) { uiInteraction.runAlarm(result.comment, rh.gs(info.nightscout.core.ui.R.string.treatmentdeliveryerror), info.nightscout.core.ui.R.raw.boluserror) } else { - bolusTimer.removeAutomationEventBolusReminder() + automation.removeAutomationEventBolusReminder() } } })