Merge pull request #780 from Philoul/New/BolusReminder
New function : Bolus reminder
This commit is contained in:
commit
04a104a9b0
|
@ -27,6 +27,8 @@ 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
|
||||
import info.nightscout.androidaps.utils.*
|
||||
|
@ -48,8 +50,10 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
@Inject lateinit var defaultValueHelper: DefaultValueHelper
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@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 commandQueue: CommandQueue
|
||||
@Inject lateinit var repository: AppRepository
|
||||
|
||||
|
@ -110,7 +114,12 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
if (sp.getBoolean(R.string.key_usebolusreminder, false)) {
|
||||
glucoseStatusProvider.glucoseStatusData?.let { glucoseStatus ->
|
||||
if (glucoseStatus.glucose + 3 * glucoseStatus.delta < 70.0)
|
||||
binding.bolusReminder.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
val maxCarbs = constraintChecker.getMaxCarbsAllowed().value().toDouble()
|
||||
binding.time.setParams(savedInstanceState?.getDouble("time")
|
||||
?: 0.0, -12 * 60.0, 12 * 60.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher)
|
||||
|
@ -184,6 +193,7 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
val actions: LinkedList<String?> = LinkedList()
|
||||
val unitLabel = if (units == GlucoseUnit.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl)
|
||||
val useAlarm = binding.alarmCheckBox.isChecked
|
||||
val remindBolus = binding.bolusReminderCheckBox.isChecked
|
||||
|
||||
val activitySelected = binding.activityTt.isChecked
|
||||
if (activitySelected)
|
||||
|
@ -296,7 +306,8 @@ class CarbsDialog : DialogFragmentWithDate() {
|
|||
override fun run() {
|
||||
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)
|
||||
bolusTimer.scheduleBolusReminder()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
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,
|
||||
private val resourceHelper: ResourceHelper,
|
||||
private val automationPlugin: AutomationPlugin,
|
||||
) {
|
||||
|
||||
fun scheduleBolusReminder() {
|
||||
val event = AutomationEvent(injector).apply {
|
||||
title = resourceHelper.gs(R.string.bolusreminder)
|
||||
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(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)))
|
||||
}
|
||||
|
||||
automationPlugin.addIfNotExists(event)
|
||||
}
|
||||
|
||||
}
|
|
@ -234,6 +234,40 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/bolusReminder"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:visibility="gone"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:text="@string/bolus_reminder"
|
||||
android:gravity="center_vertical"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_access_alarm_24dp" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/bolusReminderCheckBox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:checked="false"
|
||||
android:padding="2dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<include
|
||||
android:id="@+id/notes_layout"
|
||||
layout="@layout/notes" />
|
||||
|
|
|
@ -844,6 +844,7 @@
|
|||
<string name="resettodefaults">Reset to defaults</string>
|
||||
<string name="nsmalfunction">NSClient malfunction. Consider NS and NSClient restart.</string>
|
||||
<string name="time_offset">Time offset</string>
|
||||
<string name="bolus_reminder">Remind to bolus later</string>
|
||||
<string name="key_aps_mode" translatable="false">aps_mode</string>
|
||||
<string name="setupwizard_preferred_aps_mode">Preferred APS mode</string>
|
||||
<string name="treatments_wizard_total_label">Total</string>
|
||||
|
@ -1066,6 +1067,12 @@
|
|||
<string name="enablebolusadvisor_summary">Use reminder to start eating later instead of wizard result during high glycemia ("pre-bolus")</string>
|
||||
<string name="time_to_eat">Time to eat!\nRun Bolus wizard and do calculation again.</string>
|
||||
<string name="timetoeat">Time to eat</string>
|
||||
<string name="bolusreminder">Bolus reminder</string>
|
||||
<string name="key_usebolusreminder" translatable="false">use_bolus_reminder</string>
|
||||
<string name="enablebolusreminder">Enable bolus reminder</string>
|
||||
<string name="enablebolusreminder_summary">Use reminder to bolus later with wizard
|
||||
("post-bolus")</string>
|
||||
<string name="time_to_bolus">Time to bolus!\nRun Bolus wizard and do calculation again.</string>
|
||||
<string name="fabric_upload_disabled">Crash logs upload disabled!</string>
|
||||
<string name="graph_menu_divider_header">Graph</string>
|
||||
<string name="chart_menu">Chart menu</string>
|
||||
|
|
|
@ -502,6 +502,12 @@
|
|||
android:summary="@string/enablesuperbolus_summary"
|
||||
android:title="@string/enablesuperbolus" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/key_usebolusreminder"
|
||||
android:summary="@string/enablebolusreminder_summary"
|
||||
android:title="@string/enablebolusreminder" />
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
|
Loading…
Reference in a new issue