diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index 46643760b0..6853fedcd5 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -27,7 +27,6 @@ import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.CommandQueue @@ -304,6 +303,7 @@ class CarbsDialog : DialogFragmentWithDate() { ValueWithUnit.Hour(duration).takeIf { duration != 0 }) commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { + carbTimer.removeEatReminder() if (!result.success) { ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) } else if (sp.getBoolean(R.string.key_usebolusreminder, false) && remindBolus) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt index 12d14ef265..51af607860 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt @@ -49,6 +49,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 uel: UserEntryLogger companion object { @@ -217,6 +218,8 @@ class InsulinDialog : DialogFragmentWithDate() { { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } }, { aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) } ) + if (timeOffset == 0) + bolusTimer.removeBolusReminder() } else { uel.log(Action.BOLUS, Sources.InsulinDialog, notes, @@ -225,6 +228,8 @@ class InsulinDialog : DialogFragmentWithDate() { override fun run() { if (!result.success) { ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) + } else { + bolusTimer.removeBolusReminder() } } }) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/BolusTimer.kt b/app/src/main/java/info/nightscout/androidaps/utils/BolusTimer.kt index 309ab0ca6a..a137794222 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/BolusTimer.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/BolusTimer.kt @@ -33,8 +33,12 @@ class BolusTimer @Inject constructor( // 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(resourceHelper, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare - .IS_GREATER)) + list.add( + TriggerDelta( + injector, InputDelta(resourceHelper, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare + .IS_GREATER + ) + ) } actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.time_to_bolus))) } @@ -42,4 +46,10 @@ class BolusTimer @Inject constructor( automationPlugin.addIfNotExists(event) } + fun removeBolusReminder() { + val event = AutomationEvent(injector).apply { + title = resourceHelper.gs(R.string.bolusreminder) + } + automationPlugin.removeIfExists(event) + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt index 3509e820df..0f61366226 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt @@ -60,4 +60,10 @@ class CarbTimer @Inject constructor( automationPlugin.addIfNotExists(event) } + fun removeEatReminder() { + val event = AutomationEvent(injector).apply { + title = resourceHelper.gs(R.string.bolusadvisor) + } + automationPlugin.removeIfExists(event) + } } \ No newline at end of file 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 90a311631c..2b5e11342d 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 @@ -29,13 +29,9 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.queue.Callback -import info.nightscout.androidaps.utils.CarbTimer -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.HtmlHelper -import info.nightscout.androidaps.utils.Round -import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.extensions.formatColor +import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.disposables.CompositeDisposable @@ -62,6 +58,7 @@ class BolusWizard @Inject constructor( @Inject lateinit var config: Config @Inject lateinit var uel: UserEntryLogger @Inject lateinit var carbTimer: CarbTimer + @Inject lateinit var bolusTimer: BolusTimer @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider @Inject lateinit var repository: AppRepository @@ -322,7 +319,10 @@ class BolusWizard @Inject constructor( return } accepted = true - + if (calculatedTotalInsulin > 0.0) + bolusTimer.removeBolusReminder() + if (carbs > 0.0) + carbTimer.removeEatReminder() if (sp.getBoolean(R.string.key_usebolusadvisor, false) && Profile.toMgdl(bg, profile.units) > 180 && carbs > 0 && carbTime >= 0) OKDialog.showYesNoCancel(ctx, resourceHelper.gs(R.string.bolusadvisor), resourceHelper.gs(R.string.bolusadvisormessage), { bolusAdvisorProcessing(ctx) }, diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index a09841f903..f8cd61486c 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -267,6 +267,16 @@ class AutomationPlugin @Inject constructor( rxBus.send(EventAutomationDataChanged()) } + @Synchronized + fun removeIfExists(event: AutomationEvent) { + for (e in automationEvents) { + if (event.title == e.title) { + automationEvents.remove(e) + rxBus.send(EventAutomationDataChanged()) + } + } + } + @Synchronized fun set(event: AutomationEvent, index: Int) { automationEvents[index] = event