Merge pull request #786 from Philoul/New/RemoveReminder

Remove EatReminder/BolusReminder if Carbs/Insulin entered before remind
This commit is contained in:
Milos Kozak 2021-10-28 20:25:36 +02:00 committed by GitHub
commit 51dcfd9a29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 9 deletions

View file

@ -27,7 +27,6 @@ import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker 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.plugins.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.queue.CommandQueue import info.nightscout.androidaps.queue.CommandQueue
@ -304,6 +303,7 @@ class CarbsDialog : DialogFragmentWithDate() {
ValueWithUnit.Hour(duration).takeIf { duration != 0 }) ValueWithUnit.Hour(duration).takeIf { duration != 0 })
commandQueue.bolus(detailedBolusInfo, object : Callback() { commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() { override fun run() {
carbTimer.removeEatReminder()
if (!result.success) { if (!result.success) {
ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror)
} else if (sp.getBoolean(R.string.key_usebolusreminder, false) && remindBolus) } else if (sp.getBoolean(R.string.key_usebolusreminder, false) && remindBolus)

View file

@ -49,6 +49,7 @@ class InsulinDialog : DialogFragmentWithDate() {
@Inject lateinit var ctx: Context @Inject lateinit var ctx: Context
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var config: Config @Inject lateinit var config: Config
@Inject lateinit var bolusTimer: BolusTimer
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
companion object { companion object {
@ -217,6 +218,8 @@ class InsulinDialog : DialogFragmentWithDate() {
{ result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } }, { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } },
{ aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) } { aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) }
) )
if (timeOffset == 0)
bolusTimer.removeBolusReminder()
} else { } else {
uel.log(Action.BOLUS, Sources.InsulinDialog, uel.log(Action.BOLUS, Sources.InsulinDialog,
notes, notes,
@ -225,6 +228,8 @@ class InsulinDialog : DialogFragmentWithDate() {
override fun run() { override fun run() {
if (!result.success) { if (!result.success) {
ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror) ErrorHelperActivity.runAlarm(ctx, result.comment, resourceHelper.gs(R.string.treatmentdeliveryerror), R.raw.boluserror)
} else {
bolusTimer.removeBolusReminder()
} }
} }
}) })

View file

@ -33,8 +33,12 @@ class BolusTimer @Inject constructor(
// Bg above 70 mgdl and delta positive mgdl // Bg above 70 mgdl and delta positive mgdl
list.add(TriggerBg(injector, 70.0, GlucoseUnit.MGDL, Comparator.Compare.IS_EQUAL_OR_GREATER)) 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 list.add(
.IS_GREATER)) 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))) actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.time_to_bolus)))
} }
@ -42,4 +46,10 @@ class BolusTimer @Inject constructor(
automationPlugin.addIfNotExists(event) automationPlugin.addIfNotExists(event)
} }
fun removeBolusReminder() {
val event = AutomationEvent(injector).apply {
title = resourceHelper.gs(R.string.bolusreminder)
}
automationPlugin.removeIfExists(event)
}
} }

View file

@ -60,4 +60,10 @@ class CarbTimer @Inject constructor(
automationPlugin.addIfNotExists(event) automationPlugin.addIfNotExists(event)
} }
fun removeEatReminder() {
val event = AutomationEvent(injector).apply {
title = resourceHelper.gs(R.string.bolusadvisor)
}
automationPlugin.removeIfExists(event)
}
} }

View file

@ -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.GlucoseStatus
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider
import info.nightscout.androidaps.queue.Callback 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.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.extensions.formatColor
import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.resources.ResourceHelper 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
@ -62,6 +58,7 @@ class BolusWizard @Inject constructor(
@Inject lateinit var config: Config @Inject lateinit var config: Config
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
@Inject lateinit var carbTimer: CarbTimer @Inject lateinit var carbTimer: CarbTimer
@Inject lateinit var bolusTimer: BolusTimer
@Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@ -322,7 +319,10 @@ class BolusWizard @Inject constructor(
return return
} }
accepted = true 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) 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), OKDialog.showYesNoCancel(ctx, resourceHelper.gs(R.string.bolusadvisor), resourceHelper.gs(R.string.bolusadvisormessage),
{ bolusAdvisorProcessing(ctx) }, { bolusAdvisorProcessing(ctx) },

View file

@ -267,6 +267,16 @@ class AutomationPlugin @Inject constructor(
rxBus.send(EventAutomationDataChanged()) rxBus.send(EventAutomationDataChanged())
} }
@Synchronized
fun removeIfExists(event: AutomationEvent) {
for (e in automationEvents) {
if (event.title == e.title) {
automationEvents.remove(e)
rxBus.send(EventAutomationDataChanged())
}
}
}
@Synchronized @Synchronized
fun set(event: AutomationEvent, index: Int) { fun set(event: AutomationEvent, index: Int) {
automationEvents[index] = event automationEvents[index] = event