From db8f8538058424218bf86c2c93f8b86c6c0ef7ba Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 11 Nov 2022 11:04:51 +0100 Subject: [PATCH] TT,TBR Dialog -> ui --- .../androidaps/di/FragmentsModule.kt | 4 - .../general/actions/ActionsFragment.kt | 4 +- .../general/overview/OverviewFragment.kt | 2 +- app/src/main/res/values/objectives.xml | 1 - automation/src/main/res/values/strings.xml | 1 - .../core-main/src/main/res/values/strings.xml | 2 + .../java/info/nightscout/ui/di/UiModule.kt | 4 + .../nightscout/ui}/dialogs/TempBasalDialog.kt | 51 ++++---- .../ui}/dialogs/TempTargetDialog.kt | 109 +++++++++++------- .../src/main/res/layout/dialog_tempbasal.xml | 0 .../src/main/res/layout/dialog_temptarget.xml | 0 11 files changed, 104 insertions(+), 74 deletions(-) rename {app/src/main/java/info/nightscout/androidaps => ui/src/main/java/info/nightscout/ui}/dialogs/TempBasalDialog.kt (80%) rename {app/src/main/java/info/nightscout/androidaps => ui/src/main/java/info/nightscout/ui}/dialogs/TempTargetDialog.kt (66%) rename {app => ui}/src/main/res/layout/dialog_tempbasal.xml (100%) rename {app => ui}/src/main/res/layout/dialog_temptarget.xml (100%) diff --git a/app/src/main/java/info/nightscout/androidaps/di/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/di/FragmentsModule.kt index ec041ca6b7..7baa02c9c7 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/FragmentsModule.kt @@ -5,8 +5,6 @@ import dagger.android.ContributesAndroidInjector import info.nightscout.androidaps.activities.MyPreferenceFragment import info.nightscout.androidaps.dialogs.LoopDialog 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.plugins.aps.OpenAPSFragment import info.nightscout.androidaps.plugins.aps.loop.LoopFragment @@ -39,8 +37,6 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesLoopDialog(): LoopDialog @ContributesAndroidInjector abstract fun contributesObjectivesExamDialog(): ObjectivesExamDialog - @ContributesAndroidInjector abstract fun contributesTempBasalDialog(): TempBasalDialog - @ContributesAndroidInjector abstract fun contributesTempTargetDialog(): TempTargetDialog @ContributesAndroidInjector abstract fun contributesWizardDialog(): WizardDialog @ContributesAndroidInjector abstract fun contributesNtpProgressDialog(): NtpProgressDialog @ContributesAndroidInjector abstract fun contributesPasswordCheck(): PasswordCheck diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index c703e87c11..9ef92c6d1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -14,8 +14,8 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.HistoryBrowseActivity import info.nightscout.androidaps.databinding.ActionsFragmentBinding import info.nightscout.ui.dialogs.ProfileSwitchDialog -import info.nightscout.androidaps.dialogs.TempBasalDialog -import info.nightscout.androidaps.dialogs.TempTargetDialog +import info.nightscout.ui.dialogs.TempBasalDialog +import info.nightscout.ui.dialogs.TempTargetDialog import info.nightscout.androidaps.extensions.toStringMedium import info.nightscout.androidaps.extensions.toStringShort import info.nightscout.androidaps.interfaces.ActivePlugin diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 781096f1b7..eccf93ed99 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -32,7 +32,7 @@ import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.databinding.OverviewFragmentBinding import info.nightscout.androidaps.dialogs.LoopDialog 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.events.EventEffectiveProfileSwitchChanged import info.nightscout.androidaps.events.EventNewBG diff --git a/app/src/main/res/values/objectives.xml b/app/src/main/res/values/objectives.xml index 0cafc68872..49da5eda10 100644 --- a/app/src/main/res/values/objectives.xml +++ b/app/src/main/res/values/objectives.xml @@ -2,7 +2,6 @@ ObjectivesDisconnectUsed ObjectivesReconnectUsed - ObjectivesTempTargetUsed ObjectivesActionsUsed ObjectivesLoopUsed ObjectivesScaleUsed diff --git a/automation/src/main/res/values/strings.xml b/automation/src/main/res/values/strings.xml index 73f6fa9b0d..cde299b865 100644 --- a/automation/src/main/res/values/strings.xml +++ b/automation/src/main/res/values/strings.xml @@ -30,7 +30,6 @@ Send SMS to all numbers Send SMS with text Start temp target - Stop temp target is lesser than is equal or lesser than is equal to diff --git a/core/core-main/src/main/res/values/strings.xml b/core/core-main/src/main/res/values/strings.xml index 0cfdf3c5b6..658d857276 100644 --- a/core/core-main/src/main/res/values/strings.xml +++ b/core/core-main/src/main/res/values/strings.xml @@ -92,6 +92,7 @@ ns_receive_offline_event ns_receive_temp_target ObjectivesProfileSwitchUsed + ObjectivesTempTargetUsed Refresh @@ -257,6 +258,7 @@ Upload now Prime/Fill Insulin + Stop temp target Limiting max basal rate to %1$.2f U/h because of %2$s diff --git a/ui/src/main/java/info/nightscout/ui/di/UiModule.kt b/ui/src/main/java/info/nightscout/ui/di/UiModule.kt index 489311b8a0..3aa6da32c8 100644 --- a/ui/src/main/java/info/nightscout/ui/di/UiModule.kt +++ b/ui/src/main/java/info/nightscout/ui/di/UiModule.kt @@ -24,6 +24,8 @@ import info.nightscout.ui.dialogs.FillDialog import info.nightscout.ui.dialogs.InsulinDialog import info.nightscout.ui.dialogs.ProfileSwitchDialog 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.WizardInfoDialog @@ -41,6 +43,8 @@ abstract class UiModule { @ContributesAndroidInjector abstract fun contributesInsulinDialog(): InsulinDialog @ContributesAndroidInjector abstract fun contributesTreatmentDialog(): TreatmentDialog @ContributesAndroidInjector abstract fun contributesProfileSwitchDialog(): ProfileSwitchDialog + @ContributesAndroidInjector abstract fun contributesTempBasalDialog(): TempBasalDialog + @ContributesAndroidInjector abstract fun contributesTempTargetDialog(): TempTargetDialog @ContributesAndroidInjector abstract fun contributesTDDStatsActivity(): TDDStatsActivity @ContributesAndroidInjector abstract fun contributeBolusProgressHelperActivity(): BolusProgressHelperActivity diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/TempBasalDialog.kt similarity index 80% rename from app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt rename to ui/src/main/java/info/nightscout/ui/dialogs/TempBasalDialog.kt index 4f3e3b6e39..34aec2aa8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/TempBasalDialog.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.dialogs +package info.nightscout.ui.dialogs import android.content.Context import android.os.Bundle @@ -6,8 +6,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.google.common.base.Joiner -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.DialogTempbasalBinding +import info.nightscout.androidaps.dialogs.DialogFragmentWithDate import info.nightscout.androidaps.extensions.formatColor import info.nightscout.androidaps.interfaces.ActivePlugin 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.alertDialogs.OKDialog import info.nightscout.androidaps.utils.protection.ProtectionCheck -import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.BOLUS -import info.nightscout.database.entities.UserEntry.Action -import info.nightscout.database.entities.UserEntry.Sources +import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.ValueWithUnit import info.nightscout.interfaces.constraints.Constraint 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.shared.SafeParse import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.ui.R +import info.nightscout.ui.databinding.DialogTempbasalBinding import java.text.DecimalFormat import java.util.LinkedList import javax.inject.Inject @@ -76,16 +75,22 @@ class TempBasalDialog : DialogFragmentWithDate() { val maxTempPercent = pumpDescription.maxTempPercent.toDouble() val tempPercentStep = pumpDescription.tempPercentStep.toDouble() - binding.basalPercentInput.setParams(savedInstanceState?.getDouble("basalPercentInput") - ?: 100.0, 0.0, maxTempPercent, tempPercentStep, DecimalFormat("0"), true, binding.okcancel.ok) + binding.basalPercentInput.setParams( + savedInstanceState?.getDouble("basalPercentInput") + ?: 100.0, 0.0, maxTempPercent, tempPercentStep, DecimalFormat("0"), true, binding.okcancel.ok + ) - binding.basalAbsoluteInput.setParams(savedInstanceState?.getDouble("basalAbsoluteInput") - ?: profile.getBasal(), 0.0, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, DecimalFormat("0.00"), true, binding.okcancel.ok) + binding.basalAbsoluteInput.setParams( + savedInstanceState?.getDouble("basalAbsoluteInput") + ?: profile.getBasal(), 0.0, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, DecimalFormat("0.00"), true, binding.okcancel.ok + ) val tempDurationStep = pumpDescription.tempDurationStep.toDouble() val tempMaxDuration = pumpDescription.tempMaxDuration.toDouble() - binding.duration.setParams(savedInstanceState?.getDouble("duration") - ?: tempDurationStep, tempDurationStep, tempMaxDuration, tempDurationStep, DecimalFormat("0"), false, binding.okcancel.ok) + binding.duration.setParams( + savedInstanceState?.getDouble("duration") + ?: tempDurationStep, tempDurationStep, tempMaxDuration, tempDurationStep, DecimalFormat("0"), false, binding.okcancel.ok + ) isPercentPump = pumpDescription.tempBasalStyle and PumpDescription.PERCENT == PumpDescription.PERCENT if (isPercentPump) { @@ -136,14 +141,18 @@ class TempBasalDialog : DialogFragmentWithDate() { } } if (isPercentPump) { - uel.log(Action.TEMP_BASAL, Sources.TempBasalDialog, - ValueWithUnit.Percent(percent), - ValueWithUnit.Minute(durationInMinutes)) + uel.log( + UserEntry.Action.TEMP_BASAL, UserEntry.Sources.TempBasalDialog, + ValueWithUnit.Percent(percent), + ValueWithUnit.Minute(durationInMinutes) + ) commandQueue.tempBasalPercent(percent, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback) } else { - uel.log(Action.TEMP_BASAL, Sources.TempBasalDialog, - ValueWithUnit.Insulin(absolute), - ValueWithUnit.Minute(durationInMinutes)) + uel.log( + UserEntry.Action.TEMP_BASAL, UserEntry.Sources.TempBasalDialog, + ValueWithUnit.Insulin(absolute), + ValueWithUnit.Minute(durationInMinutes) + ) commandQueue.tempBasalAbsolute(absolute, durationInMinutes, true, profile, PumpSync.TemporaryBasalType.NORMAL, callback) } }) @@ -153,7 +162,7 @@ class TempBasalDialog : DialogFragmentWithDate() { override fun onResume() { super.onResume() - if(!queryingProtection) { + if (!queryingProtection) { queryingProtection = true activity?.let { activity -> val cancelFail = { @@ -162,8 +171,8 @@ class TempBasalDialog : DialogFragmentWithDate() { ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } - protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, { queryingProtection = false }, cancelFail, cancelFail) } } } -} +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/TempTargetDialog.kt similarity index 66% rename from app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt rename to ui/src/main/java/info/nightscout/ui/dialogs/TempTargetDialog.kt index b96fb82424..e2229eaeb1 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/TempTargetDialog.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.dialogs +package info.nightscout.ui.dialogs import android.content.Context import android.os.Bundle @@ -8,8 +8,7 @@ import android.view.ViewGroup import android.widget.ArrayAdapter import com.google.common.base.Joiner import com.google.common.collect.Lists -import info.nightscout.androidaps.R -import info.nightscout.androidaps.databinding.DialogTemptargetBinding +import info.nightscout.androidaps.dialogs.DialogFragmentWithDate import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.ProfileFunction 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.alertDialogs.OKDialog 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.toMgdl import info.nightscout.database.entities.TemporaryTarget -import info.nightscout.database.entities.UserEntry.Action -import info.nightscout.database.entities.UserEntry.Sources +import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.impl.AppRepository 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.rx.logging.LTag 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.kotlin.plusAssign import java.text.DecimalFormat @@ -76,19 +75,23 @@ class TempTargetDialog : DialogFragmentWithDate() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding.duration.setParams(savedInstanceState?.getDouble("duration") - ?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, binding.okcancel.ok) + binding.duration.setParams( + 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) binding.temptarget.setParams( savedInstanceState?.getDouble("tempTarget") ?: 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 binding.temptarget.setParams( savedInstanceState?.getDouble("tempTarget") ?: 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() 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 -> OKDialog.showConfirmation(activity, rh.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { val units = profileFunction.getUnits() - when(reason) { - rh.gs(R.string.eatingsoon) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( - TemporaryTarget.Reason.EATING_SOON), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)) - rh.gs(R.string.activity) -> uel.log(Action.TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( - TemporaryTarget.Reason.ACTIVITY), 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( - TemporaryTarget.Reason.CUSTOM), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration)) - rh.gs(R.string.stoptemptarget) -> uel.log(Action.CANCEL_TT, Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }) + when (reason) { + rh.gs(R.string.eatingsoon) -> uel.log( + UserEntry.Action.TT, UserEntry.Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( + TemporaryTarget.Reason.EATING_SOON + ), ValueWithUnit.fromGlucoseUnit(target, units.asText), ValueWithUnit.Minute(duration) + ) + + rh.gs(R.string.activity) -> uel.log( + UserEntry.Action.TT, UserEntry.Sources.TTDialog, ValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, ValueWithUnit.TherapyEventTTReason( + 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) { disposable += repository.runTransactionForResult(CancelCurrentTemporaryTargetIfAnyTransaction(eventTime)) .subscribe({ result -> - result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated 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) + }) } else { - disposable += repository.runTransactionForResult(InsertAndCancelCurrentTemporaryTargetTransaction( - timestamp = eventTime, - duration = TimeUnit.MINUTES.toMillis(duration.toLong()), - reason = when (reason) { - rh.gs(R.string.eatingsoon) -> TemporaryTarget.Reason.EATING_SOON - rh.gs(R.string.activity) -> TemporaryTarget.Reason.ACTIVITY - rh.gs(R.string.hypo) -> TemporaryTarget.Reason.HYPOGLYCEMIA - else -> TemporaryTarget.Reason.CUSTOM - }, - lowTarget = Profile.toMgdl(target, profileFunction.getUnits()), - highTarget = Profile.toMgdl(target, profileFunction.getUnits()) - )).subscribe({ result -> - result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp target $it") } - result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated temp target $it") } - }, { - aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) - }) + disposable += repository.runTransactionForResult( + InsertAndCancelCurrentTemporaryTargetTransaction( + timestamp = eventTime, + duration = TimeUnit.MINUTES.toMillis(duration.toLong()), + reason = when (reason) { + rh.gs(R.string.eatingsoon) -> TemporaryTarget.Reason.EATING_SOON + rh.gs(R.string.activity) -> TemporaryTarget.Reason.ACTIVITY + rh.gs(R.string.hypo) -> TemporaryTarget.Reason.HYPOGLYCEMIA + else -> TemporaryTarget.Reason.CUSTOM + }, + lowTarget = Profile.toMgdl(target, profileFunction.getUnits()), + highTarget = Profile.toMgdl(target, profileFunction.getUnits()) + ) + ).subscribe({ result -> + result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted temp 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) @@ -230,7 +251,7 @@ class TempTargetDialog : DialogFragmentWithDate() { override fun onResume() { super.onResume() - if(!queryingProtection) { + if (!queryingProtection) { queryingProtection = true activity?.let { activity -> val cancelFail = { @@ -239,8 +260,8 @@ class TempTargetDialog : DialogFragmentWithDate() { ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } - protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, { queryingProtection = false }, cancelFail, cancelFail) } } } -} +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_tempbasal.xml b/ui/src/main/res/layout/dialog_tempbasal.xml similarity index 100% rename from app/src/main/res/layout/dialog_tempbasal.xml rename to ui/src/main/res/layout/dialog_tempbasal.xml diff --git a/app/src/main/res/layout/dialog_temptarget.xml b/ui/src/main/res/layout/dialog_temptarget.xml similarity index 100% rename from app/src/main/res/layout/dialog_temptarget.xml rename to ui/src/main/res/layout/dialog_temptarget.xml