TT,TBR Dialog -> ui

This commit is contained in:
Milos Kozak 2022-11-11 11:04:51 +01:00
parent 71f01a00ab
commit db8f853805
11 changed files with 104 additions and 74 deletions

View file

@ -5,8 +5,6 @@ import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.activities.MyPreferenceFragment import info.nightscout.androidaps.activities.MyPreferenceFragment
import info.nightscout.androidaps.dialogs.LoopDialog import info.nightscout.androidaps.dialogs.LoopDialog
import info.nightscout.androidaps.dialogs.NtpProgressDialog import info.nightscout.androidaps.dialogs.NtpProgressDialog
import info.nightscout.androidaps.dialogs.TempBasalDialog
import info.nightscout.androidaps.dialogs.TempTargetDialog
import info.nightscout.androidaps.dialogs.WizardDialog import info.nightscout.androidaps.dialogs.WizardDialog
import info.nightscout.androidaps.plugins.aps.OpenAPSFragment import info.nightscout.androidaps.plugins.aps.OpenAPSFragment
import info.nightscout.androidaps.plugins.aps.loop.LoopFragment import info.nightscout.androidaps.plugins.aps.loop.LoopFragment
@ -39,8 +37,6 @@ abstract class FragmentsModule {
@ContributesAndroidInjector abstract fun contributesLoopDialog(): LoopDialog @ContributesAndroidInjector abstract fun contributesLoopDialog(): LoopDialog
@ContributesAndroidInjector abstract fun contributesObjectivesExamDialog(): ObjectivesExamDialog @ContributesAndroidInjector abstract fun contributesObjectivesExamDialog(): ObjectivesExamDialog
@ContributesAndroidInjector abstract fun contributesTempBasalDialog(): TempBasalDialog
@ContributesAndroidInjector abstract fun contributesTempTargetDialog(): TempTargetDialog
@ContributesAndroidInjector abstract fun contributesWizardDialog(): WizardDialog @ContributesAndroidInjector abstract fun contributesWizardDialog(): WizardDialog
@ContributesAndroidInjector abstract fun contributesNtpProgressDialog(): NtpProgressDialog @ContributesAndroidInjector abstract fun contributesNtpProgressDialog(): NtpProgressDialog
@ContributesAndroidInjector abstract fun contributesPasswordCheck(): PasswordCheck @ContributesAndroidInjector abstract fun contributesPasswordCheck(): PasswordCheck

View file

@ -14,8 +14,8 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.HistoryBrowseActivity import info.nightscout.androidaps.activities.HistoryBrowseActivity
import info.nightscout.androidaps.databinding.ActionsFragmentBinding import info.nightscout.androidaps.databinding.ActionsFragmentBinding
import info.nightscout.ui.dialogs.ProfileSwitchDialog import info.nightscout.ui.dialogs.ProfileSwitchDialog
import info.nightscout.androidaps.dialogs.TempBasalDialog import info.nightscout.ui.dialogs.TempBasalDialog
import info.nightscout.androidaps.dialogs.TempTargetDialog import info.nightscout.ui.dialogs.TempTargetDialog
import info.nightscout.androidaps.extensions.toStringMedium import info.nightscout.androidaps.extensions.toStringMedium
import info.nightscout.androidaps.extensions.toStringShort import info.nightscout.androidaps.extensions.toStringShort
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin

View file

@ -32,7 +32,7 @@ import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.databinding.OverviewFragmentBinding import info.nightscout.androidaps.databinding.OverviewFragmentBinding
import info.nightscout.androidaps.dialogs.LoopDialog import info.nightscout.androidaps.dialogs.LoopDialog
import info.nightscout.ui.dialogs.ProfileSwitchDialog import info.nightscout.ui.dialogs.ProfileSwitchDialog
import info.nightscout.androidaps.dialogs.TempTargetDialog import info.nightscout.ui.dialogs.TempTargetDialog
import info.nightscout.androidaps.dialogs.WizardDialog import info.nightscout.androidaps.dialogs.WizardDialog
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
import info.nightscout.androidaps.events.EventNewBG import info.nightscout.androidaps.events.EventNewBG

View file

@ -2,7 +2,6 @@
<resources> <resources>
<string name="key_objectiveusedisconnect" translatable="false">ObjectivesDisconnectUsed</string> <string name="key_objectiveusedisconnect" translatable="false">ObjectivesDisconnectUsed</string>
<string name="key_objectiveusereconnect" translatable="false">ObjectivesReconnectUsed</string> <string name="key_objectiveusereconnect" translatable="false">ObjectivesReconnectUsed</string>
<string name="key_objectiveusetemptarget" translatable="false">ObjectivesTempTargetUsed</string>
<string name="key_objectiveuseactions" translatable="false">ObjectivesActionsUsed</string> <string name="key_objectiveuseactions" translatable="false">ObjectivesActionsUsed</string>
<string name="key_objectiveuseloop" translatable="false">ObjectivesLoopUsed</string> <string name="key_objectiveuseloop" translatable="false">ObjectivesLoopUsed</string>
<string name="key_objectiveusescale" translatable="false">ObjectivesScaleUsed</string> <string name="key_objectiveusescale" translatable="false">ObjectivesScaleUsed</string>

View file

@ -30,7 +30,6 @@
<string name="sendsmsactiondescription">Send SMS to all numbers</string> <string name="sendsmsactiondescription">Send SMS to all numbers</string>
<string name="sendsmsactiontext">Send SMS with text</string> <string name="sendsmsactiontext">Send SMS with text</string>
<string name="starttemptarget">Start temp target</string> <string name="starttemptarget">Start temp target</string>
<string name="stoptemptarget">Stop temp target</string>
<string name="islesser">is lesser than</string> <string name="islesser">is lesser than</string>
<string name="isequalorlesser">is equal or lesser than</string> <string name="isequalorlesser">is equal or lesser than</string>
<string name="isequal">is equal to</string> <string name="isequal">is equal to</string>

View file

@ -92,6 +92,7 @@
<string name="key_ns_receive_offline_event" translatable="false">ns_receive_offline_event</string> <string name="key_ns_receive_offline_event" translatable="false">ns_receive_offline_event</string>
<string name="key_ns_receive_temp_target" translatable="false">ns_receive_temp_target</string> <string name="key_ns_receive_temp_target" translatable="false">ns_receive_temp_target</string>
<string name="key_objectiveuseprofileswitch" translatable="false">ObjectivesProfileSwitchUsed</string> <string name="key_objectiveuseprofileswitch" translatable="false">ObjectivesProfileSwitchUsed</string>
<string name="key_objectiveusetemptarget" translatable="false">ObjectivesTempTargetUsed</string>
<!-- General--> <!-- General-->
<string name="refresh">Refresh</string> <string name="refresh">Refresh</string>
@ -257,6 +258,7 @@
<string name="upload_now">Upload now</string> <string name="upload_now">Upload now</string>
<string name="prime_fill">Prime/Fill</string> <string name="prime_fill">Prime/Fill</string>
<string name="overview_insulin_label">Insulin</string> <string name="overview_insulin_label">Insulin</string>
<string name="stoptemptarget">Stop temp target</string>
<!-- Constraints--> <!-- Constraints-->
<string name="limitingbasalratio">Limiting max basal rate to %1$.2f U/h because of %2$s</string> <string name="limitingbasalratio">Limiting max basal rate to %1$.2f U/h because of %2$s</string>

View file

@ -24,6 +24,8 @@ import info.nightscout.ui.dialogs.FillDialog
import info.nightscout.ui.dialogs.InsulinDialog import info.nightscout.ui.dialogs.InsulinDialog
import info.nightscout.ui.dialogs.ProfileSwitchDialog import info.nightscout.ui.dialogs.ProfileSwitchDialog
import info.nightscout.ui.dialogs.ProfileViewerDialog import info.nightscout.ui.dialogs.ProfileViewerDialog
import info.nightscout.ui.dialogs.TempBasalDialog
import info.nightscout.ui.dialogs.TempTargetDialog
import info.nightscout.ui.dialogs.TreatmentDialog import info.nightscout.ui.dialogs.TreatmentDialog
import info.nightscout.ui.dialogs.WizardInfoDialog import info.nightscout.ui.dialogs.WizardInfoDialog
@ -41,6 +43,8 @@ abstract class UiModule {
@ContributesAndroidInjector abstract fun contributesInsulinDialog(): InsulinDialog @ContributesAndroidInjector abstract fun contributesInsulinDialog(): InsulinDialog
@ContributesAndroidInjector abstract fun contributesTreatmentDialog(): TreatmentDialog @ContributesAndroidInjector abstract fun contributesTreatmentDialog(): TreatmentDialog
@ContributesAndroidInjector abstract fun contributesProfileSwitchDialog(): ProfileSwitchDialog @ContributesAndroidInjector abstract fun contributesProfileSwitchDialog(): ProfileSwitchDialog
@ContributesAndroidInjector abstract fun contributesTempBasalDialog(): TempBasalDialog
@ContributesAndroidInjector abstract fun contributesTempTargetDialog(): TempTargetDialog
@ContributesAndroidInjector abstract fun contributesTDDStatsActivity(): TDDStatsActivity @ContributesAndroidInjector abstract fun contributesTDDStatsActivity(): TDDStatsActivity
@ContributesAndroidInjector abstract fun contributeBolusProgressHelperActivity(): BolusProgressHelperActivity @ContributesAndroidInjector abstract fun contributeBolusProgressHelperActivity(): BolusProgressHelperActivity

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.dialogs package info.nightscout.ui.dialogs
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
@ -6,8 +6,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.google.common.base.Joiner import com.google.common.base.Joiner
import info.nightscout.androidaps.R import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.databinding.DialogTempbasalBinding
import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.extensions.formatColor
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.CommandQueue
@ -17,9 +16,7 @@ import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BOLUS import info.nightscout.database.entities.UserEntry
import info.nightscout.database.entities.UserEntry.Action
import info.nightscout.database.entities.UserEntry.Sources
import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
@ -30,6 +27,8 @@ import info.nightscout.interfaces.utils.HtmlHelper
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.ui.R
import info.nightscout.ui.databinding.DialogTempbasalBinding
import java.text.DecimalFormat import java.text.DecimalFormat
import java.util.LinkedList import java.util.LinkedList
import javax.inject.Inject import javax.inject.Inject
@ -76,16 +75,22 @@ class TempBasalDialog : DialogFragmentWithDate() {
val maxTempPercent = pumpDescription.maxTempPercent.toDouble() val maxTempPercent = pumpDescription.maxTempPercent.toDouble()
val tempPercentStep = pumpDescription.tempPercentStep.toDouble() val tempPercentStep = pumpDescription.tempPercentStep.toDouble()
binding.basalPercentInput.setParams(savedInstanceState?.getDouble("basalPercentInput") binding.basalPercentInput.setParams(
?: 100.0, 0.0, maxTempPercent, tempPercentStep, DecimalFormat("0"), true, binding.okcancel.ok) savedInstanceState?.getDouble("basalPercentInput")
?: 100.0, 0.0, maxTempPercent, tempPercentStep, DecimalFormat("0"), true, binding.okcancel.ok
)
binding.basalAbsoluteInput.setParams(savedInstanceState?.getDouble("basalAbsoluteInput") binding.basalAbsoluteInput.setParams(
?: profile.getBasal(), 0.0, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, DecimalFormat("0.00"), true, binding.okcancel.ok) savedInstanceState?.getDouble("basalAbsoluteInput")
?: profile.getBasal(), 0.0, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, DecimalFormat("0.00"), true, binding.okcancel.ok
)
val tempDurationStep = pumpDescription.tempDurationStep.toDouble() val tempDurationStep = pumpDescription.tempDurationStep.toDouble()
val tempMaxDuration = pumpDescription.tempMaxDuration.toDouble() val tempMaxDuration = pumpDescription.tempMaxDuration.toDouble()
binding.duration.setParams(savedInstanceState?.getDouble("duration") binding.duration.setParams(
?: tempDurationStep, tempDurationStep, tempMaxDuration, tempDurationStep, DecimalFormat("0"), false, binding.okcancel.ok) savedInstanceState?.getDouble("duration")
?: tempDurationStep, tempDurationStep, tempMaxDuration, tempDurationStep, DecimalFormat("0"), false, binding.okcancel.ok
)
isPercentPump = pumpDescription.tempBasalStyle and PumpDescription.PERCENT == PumpDescription.PERCENT isPercentPump = pumpDescription.tempBasalStyle and PumpDescription.PERCENT == PumpDescription.PERCENT
if (isPercentPump) { if (isPercentPump) {
@ -136,14 +141,18 @@ class TempBasalDialog : DialogFragmentWithDate() {
} }
} }
if (isPercentPump) { if (isPercentPump) {
uel.log(Action.TEMP_BASAL, Sources.TempBasalDialog, uel.log(
ValueWithUnit.Percent(percent), UserEntry.Action.TEMP_BASAL, UserEntry.Sources.TempBasalDialog,
ValueWithUnit.Minute(durationInMinutes)) ValueWithUnit.Percent(percent),
ValueWithUnit.Minute(durationInMinutes)
)
commandQueue.tempBasalPercent(percent, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback) commandQueue.tempBasalPercent(percent, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback)
} else { } else {
uel.log(Action.TEMP_BASAL, Sources.TempBasalDialog, uel.log(
ValueWithUnit.Insulin(absolute), UserEntry.Action.TEMP_BASAL, UserEntry.Sources.TempBasalDialog,
ValueWithUnit.Minute(durationInMinutes)) ValueWithUnit.Insulin(absolute),
ValueWithUnit.Minute(durationInMinutes)
)
commandQueue.tempBasalAbsolute(absolute, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback) commandQueue.tempBasalAbsolute(absolute, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback)
} }
}) })
@ -153,7 +162,7 @@ class TempBasalDialog : DialogFragmentWithDate() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if(!queryingProtection) { if (!queryingProtection) {
queryingProtection = true queryingProtection = true
activity?.let { activity -> activity?.let { activity ->
val cancelFail = { val cancelFail = {
@ -162,7 +171,7 @@ class TempBasalDialog : DialogFragmentWithDate() {
ToastUtils.warnToast(ctx, R.string.dialog_canceled) ToastUtils.warnToast(ctx, R.string.dialog_canceled)
dismiss() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, { queryingProtection = false }, cancelFail, cancelFail)
} }
} }
} }

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.dialogs package info.nightscout.ui.dialogs
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
@ -8,8 +8,7 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import com.google.common.base.Joiner import com.google.common.base.Joiner
import com.google.common.collect.Lists import com.google.common.collect.Lists
import info.nightscout.androidaps.R import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.databinding.DialogTemptargetBinding
import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
@ -17,12 +16,10 @@ import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BOLUS
import info.nightscout.core.profile.toCurrentUnitsString import info.nightscout.core.profile.toCurrentUnitsString
import info.nightscout.core.profile.toMgdl import info.nightscout.core.profile.toMgdl
import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry
import info.nightscout.database.entities.UserEntry.Sources
import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.ValueWithUnit
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.ValueWrapper
@ -34,6 +31,8 @@ import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.utils.HtmlHelper import info.nightscout.interfaces.utils.HtmlHelper
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.ui.R
import info.nightscout.ui.databinding.DialogTemptargetBinding
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
import java.text.DecimalFormat import java.text.DecimalFormat
@ -76,19 +75,23 @@ class TempTargetDialog : DialogFragmentWithDate() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.duration.setParams(savedInstanceState?.getDouble("duration") binding.duration.setParams(
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok) savedInstanceState?.getDouble("duration")
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok
)
if (profileFunction.getUnits() == GlucoseUnit.MMOL) if (profileFunction.getUnits() == GlucoseUnit.MMOL)
binding.temptarget.setParams( binding.temptarget.setParams(
savedInstanceState?.getDouble("tempTarget") savedInstanceState?.getDouble("tempTarget")
?: 8.0, ?: 8.0,
Constants.MIN_TT_MMOL, Constants.MAX_TT_MMOL, 0.1, DecimalFormat("0.0"), false, binding.okcancel.ok) Constants.MIN_TT_MMOL, Constants.MAX_TT_MMOL, 0.1, DecimalFormat("0.0"), false, binding.okcancel.ok
)
else else
binding.temptarget.setParams( binding.temptarget.setParams(
savedInstanceState?.getDouble("tempTarget") savedInstanceState?.getDouble("tempTarget")
?: 144.0, ?: 144.0,
Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 1.0, DecimalFormat("0"), false, binding.okcancel.ok) Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 1.0, DecimalFormat("0"), false, binding.okcancel.ok
)
val units = profileFunction.getUnits() val units = profileFunction.getUnits()
binding.units.text = if (units == GlucoseUnit.MMOL) rh.gs(R.string.mmol) else rh.gs(R.string.mgdl) binding.units.text = if (units == GlucoseUnit.MMOL) rh.gs(R.string.mmol) else rh.gs(R.string.mgdl)
@ -184,42 +187,60 @@ class TempTargetDialog : DialogFragmentWithDate() {
activity?.let { activity -> activity?.let { activity ->
OKDialog.showConfirmation(activity, rh.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), { OKDialog.showConfirmation(activity, rh.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), {
val units = profileFunction.getUnits() val units = profileFunction.getUnits()
when(reason) { when (reason) {
rh.gs(R.string.eatingsoon) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( rh.gs(R.string.eatingsoon) -> uel.log(
TemporaryTarget.Reason.EATING_SOON), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)) UserEntry.Action.TT, UserEntry.Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(
rh.gs(R.string.activity) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( TemporaryTarget.Reason.EATING_SOON
TemporaryTarget.Reason.ACTIVITY), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)) ), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)
rh.gs(R.string.hypo) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( )
TemporaryTarget.Reason.HYPOGLYCEMIA), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration))
rh.gs(R.string.manual) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( rh.gs(R.string.activity) -> uel.log(
TemporaryTarget.Reason.CUSTOM), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)) UserEntry.Action.TT, UserEntry.Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(
rh.gs(R.string.stoptemptarget) -> uel.log(Action.CANCEL_TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }) TemporaryTarget.Reason.ACTIVITY
), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)
)
rh.gs(R.string.hypo) -> uel.log(
UserEntry.Action.TT, UserEntry.Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(
TemporaryTarget.Reason.HYPOGLYCEMIA
), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)
)
rh.gs(R.string.manual) -> uel.log(
UserEntry.Action.TT, UserEntry.Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason(
TemporaryTarget.Reason.CUSTOM
), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)
)
rh.gs(R.string.stoptemptarget) -> uel.log(UserEntry.Action.CANCEL_TT, UserEntry.Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged })
} }
if (target == 0.0 || duration == 0) { if (target == 0.0 || duration == 0) {
disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(eventTime)) disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(eventTime))
.subscribe({ result -> .subscribe({ result ->
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
}, { }, {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
}) })
} else { } else {
disposable += repository.runTransactionForResult(InsertAndCancelCurrentTemporaryTargetTransaction( disposable += repository.runTransactionForResult(
timestamp = eventTime, InsertAndCancelCurrentTemporaryTargetTransaction(
duration = TimeUnit.MINUTES.toMillis(duration.toLong()), timestamp = eventTime,
reason = when (reason) { duration = TimeUnit.MINUTES.toMillis(duration.toLong()),
rh.gs(R.string.eatingsoon) -> TemporaryTarget.Reason.EATING_SOON reason = when (reason) {
rh.gs(R.string.activity) -> TemporaryTarget.Reason.ACTIVITY rh.gs(R.string.eatingsoon) -> TemporaryTarget.Reason.EATING_SOON
rh.gs(R.string.hypo) -> TemporaryTarget.Reason.HYPOGLYCEMIA rh.gs(R.string.activity) -> TemporaryTarget.Reason.ACTIVITY
else -> TemporaryTarget.Reason.CUSTOM rh.gs(R.string.hypo) -> TemporaryTarget.Reason.HYPOGLYCEMIA
}, else -> TemporaryTarget.Reason.CUSTOM
lowTarget = Profile.toMgdl(target, profileFunction.getUnits()), },
highTarget = Profile.toMgdl(target, profileFunction.getUnits()) lowTarget = Profile.toMgdl(target, profileFunction.getUnits()),
)).subscribe({ result -> highTarget = Profile.toMgdl(target, profileFunction.getUnits())
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") } )
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } ).subscribe({ result ->
}, { result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") }
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") }
}) }, {
aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it)
})
} }
if (duration == 10) sp.putBoolean(R.string.key_objectiveusetemptarget, true) if (duration == 10) sp.putBoolean(R.string.key_objectiveusetemptarget, true)
@ -230,7 +251,7 @@ class TempTargetDialog : DialogFragmentWithDate() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if(!queryingProtection) { if (!queryingProtection) {
queryingProtection = true queryingProtection = true
activity?.let { activity -> activity?.let { activity ->
val cancelFail = { val cancelFail = {
@ -239,7 +260,7 @@ class TempTargetDialog : DialogFragmentWithDate() {
ToastUtils.warnToast(ctx, R.string.dialog_canceled) ToastUtils.warnToast(ctx, R.string.dialog_canceled)
dismiss() dismiss()
} }
protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, { queryingProtection = false }, cancelFail, cancelFail)
} }
} }
} }