AndroidAPS/app/src/main/java/info/nightscout/androidaps/utils/BolusTimer.kt

55 lines
2.3 KiB
Kotlin
Raw Normal View History

2021-10-22 16:15:26 +02:00
package info.nightscout.androidaps.utils
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.GlucoseUnit
import info.nightscout.androidaps.plugins.general.automation.AutomationEvent
import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin
import info.nightscout.androidaps.plugins.general.automation.actions.ActionAlarm
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator
import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDelta
import info.nightscout.androidaps.utils.resources.ResourceHelper
import java.text.DecimalFormat
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class BolusTimer @Inject constructor(
private val injector: HasAndroidInjector,
2021-11-04 10:56:12 +01:00
private val rh: ResourceHelper,
2021-10-22 16:15:26 +02:00
private val automationPlugin: AutomationPlugin,
) {
fun scheduleBolusReminder() {
val event = AutomationEvent(injector).apply {
2021-11-04 10:56:12 +01:00
title = rh.gs(R.string.bolusreminder)
2021-10-22 16:15:26 +02:00
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(
2021-11-04 10:56:12 +01:00
injector, InputDelta(rh, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), GlucoseUnit.MGDL, Comparator.Compare
.IS_GREATER
)
)
2021-10-22 16:15:26 +02:00
}
2021-11-04 10:56:12 +01:00
actions.add(ActionAlarm(injector, rh.gs(R.string.time_to_bolus)))
2021-10-22 16:15:26 +02:00
}
automationPlugin.addIfNotExists(event)
}
fun removeBolusReminder() {
val event = AutomationEvent(injector).apply {
2021-11-04 10:56:12 +01:00
title = rh.gs(R.string.bolusreminder)
}
automationPlugin.removeIfExists(event)
}
2021-10-22 16:15:26 +02:00
}