From 8013f903305066cdcfc0542ce97d91cef0b31a24 Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Fri, 4 Oct 2024 22:35:19 +0200 Subject: [PATCH 01/11] sms command to send insulin wip --- core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt | 1 + .../main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt | 6 +++++- core/ui/src/main/res/values/strings.xml | 2 ++ .../aaps/plugins/main/general/overview/OverviewPlugin.kt | 1 + plugins/main/src/main/res/values/strings.xml | 1 + ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt | 4 +++- ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt | 4 +++- 7 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt b/core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt index 2bb054853d6..45d390db2dd 100644 --- a/core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt +++ b/core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt @@ -39,6 +39,7 @@ enum class StringKey( AutomationLocation("location", "PASSIVE", hideParentScreenIfHidden = true), SmsAllowedNumbers("smscommunicator_allowednumbers", ""), + SmsReveiverNumber("sms_communicator_reveiver_number", ""), SmsOtpPassword("smscommunicator_otp_password", "", dependency = BooleanKey.SmsAllowRemoteCommands), VirtualPumpType("virtualpump_type", "Generic AAPS"), diff --git a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt index 29f87a91f0b..054f0474ae8 100644 --- a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt +++ b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt @@ -371,7 +371,11 @@ class BolusWizard @Inject constructor( .formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) ) if (config.NSCLIENT && insulinAfterConstraints > 0) - actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + // TODO: check phone number + if(1) + actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus + "bolusWizard.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + else + actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (useAlarm && !advisor && carbs > 0 && carbTime > 0) actions.add(rh.gs(app.aaps.core.ui.R.string.alarminxmin, carbTime).formatColor(context, rh, app.aaps.core.ui.R.attr.infoColor)) if (advisor) diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 6f5ed8199ad..a72647678b5 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -452,9 +452,11 @@ COB vs IOB !!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be overestimated thus more insulin could be given !!!!!]]> Deliver this part of bolus wizard result [%] + If number is provided, insulin and calculator buttons will change the way they work. They will send SMS command to inject bolus to a given number. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. Old glycemia time threshold [min] Bolus constraint applied: %1$.2f U to %2$.2f U Bolus will be recorded only (not delivered by pump) + Send sms with insulin request Run alarm when is time to eat No action selected, nothing will happen Carbs = 0. No action taken! diff --git a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt index c92e4bf97f8..fac82d450bc 100644 --- a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt +++ b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt @@ -286,6 +286,7 @@ class OverviewPlugin @Inject constructor( })) }) addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewBolusPercentage, dialogMessage = R.string.deliverpartofboluswizard, title = app.aaps.core.ui.R.string.partialboluswizard)) + addPreference(AdaptiveIntPreference(ctx = context, intKey = StringKey.SmsReveiverNumber, dialogMessage = R.string.sms_receiver_number_dialog, title = app.aaps.core.ui.R.string.sms_receiver_number)) addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewResetBolusPercentageTime, dialogMessage = R.string.deliver_part_of_boluswizard_reset_time, title = app.aaps.core.ui.R.string.partialboluswizard_reset_time)) addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewUseBolusAdvisor, summary = R.string.enable_bolus_advisor_summary, title = R.string.enable_bolus_advisor)) addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewUseBolusReminder, summary = R.string.enablebolusreminder_summary, title = R.string.enablebolusreminder)) diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index 2796978e7dc..bcb47471b2f 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -268,6 +268,7 @@ Shorten tab titles Show notes field in treatment dialogs Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm. + Receiver phone number for sms commands send from AAPS client phone Deliver full bolus (100%) if glycemia is older than Enable bolus advisor Use reminder to start eating later instead of wizard result during high glycemia ("pre-bolus") diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index 617c86d46ef..21662e89fa5 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -205,7 +205,9 @@ class InsulinDialog : DialogFragmentWithDate() { rh.gs(app.aaps.core.ui.R.string.bolus) + ": " + decimalFormatter.toPumpSupportedBolus(insulinAfterConstraints, activePlugin.activePump.pumpDescription.bolusStep) .formatColor(context, rh, app.aaps.core.ui.R.attr.bolusColor) ) - if (recordOnlyChecked) + if(1) + actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus + "insulinDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + else if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) actions.add( diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt index 8b40adcdf90..23c7706c90d 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt @@ -154,7 +154,9 @@ class TreatmentDialog : DialogFragmentWithDate() { app.aaps.core.ui.R.attr.bolusColor ) ) - if (recordOnlyChecked) + if(1) + actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus + "treatmentDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + else if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) actions.add( From 7dd7c3fd4fe54708d1daeea0d0afd4b6fd5e04e7 Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Thu, 10 Oct 2024 22:49:23 +0200 Subject: [PATCH 02/11] - fix compilation issues - preferences config update --- app/build.gradle.kts | 6 +++--- .../keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt | 2 +- .../kotlin/app/aaps/core/objects/wizard/BolusWizard.kt | 4 ++-- core/ui/src/main/res/values/strings.xml | 2 +- .../aaps/plugins/main/general/overview/OverviewPlugin.kt | 5 ++++- plugins/main/src/main/res/values/strings.xml | 2 +- ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt | 9 +++++---- .../main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt | 9 +++++---- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 97f1b87372e..dda392af282 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -239,7 +239,7 @@ println("-------------------") if (isMaster() && !gitAvailable()) { throw GradleException("GIT system is not available. On Windows try to run Android Studio as an Administrator. Check if GIT is installed and Studio have permissions to use it") } -if (isMaster() && !allCommitted()) { - throw GradleException("There are uncommitted changes. Clone sources again as described in wiki and do not allow gradle update") -} +// if (isMaster() && !allCommitted()) { +// throw GradleException("There are uncommitted changes. Clone sources again as described in wiki and do not allow gradle update") +// } diff --git a/core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt b/core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt index 45d390db2dd..932dc35bf85 100644 --- a/core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt +++ b/core/keys/src/main/kotlin/app/aaps/core/keys/StringKey.kt @@ -39,7 +39,7 @@ enum class StringKey( AutomationLocation("location", "PASSIVE", hideParentScreenIfHidden = true), SmsAllowedNumbers("smscommunicator_allowednumbers", ""), - SmsReveiverNumber("sms_communicator_reveiver_number", ""), + SmsReceiverNumber("sms_communicator_receiver_number", "", showInApsMode = false, showInPumpControlMode = false, dependency = BooleanKey.SmsAllowRemoteCommands), SmsOtpPassword("smscommunicator_otp_password", "", dependency = BooleanKey.SmsAllowRemoteCommands), VirtualPumpType("virtualpump_type", "Generic AAPS"), diff --git a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt index 054f0474ae8..fa835d56f5c 100644 --- a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt +++ b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt @@ -372,8 +372,8 @@ class BolusWizard @Inject constructor( ) if (config.NSCLIENT && insulinAfterConstraints > 0) // TODO: check phone number - if(1) - actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus + "bolusWizard.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + if(true) + actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus)+"bolusWizard.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) else actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (useAlarm && !advisor && carbs > 0 && carbTime > 0) diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index a72647678b5..9c83295b67c 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -452,7 +452,7 @@ COB vs IOB !!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be overestimated thus more insulin could be given !!!!!]]> Deliver this part of bolus wizard result [%] - If number is provided, insulin and calculator buttons will change the way they work. They will send SMS command to inject bolus to a given number. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. + Receiver phone number for sms commands send from AAPS client phone Old glycemia time threshold [min] Bolus constraint applied: %1$.2f U to %2$.2f U Bolus will be recorded only (not delivered by pump) diff --git a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt index fac82d450bc..68dd7d04e3c 100644 --- a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt +++ b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt @@ -45,6 +45,7 @@ import app.aaps.core.validators.preferences.AdaptiveClickPreference import app.aaps.core.validators.preferences.AdaptiveDoublePreference import app.aaps.core.validators.preferences.AdaptiveIntPreference import app.aaps.core.validators.preferences.AdaptiveIntentPreference +import app.aaps.core.validators.preferences.AdaptiveStringPreference import app.aaps.core.validators.preferences.AdaptiveSwitchPreference import app.aaps.core.validators.preferences.AdaptiveUnitPreference import app.aaps.plugins.main.R @@ -286,7 +287,9 @@ class OverviewPlugin @Inject constructor( })) }) addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewBolusPercentage, dialogMessage = R.string.deliverpartofboluswizard, title = app.aaps.core.ui.R.string.partialboluswizard)) - addPreference(AdaptiveIntPreference(ctx = context, intKey = StringKey.SmsReveiverNumber, dialogMessage = R.string.sms_receiver_number_dialog, title = app.aaps.core.ui.R.string.sms_receiver_number)) + addPreference(AdaptiveStringPreference(ctx = context, stringKey = StringKey.SmsReceiverNumber, dialogMessage = R.string.sms_receiver_number_dialog, title = app.aaps.core.ui.R.string.sms_receiver_number)) + + addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewResetBolusPercentageTime, dialogMessage = R.string.deliver_part_of_boluswizard_reset_time, title = app.aaps.core.ui.R.string.partialboluswizard_reset_time)) addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewUseBolusAdvisor, summary = R.string.enable_bolus_advisor_summary, title = R.string.enable_bolus_advisor)) addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewUseBolusReminder, summary = R.string.enablebolusreminder_summary, title = R.string.enablebolusreminder)) diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index bcb47471b2f..6601b1d0d65 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -268,7 +268,7 @@ Shorten tab titles Show notes field in treatment dialogs Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm. - Receiver phone number for sms commands send from AAPS client phone + If number is provided, insulin and calculator buttons will be able to send SMS command to inject bolus. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. Deliver full bolus (100%) if glycemia is older than Enable bolus advisor Use reminder to start eating later instead of wizard result during high glycemia ("pre-bolus") diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index 21662e89fa5..4b2491559f5 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -35,6 +35,7 @@ import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.core.interfaces.utils.SafeParse import app.aaps.core.keys.DoubleKey import app.aaps.core.keys.IntKey +import app.aaps.core.keys.StringKey import app.aaps.core.keys.UnitDoubleKey import app.aaps.core.objects.constraints.ConstraintObject import app.aaps.core.objects.extensions.formatColor @@ -125,8 +126,7 @@ class InsulinDialog : DialogFragmentWithDate() { val pump = activePlugin.activePump if (config.NSCLIENT) { - binding.recordOnly.isChecked = true - binding.recordOnly.isEnabled = false + binding.recordOnly.isChecked = preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() } val maxInsulin = constraintChecker.getMaxBolusAllowed().value() @@ -197,6 +197,7 @@ class InsulinDialog : DialogFragmentWithDate() { val actions: LinkedList = LinkedList() val units = profileFunction.getUnits() val unitLabel = if (units == GlucoseUnit.MMOL) rh.gs(app.aaps.core.ui.R.string.mmol) else rh.gs(app.aaps.core.ui.R.string.mgdl) + val smsNumber = preferences.get(StringKey.SmsReceiverNumber) val recordOnlyChecked = binding.recordOnly.isChecked val eatingSoonChecked = binding.startEatingSoonTt.isChecked @@ -205,8 +206,8 @@ class InsulinDialog : DialogFragmentWithDate() { rh.gs(app.aaps.core.ui.R.string.bolus) + ": " + decimalFormatter.toPumpSupportedBolus(insulinAfterConstraints, activePlugin.activePump.pumpDescription.bolusStep) .formatColor(context, rh, app.aaps.core.ui.R.attr.bolusColor) ) - if(1) - actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus + "insulinDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + if(true) + actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus)+"insulinDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) else if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt index 23c7706c90d..e521ab4a8e7 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt @@ -26,6 +26,7 @@ import app.aaps.core.interfaces.resources.ResourceHelper import app.aaps.core.interfaces.ui.UiInteraction import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.core.interfaces.utils.SafeParse +import app.aaps.core.keys.StringKey import app.aaps.core.objects.constraints.ConstraintObject import app.aaps.core.objects.extensions.formatColor import app.aaps.core.ui.dialogs.OKDialog @@ -105,8 +106,7 @@ class TreatmentDialog : DialogFragmentWithDate() { super.onViewCreated(view, savedInstanceState) if (config.NSCLIENT) { - binding.recordOnly.isChecked = true - binding.recordOnly.isEnabled = false + binding.recordOnly.isChecked = preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() } val maxCarbs = constraintChecker.getMaxCarbsAllowed().value().toDouble() val maxInsulin = constraintChecker.getMaxBolusAllowed().value() @@ -141,6 +141,7 @@ class TreatmentDialog : DialogFragmentWithDate() { val pumpDescription = activePlugin.activePump.pumpDescription val insulin = SafeParse.stringToDouble(binding.insulin.text) val carbs = SafeParse.stringToInt(binding.carbs.text) + val phoneNumber = preferences.get(StringKey.SmsReceiverNumber) val recordOnlyChecked = binding.recordOnly.isChecked val actions: LinkedList = LinkedList() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, aapsLogger)).value() @@ -154,8 +155,8 @@ class TreatmentDialog : DialogFragmentWithDate() { app.aaps.core.ui.R.attr.bolusColor ) ) - if(1) - actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus + "treatmentDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + if(true) + actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus)+"treatmentDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) else if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) From 793c36e16009edd020980c3fdd9d7bfd8c57fa7d Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Thu, 17 Oct 2024 21:28:05 +0200 Subject: [PATCH 03/11] - working dialog from insulindialog.kt - TODO: calc wizard doesn't send sms, remove animation --- .../kotlin/app/aaps/ui/dialogs/InsulinDialog.kt | 13 +++++++++---- .../kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt | 14 ++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index 4b2491559f5..9c3d4eb243a 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -30,6 +30,8 @@ import app.aaps.core.interfaces.pump.defs.determineCorrectBolusStepSize import app.aaps.core.interfaces.queue.Callback import app.aaps.core.interfaces.queue.CommandQueue import app.aaps.core.interfaces.resources.ResourceHelper +import app.aaps.core.interfaces.smsCommunicator.Sms +import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import app.aaps.core.interfaces.ui.UiInteraction import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.core.interfaces.utils.SafeParse @@ -59,6 +61,7 @@ import kotlin.math.max class InsulinDialog : DialogFragmentWithDate() { + @Inject lateinit var smsCommunicator: SmsCommunicator @Inject lateinit var constraintChecker: ConstraintsChecker @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @@ -197,7 +200,7 @@ class InsulinDialog : DialogFragmentWithDate() { val actions: LinkedList = LinkedList() val units = profileFunction.getUnits() val unitLabel = if (units == GlucoseUnit.MMOL) rh.gs(app.aaps.core.ui.R.string.mmol) else rh.gs(app.aaps.core.ui.R.string.mgdl) - val smsNumber = preferences.get(StringKey.SmsReceiverNumber) + val phoneNumber = preferences.get(StringKey.SmsReceiverNumber) val recordOnlyChecked = binding.recordOnly.isChecked val eatingSoonChecked = binding.startEatingSoonTt.isChecked @@ -206,10 +209,10 @@ class InsulinDialog : DialogFragmentWithDate() { rh.gs(app.aaps.core.ui.R.string.bolus) + ": " + decimalFormatter.toPumpSupportedBolus(insulinAfterConstraints, activePlugin.activePump.pumpDescription.bolusStep) .formatColor(context, rh, app.aaps.core.ui.R.attr.bolusColor) ) - if(true) - actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus)+"insulinDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if (recordOnlyChecked) + if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + else if(!phoneNumber.isNullOrBlank()) + actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus)+"insulinDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) actions.add( rh.gs(app.aaps.core.ui.R.string.bolus_constraint_applied_warn, insulin, insulinAfterConstraints).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) @@ -272,6 +275,8 @@ class InsulinDialog : DialogFragmentWithDate() { ).subscribe() if (timeOffset == 0) automation.removeAutomationEventBolusReminder() + } else if(!phoneNumber.isNullOrBlank()){ + smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + detailedBolusInfo.insulin)) } else { uel.log( Action.BOLUS, Sources.InsulinDialog, diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt index e521ab4a8e7..878882a1eb6 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt @@ -26,6 +26,8 @@ import app.aaps.core.interfaces.resources.ResourceHelper import app.aaps.core.interfaces.ui.UiInteraction import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.core.interfaces.utils.SafeParse +import app.aaps.core.interfaces.smsCommunicator.Sms +import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import app.aaps.core.keys.StringKey import app.aaps.core.objects.constraints.ConstraintObject import app.aaps.core.objects.extensions.formatColor @@ -45,6 +47,7 @@ import kotlin.math.abs class TreatmentDialog : DialogFragmentWithDate() { + @Inject lateinit var smsCommunicator: SmsCommunicator @Inject lateinit var constraintChecker: ConstraintsChecker @Inject lateinit var rh: ResourceHelper @Inject lateinit var activePlugin: ActivePlugin @@ -155,10 +158,11 @@ class TreatmentDialog : DialogFragmentWithDate() { app.aaps.core.ui.R.attr.bolusColor ) ) - if(true) - actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus)+"treatmentDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if (recordOnlyChecked) + if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + else if(phoneNumber.isNullOrBlank()) + actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) actions.add( rh.gs(app.aaps.core.ui.R.string.bolus_constraint_applied_warn, insulin, insulinAfterConstraints).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) @@ -202,6 +206,8 @@ class TreatmentDialog : DialogFragmentWithDate() { source = Sources.TreatmentDialog, note = if (carbsAfterConstraints != 0) rh.gs(app.aaps.core.ui.R.string.record) else "" ).subscribe() + } else if(phoneNumber.isNullOrBlank()){ + smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + detailedBolusInfo.insulin)) } else { if (detailedBolusInfo.insulin > 0) { uel.log( @@ -252,4 +258,4 @@ class TreatmentDialog : DialogFragmentWithDate() { } } } -} \ No newline at end of file +} From e6d87d5790308ced62cf1dfeccace7730eba0340 Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Wed, 23 Oct 2024 19:39:53 +0200 Subject: [PATCH 04/11] - calc wizard working - create calc entry in history if sms was send --- .../aaps/core/objects/wizard/BolusWizard.kt | 35 +++++++++++++------ core/ui/src/main/res/values/strings.xml | 2 +- .../app/aaps/ui/dialogs/InsulinDialog.kt | 5 +-- .../app/aaps/ui/dialogs/TreatmentDialog.kt | 5 +-- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt index fa835d56f5c..4c13f6d8269 100644 --- a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt +++ b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt @@ -43,6 +43,7 @@ import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.core.interfaces.utils.Round import app.aaps.core.keys.BooleanKey import app.aaps.core.keys.Preferences +import app.aaps.core.keys.StringKey import app.aaps.core.objects.constraints.ConstraintObject import app.aaps.core.objects.extensions.formatColor import app.aaps.core.objects.extensions.highValueToUnitsToString @@ -52,6 +53,8 @@ import app.aaps.core.ui.dialogs.OKDialog import app.aaps.core.utils.HtmlHelper import app.aaps.core.utils.JsonHelper import dagger.android.HasAndroidInjector +import app.aaps.core.interfaces.smsCommunicator.Sms +import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import java.util.Calendar import java.util.LinkedList import javax.inject.Inject @@ -63,6 +66,7 @@ class BolusWizard @Inject constructor( val injector: HasAndroidInjector ) { + @Inject lateinit var smsCommunicator: SmsCommunicator @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rh: ResourceHelper @Inject lateinit var rxBus: RxBus @@ -86,9 +90,12 @@ class BolusWizard @Inject constructor( @Inject lateinit var processedDeviceStatusData: ProcessedDeviceStatusData var timeStamp: Long + // var phoneNumber: String init { injector.androidInjector().inject(this) + // TODO: why this@BolusWizar.phoneNumber not visible in scoped DetailedBolusInfo().apply + // phoneNumber = preferences.get(StringKey.SmsReceiverNumber) timeStamp = dateUtil.now() } @@ -330,7 +337,7 @@ class BolusWizard @Inject constructor( } private fun confirmMessageAfterConstraints(context: Context, advisor: Boolean, quickWizardEntry: QuickWizardEntry? = null): Spanned { - + var phoneNumber = preferences.get(StringKey.SmsReceiverNumber) val actions: LinkedList = LinkedList() if (insulinAfterConstraints > 0) { val pct = if (percentageCorrection != 100) " ($percentageCorrection%)" else "" @@ -371,9 +378,8 @@ class BolusWizard @Inject constructor( .formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) ) if (config.NSCLIENT && insulinAfterConstraints > 0) - // TODO: check phone number - if(true) - actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus)+"bolusWizard.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + if(config.NSCLIENT && !phoneNumber.isNullOrBlank()) + actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification)+"bolusWizard.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) else actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (useAlarm && !advisor && carbs > 0 && carbTime > 0) @@ -542,15 +548,22 @@ class BolusWizard @Inject constructor( ValueWithUnit.Minute(carbTime).takeIf { carbTime != 0 } ).filterNotNull() ) - commandQueue.bolus(this, object : Callback() { - override fun run() { - if (!result.success) { - uiInteraction.runAlarm(result.comment, rh.gs(app.aaps.core.ui.R.string.treatmentdeliveryerror), app.aaps.core.ui.R.raw.boluserror) + var phoneNumber = preferences.get(StringKey.SmsReceiverNumber) + if (config.NSCLIENT && !phoneNumber.isNullOrBlank()) { + rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) + smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + insulin)) + } else if (!config.APS) + commandQueue.bolus(this, object : Callback() { + override fun run() { + if (!result.success) { + uiInteraction.runAlarm(result.comment, rh.gs(app.aaps.core.ui.R.string.treatmentdeliveryerror), app.aaps.core.ui.R.raw.boluserror) + } } - } - }) + }) + } + bolusCalculatorResult?.let { + persistenceLayer.insertOrUpdateBolusCalculatorResult(it).blockingGet() } - bolusCalculatorResult?.let { persistenceLayer.insertOrUpdateBolusCalculatorResult(it).blockingGet() } } if (useAlarm && carbs > 0 && carbTime > 0) { automation.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt()) diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 9c83295b67c..33e7a8d44f4 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -456,7 +456,7 @@ Old glycemia time threshold [min] Bolus constraint applied: %1$.2f U to %2$.2f U Bolus will be recorded only (not delivered by pump) - Send sms with insulin request + Send sms with insulin request Run alarm when is time to eat No action selected, nothing will happen Carbs = 0. No action taken! diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index 9c3d4eb243a..7ae1e35fd31 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -211,8 +211,9 @@ class InsulinDialog : DialogFragmentWithDate() { ) if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if(!phoneNumber.isNullOrBlank()) - actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus)+"insulinDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + else if(config.NSCLIENT && !phoneNumber.isNullOrBlank()) + actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification) + "insulinDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) actions.add( rh.gs(app.aaps.core.ui.R.string.bolus_constraint_applied_warn, insulin, insulinAfterConstraints).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt index 878882a1eb6..afbb70dd284 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt @@ -160,8 +160,9 @@ class TreatmentDialog : DialogFragmentWithDate() { ) if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if(phoneNumber.isNullOrBlank()) - actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + else if (!phoneNumber.isNullOrBlank()) + actions.add((rh.gs( + app.aaps.core.ui.R.string.sms_bolus_notification)+"treatmentdialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) actions.add( From 9c86d099f4e19ae19d31a26e04bd1d4721a6f8cf Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Wed, 23 Oct 2024 20:01:40 +0200 Subject: [PATCH 05/11] cleanup and formatting --- app/build.gradle.kts | 6 ++-- .../aaps/core/objects/wizard/BolusWizard.kt | 14 ++++------ .../app/aaps/ui/dialogs/InsulinDialog.kt | 4 +-- .../app/aaps/ui/dialogs/TreatmentDialog.kt | 28 +++++++++++-------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index dda392af282..97f1b87372e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -239,7 +239,7 @@ println("-------------------") if (isMaster() && !gitAvailable()) { throw GradleException("GIT system is not available. On Windows try to run Android Studio as an Administrator. Check if GIT is installed and Studio have permissions to use it") } -// if (isMaster() && !allCommitted()) { -// throw GradleException("There are uncommitted changes. Clone sources again as described in wiki and do not allow gradle update") -// } +if (isMaster() && !allCommitted()) { + throw GradleException("There are uncommitted changes. Clone sources again as described in wiki and do not allow gradle update") +} diff --git a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt index 4c13f6d8269..e13cab51640 100644 --- a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt +++ b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt @@ -37,6 +37,8 @@ import app.aaps.core.interfaces.resources.ResourceHelper import app.aaps.core.interfaces.rx.bus.RxBus import app.aaps.core.interfaces.rx.events.EventRefreshOverview import app.aaps.core.interfaces.sharedPreferences.SP +import app.aaps.core.interfaces.smsCommunicator.Sms +import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import app.aaps.core.interfaces.ui.UiInteraction import app.aaps.core.interfaces.utils.DateUtil import app.aaps.core.interfaces.utils.DecimalFormatter @@ -53,8 +55,6 @@ import app.aaps.core.ui.dialogs.OKDialog import app.aaps.core.utils.HtmlHelper import app.aaps.core.utils.JsonHelper import dagger.android.HasAndroidInjector -import app.aaps.core.interfaces.smsCommunicator.Sms -import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import java.util.Calendar import java.util.LinkedList import javax.inject.Inject @@ -378,8 +378,8 @@ class BolusWizard @Inject constructor( .formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) ) if (config.NSCLIENT && insulinAfterConstraints > 0) - if(config.NSCLIENT && !phoneNumber.isNullOrBlank()) - actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification)+"bolusWizard.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + if (!phoneNumber.isNullOrBlank()) + actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) else actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (useAlarm && !advisor && carbs > 0 && carbTime > 0) @@ -549,7 +549,7 @@ class BolusWizard @Inject constructor( ).filterNotNull() ) var phoneNumber = preferences.get(StringKey.SmsReceiverNumber) - if (config.NSCLIENT && !phoneNumber.isNullOrBlank()) { + if (!phoneNumber.isNullOrBlank()) { rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + insulin)) } else if (!config.APS) @@ -561,9 +561,7 @@ class BolusWizard @Inject constructor( } }) } - bolusCalculatorResult?.let { - persistenceLayer.insertOrUpdateBolusCalculatorResult(it).blockingGet() - } + bolusCalculatorResult?.let { persistenceLayer.insertOrUpdateBolusCalculatorResult(it).blockingGet() } } if (useAlarm && carbs > 0 && carbTime > 0) { automation.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt()) diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index 7ae1e35fd31..186dbf3b5c1 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -211,8 +211,8 @@ class InsulinDialog : DialogFragmentWithDate() { ) if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if(config.NSCLIENT && !phoneNumber.isNullOrBlank()) - actions.add((rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification) + "insulinDialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + else if(!phoneNumber.isNullOrBlank()) + actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) actions.add( diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt index afbb70dd284..27b130fb3ff 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt @@ -23,11 +23,11 @@ import app.aaps.core.interfaces.pump.defs.determineCorrectBolusStepSize import app.aaps.core.interfaces.queue.Callback import app.aaps.core.interfaces.queue.CommandQueue import app.aaps.core.interfaces.resources.ResourceHelper +import app.aaps.core.interfaces.smsCommunicator.Sms +import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import app.aaps.core.interfaces.ui.UiInteraction import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.core.interfaces.utils.SafeParse -import app.aaps.core.interfaces.smsCommunicator.Sms -import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import app.aaps.core.keys.StringKey import app.aaps.core.objects.constraints.ConstraintObject import app.aaps.core.objects.extensions.formatColor @@ -161,8 +161,11 @@ class TreatmentDialog : DialogFragmentWithDate() { if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) else if (!phoneNumber.isNullOrBlank()) - actions.add((rh.gs( - app.aaps.core.ui.R.string.sms_bolus_notification)+"treatmentdialog.kt").formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) + actions.add( + rh.gs( + app.aaps.core.ui.R.string.sms_bolus_notification + ).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) + ) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) actions.add( @@ -194,12 +197,15 @@ class TreatmentDialog : DialogFragmentWithDate() { detailedBolusInfo.context = context if (recordOnlyChecked) { if (detailedBolusInfo.insulin > 0) - disposable += persistenceLayer.insertOrUpdateBolus( - bolus = detailedBolusInfo.createBolus(), - action = action, - source = Sources.TreatmentDialog, - note = if (insulinAfterConstraints != 0.0) rh.gs(app.aaps.core.ui.R.string.record) else "" - ).subscribe() + if (!phoneNumber.isNullOrBlank()) + smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + detailedBolusInfo.insulin)) + else + disposable += persistenceLayer.insertOrUpdateBolus( + bolus = detailedBolusInfo.createBolus(), + action = action, + source = Sources.TreatmentDialog, + note = if (insulinAfterConstraints != 0.0) rh.gs(app.aaps.core.ui.R.string.record) else "" + ).subscribe() if (detailedBolusInfo.carbs > 0) disposable += persistenceLayer.insertOrUpdateCarbs( carbs = detailedBolusInfo.createCarbs(), @@ -207,8 +213,6 @@ class TreatmentDialog : DialogFragmentWithDate() { source = Sources.TreatmentDialog, note = if (carbsAfterConstraints != 0) rh.gs(app.aaps.core.ui.R.string.record) else "" ).subscribe() - } else if(phoneNumber.isNullOrBlank()){ - smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + detailedBolusInfo.insulin)) } else { if (detailedBolusInfo.insulin > 0) { uel.log( From d18ab0d9efd1d62c71b1a894f67045be0ec3a015 Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Thu, 31 Oct 2024 22:22:47 +0100 Subject: [PATCH 06/11] - improve sms option placement in menu - fix this option to work only on aapsclient, only when it's enabledd --- .../kotlin/app/aaps/activities/MyPreferenceFragment.kt | 2 ++ app/src/main/res/values/strings.xml | 4 ++++ .../kotlin/app/aaps/core/objects/wizard/BolusWizard.kt | 4 ++-- .../plugins/main/general/overview/OverviewPlugin.kt | 1 - plugins/main/src/main/res/values/strings.xml | 4 +--- .../main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt | 10 +++++++--- .../main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt | 5 +++-- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt b/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt index dc68b1777b9..ef497f4561a 100644 --- a/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt @@ -407,6 +407,8 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang summary = app.aaps.plugins.main.R.string.theme_switcher_summary ) ) + addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.SmsAllowRemoteCommands, title = R.string.client_allow_sms)) + addPreference(AdaptiveStringPreference(ctx = context, stringKey = StringKey.SmsReceiverNumber, dialogMessage = R.string.sms_receiver_number_dialog, title = app.aaps.core.ui.R.string.sms_receiver_number)) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3e1988b7f9b..744f9da46f6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,10 @@ Authorization failed Cannula Identification not set in dev mode + dialog + + If number is provided, insulin and calculator buttons will be able to send SMS command to inject bolus. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. + Allow AAPS client to send SMS with bolus command Remove selected items %1$d selected diff --git a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt index e13cab51640..77d083b341b 100644 --- a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt +++ b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt @@ -378,7 +378,7 @@ class BolusWizard @Inject constructor( .formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) ) if (config.NSCLIENT && insulinAfterConstraints > 0) - if (!phoneNumber.isNullOrBlank()) + if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) else actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) @@ -549,7 +549,7 @@ class BolusWizard @Inject constructor( ).filterNotNull() ) var phoneNumber = preferences.get(StringKey.SmsReceiverNumber) - if (!phoneNumber.isNullOrBlank()) { + if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) { rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + insulin)) } else if (!config.APS) diff --git a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt index 68dd7d04e3c..f4cb00ecb1f 100644 --- a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt +++ b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt @@ -287,7 +287,6 @@ class OverviewPlugin @Inject constructor( })) }) addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewBolusPercentage, dialogMessage = R.string.deliverpartofboluswizard, title = app.aaps.core.ui.R.string.partialboluswizard)) - addPreference(AdaptiveStringPreference(ctx = context, stringKey = StringKey.SmsReceiverNumber, dialogMessage = R.string.sms_receiver_number_dialog, title = app.aaps.core.ui.R.string.sms_receiver_number)) addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewResetBolusPercentageTime, dialogMessage = R.string.deliver_part_of_boluswizard_reset_time, title = app.aaps.core.ui.R.string.partialboluswizard_reset_time)) diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index 6601b1d0d65..475c4368737 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -2,7 +2,6 @@ - SMS Communicator SMS Remote control AAPS using SMS commands. @@ -186,7 +185,7 @@ patch pump age Patch pump - + Show status lights on home screen Threshold warning cannula age [h] Threshold critical cannula age [h] @@ -268,7 +267,6 @@ Shorten tab titles Show notes field in treatment dialogs Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm. - If number is provided, insulin and calculator buttons will be able to send SMS command to inject bolus. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. Deliver full bolus (100%) if glycemia is older than Enable bolus advisor Use reminder to start eating later instead of wizard result during high glycemia ("pre-bolus") diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index 186dbf3b5c1..2e94957a6a9 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -35,6 +35,7 @@ import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import app.aaps.core.interfaces.ui.UiInteraction import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.core.interfaces.utils.SafeParse +import app.aaps.core.keys.BooleanKey import app.aaps.core.keys.DoubleKey import app.aaps.core.keys.IntKey import app.aaps.core.keys.StringKey @@ -129,7 +130,10 @@ class InsulinDialog : DialogFragmentWithDate() { val pump = activePlugin.activePump if (config.NSCLIENT) { - binding.recordOnly.isChecked = preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() + // If SmsAllowRemoteCommands is True, then user might use either SMS command or record only, otherwise hardcode record_only option + val allow_sms = preferences.get(BooleanKey.SmsAllowRemoteCommands) + binding.recordOnly.isEnabled = allow_sms + binding.recordOnly.isChecked = if (allow_sms) preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() else true } val maxInsulin = constraintChecker.getMaxBolusAllowed().value() @@ -211,7 +215,7 @@ class InsulinDialog : DialogFragmentWithDate() { ) if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if(!phoneNumber.isNullOrBlank()) + else if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) @@ -276,7 +280,7 @@ class InsulinDialog : DialogFragmentWithDate() { ).subscribe() if (timeOffset == 0) automation.removeAutomationEventBolusReminder() - } else if(!phoneNumber.isNullOrBlank()){ + } else if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) { smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + detailedBolusInfo.insulin)) } else { uel.log( diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt index 27b130fb3ff..430dd95ca59 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt @@ -28,6 +28,7 @@ import app.aaps.core.interfaces.smsCommunicator.SmsCommunicator import app.aaps.core.interfaces.ui.UiInteraction import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.core.interfaces.utils.SafeParse +import app.aaps.core.keys.BooleanKey import app.aaps.core.keys.StringKey import app.aaps.core.objects.constraints.ConstraintObject import app.aaps.core.objects.extensions.formatColor @@ -160,7 +161,7 @@ class TreatmentDialog : DialogFragmentWithDate() { ) if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if (!phoneNumber.isNullOrBlank()) + else if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) actions.add( rh.gs( app.aaps.core.ui.R.string.sms_bolus_notification @@ -197,7 +198,7 @@ class TreatmentDialog : DialogFragmentWithDate() { detailedBolusInfo.context = context if (recordOnlyChecked) { if (detailedBolusInfo.insulin > 0) - if (!phoneNumber.isNullOrBlank()) + if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + detailedBolusInfo.insulin)) else disposable += persistenceLayer.insertOrUpdateBolus( From a3107c06b18eba6437a4e6ba8309ca1d6a4c1fa9 Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Thu, 31 Oct 2024 23:06:47 +0100 Subject: [PATCH 07/11] fix some sonarscan issues --- .../main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt | 2 +- .../aaps/plugins/main/general/overview/OverviewPlugin.kt | 1 - ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt index 77d083b341b..98a2be3cdd3 100644 --- a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt +++ b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt @@ -94,7 +94,7 @@ class BolusWizard @Inject constructor( init { injector.androidInjector().inject(this) - // TODO: why this@BolusWizar.phoneNumber not visible in scoped DetailedBolusInfo().apply + // why this@BolusWizar.phoneNumber not visible in scoped DetailedBolusInfo().apply // phoneNumber = preferences.get(StringKey.SmsReceiverNumber) timeStamp = dateUtil.now() } diff --git a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt index f4cb00ecb1f..427d3dd4672 100644 --- a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt +++ b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt @@ -45,7 +45,6 @@ import app.aaps.core.validators.preferences.AdaptiveClickPreference import app.aaps.core.validators.preferences.AdaptiveDoublePreference import app.aaps.core.validators.preferences.AdaptiveIntPreference import app.aaps.core.validators.preferences.AdaptiveIntentPreference -import app.aaps.core.validators.preferences.AdaptiveStringPreference import app.aaps.core.validators.preferences.AdaptiveSwitchPreference import app.aaps.core.validators.preferences.AdaptiveUnitPreference import app.aaps.plugins.main.R diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index 2e94957a6a9..d3fd6a811ae 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -131,9 +131,9 @@ class InsulinDialog : DialogFragmentWithDate() { val pump = activePlugin.activePump if (config.NSCLIENT) { // If SmsAllowRemoteCommands is True, then user might use either SMS command or record only, otherwise hardcode record_only option - val allow_sms = preferences.get(BooleanKey.SmsAllowRemoteCommands) - binding.recordOnly.isEnabled = allow_sms - binding.recordOnly.isChecked = if (allow_sms) preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() else true + val allowSms = preferences.get(BooleanKey.SmsAllowRemoteCommands) + binding.recordOnly.isEnabled = allowSms + binding.recordOnly.isChecked = preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() } val maxInsulin = constraintChecker.getMaxBolusAllowed().value() From 79912633e210807e7572d1cec3b07a0bd5664b7d Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Fri, 1 Nov 2024 15:47:12 +0100 Subject: [PATCH 08/11] review fixes --- app/src/main/res/values/strings.xml | 4 ++-- core/ui/src/main/res/values/strings.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 744f9da46f6..6a3affd0ab2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,9 +26,9 @@ Cannula Identification not set in dev mode dialog - + If number is provided, insulin and calculator buttons will be able to send SMS command to inject bolus. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. - Allow AAPS client to send SMS with bolus command + Allow AAPSClient to send SMS with bolus command Remove selected items %1$d selected diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 33e7a8d44f4..bc73a54ff4e 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -452,7 +452,7 @@ COB vs IOB !!!!! Slow carbs absorption detected: %2$d%% of time. Double check your calculation. COB can be overestimated thus more insulin could be given !!!!!]]> Deliver this part of bolus wizard result [%] - Receiver phone number for sms commands send from AAPS client phone + Receiver phone number for sms commands sent from AAPSClient phone Old glycemia time threshold [min] Bolus constraint applied: %1$.2f U to %2$.2f U Bolus will be recorded only (not delivered by pump) From b093f7f0b7094af2db0fdb8c722fe275542d0ed9 Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Fri, 15 Nov 2024 21:41:29 +0100 Subject: [PATCH 09/11] add warning regarding IOB synchronization --- app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt | 2 +- app/src/main/res/values/strings.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt b/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt index ef497f4561a..46883de3df5 100644 --- a/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt @@ -407,7 +407,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang summary = app.aaps.plugins.main.R.string.theme_switcher_summary ) ) - addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.SmsAllowRemoteCommands, title = R.string.client_allow_sms)) + addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.SmsAllowRemoteCommands, summary = R.string.client_allow_sms_warning, title = R.string.client_allow_sms)) addPreference(AdaptiveStringPreference(ctx = context, stringKey = StringKey.SmsReceiverNumber, dialogMessage = R.string.sms_receiver_number_dialog, title = app.aaps.core.ui.R.string.sms_receiver_number)) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6a3affd0ab2..9f9e49e0b30 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,6 +29,7 @@ If number is provided, insulin and calculator buttons will be able to send SMS command to inject bolus. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. Allow AAPSClient to send SMS with bolus command + "Use this functionality with caution. Before enabling make sure that IOB and BG is synchronized between AAPS and AAPSClient. Some users reported issue with that. Use it at your own risk, every time you shall check IOB and BG before issuing a bolus. You can do that by sending 'BG' command." Remove selected items %1$d selected From 9f2a45e669729cba50d238db74eac375a9b800da Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Sun, 8 Dec 2024 22:05:11 +0100 Subject: [PATCH 10/11] - move sms related settings to Button menu - enable phone number verification in settings - fix issues - update AAPS response for SMS bolus request to include IOB --- .../aaps/activities/MyPreferenceFragment.kt | 2 -- app/src/main/res/values/strings.xml | 5 ----- .../aaps/core/objects/wizard/BolusWizard.kt | 16 ++++++++------ .../main/general/overview/OverviewPlugin.kt | 22 ++++++++++++++----- .../smsCommunicator/SmsCommunicatorPlugin.kt | 5 +++-- plugins/main/src/main/res/values/strings.xml | 10 ++++++--- .../app/aaps/ui/dialogs/InsulinDialog.kt | 14 ++++++++---- .../app/aaps/ui/dialogs/TreatmentDialog.kt | 13 +++++++---- 8 files changed, 55 insertions(+), 32 deletions(-) diff --git a/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt b/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt index 46883de3df5..dc68b1777b9 100644 --- a/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/kotlin/app/aaps/activities/MyPreferenceFragment.kt @@ -407,8 +407,6 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang summary = app.aaps.plugins.main.R.string.theme_switcher_summary ) ) - addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.SmsAllowRemoteCommands, summary = R.string.client_allow_sms_warning, title = R.string.client_allow_sms)) - addPreference(AdaptiveStringPreference(ctx = context, stringKey = StringKey.SmsReceiverNumber, dialogMessage = R.string.sms_receiver_number_dialog, title = app.aaps.core.ui.R.string.sms_receiver_number)) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f9e49e0b30..3e1988b7f9b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,11 +25,6 @@ Authorization failed Cannula Identification not set in dev mode - dialog - - If number is provided, insulin and calculator buttons will be able to send SMS command to inject bolus. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. - Allow AAPSClient to send SMS with bolus command - "Use this functionality with caution. Before enabling make sure that IOB and BG is synchronized between AAPS and AAPSClient. Some users reported issue with that. Use it at your own risk, every time you shall check IOB and BG before issuing a bolus. You can do that by sending 'BG' command." Remove selected items %1$d selected diff --git a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt index 98a2be3cdd3..db8b30656ca 100644 --- a/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt +++ b/core/objects/src/main/kotlin/app/aaps/core/objects/wizard/BolusWizard.kt @@ -552,14 +552,16 @@ class BolusWizard @Inject constructor( if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) { rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor) smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + insulin)) - } else if (!config.APS) - commandQueue.bolus(this, object : Callback() { - override fun run() { - if (!result.success) { - uiInteraction.runAlarm(result.comment, rh.gs(app.aaps.core.ui.R.string.treatmentdeliveryerror), app.aaps.core.ui.R.raw.boluserror) - } + insulin = 0.0 // commandQueue will process carbs + } + + commandQueue.bolus(this, object : Callback() { + override fun run() { + if (!result.success) { + uiInteraction.runAlarm(result.comment, rh.gs(app.aaps.core.ui.R.string.treatmentdeliveryerror), app.aaps.core.ui.R.raw.boluserror) } - }) + } + }) } bolusCalculatorResult?.let { persistenceLayer.insertOrUpdateBolusCalculatorResult(it).blockingGet() } } diff --git a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt index 427d3dd4672..3f1f60b916e 100644 --- a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt +++ b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/overview/OverviewPlugin.kt @@ -41,10 +41,13 @@ import app.aaps.core.objects.extensions.putString import app.aaps.core.objects.extensions.store import app.aaps.core.objects.extensions.storeBoolean import app.aaps.core.objects.extensions.storeString +import app.aaps.core.validators.DefaultEditTextValidator +import app.aaps.core.validators.EditTextValidator import app.aaps.core.validators.preferences.AdaptiveClickPreference import app.aaps.core.validators.preferences.AdaptiveDoublePreference import app.aaps.core.validators.preferences.AdaptiveIntPreference import app.aaps.core.validators.preferences.AdaptiveIntentPreference +import app.aaps.core.validators.preferences.AdaptiveStringPreference import app.aaps.core.validators.preferences.AdaptiveSwitchPreference import app.aaps.core.validators.preferences.AdaptiveUnitPreference import app.aaps.plugins.main.R @@ -219,6 +222,13 @@ class OverviewPlugin @Inject constructor( addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewShowTreatmentButton, title = R.string.treatments)) addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewShowWizardButton, title = R.string.calculator_label)) addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewShowInsulinButton, title = app.aaps.core.ui.R.string.configbuilder_insulin)) + addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.SmsAllowRemoteCommands, summary = R.string.client_allow_sms_warning, title = R.string.client_allow_sms)) + addPreference( + AdaptiveStringPreference( + ctx = context, stringKey = StringKey.SmsReceiverNumber, dialogMessage = R.string.sms_receiver_number_dialog, title = app.aaps.core.ui.R.string.sms_receiver_number, + validatorParams = DefaultEditTextValidator.Parameters(testType = EditTextValidator.TEST_PHONE) + ) + ) addPreference(AdaptiveDoublePreference(ctx = context, doubleKey = DoubleKey.OverviewInsulinButtonIncrement1, dialogMessage = R.string.insulin_increment_button_message, title = R.string.firstinsulinincrement)) addPreference(AdaptiveDoublePreference(ctx = context, doubleKey = DoubleKey.OverviewInsulinButtonIncrement2, dialogMessage = R.string.insulin_increment_button_message, title = R.string.secondinsulinincrement)) addPreference(AdaptiveDoublePreference(ctx = context, doubleKey = DoubleKey.OverviewInsulinButtonIncrement3, dialogMessage = R.string.insulin_increment_button_message, title = R.string.thirdinsulinincrement)) @@ -279,11 +289,13 @@ class OverviewPlugin @Inject constructor( addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewResCritical, title = R.string.statuslights_res_critical)) addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewBattWarning, title = R.string.statuslights_bat_warning)) addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewBattCritical, title = R.string.statuslights_bat_critical)) - addPreference(AdaptiveClickPreference(ctx = context, stringKey = StringKey.OverviewCopySettingsFromNs, title = R.string.statuslights_copy_ns, - onPreferenceClickListener = { - nsSettingStatus.copyStatusLightsNsSettings(context) - true - })) + addPreference( + AdaptiveClickPreference(ctx = context, stringKey = StringKey.OverviewCopySettingsFromNs, title = R.string.statuslights_copy_ns, + onPreferenceClickListener = { + nsSettingStatus.copyStatusLightsNsSettings(context) + true + }) + ) }) addPreference(AdaptiveIntPreference(ctx = context, intKey = IntKey.OverviewBolusPercentage, dialogMessage = R.string.deliverpartofboluswizard, title = app.aaps.core.ui.R.string.partialboluswizard)) diff --git a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/smsCommunicator/SmsCommunicatorPlugin.kt b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/smsCommunicator/SmsCommunicatorPlugin.kt index 7e36ee88d28..6ce0c81854e 100644 --- a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -933,11 +933,12 @@ class SmsCommunicatorPlugin @Inject constructor( if (divided.size == 3 && !isMeal) { sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) } else if (bolus > 0.0) { + val iob = (iobCobCalculator.calculateIobFromBolus() + iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).round() val passCode = generatePassCode() val reply = if (isMeal) - rh.gs(R.string.smscommunicator_meal_bolus_reply_with_code, bolus, passCode) + rh.gs(R.string.smscommunicator_meal_bolus_reply_with_code, bolus, passCode, iob) else - rh.gs(R.string.smscommunicator_bolus_reply_with_code, bolus, passCode) + rh.gs(R.string.smscommunicator_bolus_reply_with_code, bolus, passCode, iob) receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(pumpCommand = true, bolus) { override fun run() { diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index 475c4368737..615c6037ffd 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -33,8 +33,8 @@ Timeout while waiting for finish of previous pump communication Allowed phone numbers +XXXXXXXXXX;+YYYYYYYYYY - To deliver bolus %1$.2fU reply with code %2$s - To deliver meal bolus %1$.2fU reply with code %2$s + To deliver bolus %1$.2fU reply with code %2$s. Current IOB is %3$.2fU + To deliver meal bolus %1$.2fU reply with code %2$s. Current IOB is %3$.2fU To set the Temp Target %1$s reply with code %2$s To cancel Temp Target reply with code %1$s To disable the SMS Remote Service reply with code %1$s.\n\nKeep in mind that you\'ll able to reactivate it directly from the AAPS master smartphone only. @@ -275,8 +275,12 @@ Enable bolus reminder Use reminder to bolus later with wizard ("post-bolus") Run %s? + + If number is provided, insulin and calculator buttons will be able to send SMS command to inject bolus. Note that you still need to confirm it and reply with security token/code. Note that you need to enabled SMS control of AAPS phone to use this function. + Allow AAPSClient to send SMS with bolus command + "Use this functionality with caution. Before enabling make sure that IOB and BG is synchronized between AAPS and AAPSClient. Some users reported issue with that. Use it at your own risk, every time you shall check IOB and BG before issuing a bolus. You can do that by sending 'BG' command." - + graphconfig Predictions Treatments diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index d3fd6a811ae..c3b047befc7 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -132,8 +132,13 @@ class InsulinDialog : DialogFragmentWithDate() { if (config.NSCLIENT) { // If SmsAllowRemoteCommands is True, then user might use either SMS command or record only, otherwise hardcode record_only option val allowSms = preferences.get(BooleanKey.SmsAllowRemoteCommands) - binding.recordOnly.isEnabled = allowSms - binding.recordOnly.isChecked = preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() + if(allowSms) { + binding.recordOnly.isEnabled = !preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() + binding.recordOnly.isChecked = preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() + } else { + binding.recordOnly.isEnabled = false + binding.recordOnly.isChecked = true + } } val maxInsulin = constraintChecker.getMaxBolusAllowed().value() @@ -207,6 +212,7 @@ class InsulinDialog : DialogFragmentWithDate() { val phoneNumber = preferences.get(StringKey.SmsReceiverNumber) val recordOnlyChecked = binding.recordOnly.isChecked val eatingSoonChecked = binding.startEatingSoonTt.isChecked + val sendSMS = preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank() if (insulinAfterConstraints > 0) { actions.add( @@ -215,7 +221,7 @@ class InsulinDialog : DialogFragmentWithDate() { ) if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) + else if (sendSMS) actions.add(rh.gs(app.aaps.core.ui.R.string.sms_bolus_notification).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) @@ -280,7 +286,7 @@ class InsulinDialog : DialogFragmentWithDate() { ).subscribe() if (timeOffset == 0) automation.removeAutomationEventBolusReminder() - } else if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) { + } else if (sendSMS) { smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + detailedBolusInfo.insulin)) } else { uel.log( diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt index 430dd95ca59..85bc8ab2480 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt @@ -110,7 +110,11 @@ class TreatmentDialog : DialogFragmentWithDate() { super.onViewCreated(view, savedInstanceState) if (config.NSCLIENT) { - binding.recordOnly.isChecked = preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() + if(preferences.get(BooleanKey.SmsAllowRemoteCommands)) { + binding.recordOnly.isChecked = preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank() + } else { + binding.recordOnly.isChecked = true + } } val maxCarbs = constraintChecker.getMaxCarbsAllowed().value().toDouble() val maxInsulin = constraintChecker.getMaxBolusAllowed().value() @@ -150,6 +154,7 @@ class TreatmentDialog : DialogFragmentWithDate() { val actions: LinkedList = LinkedList() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(ConstraintObject(insulin, aapsLogger)).value() val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(ConstraintObject(carbs, aapsLogger)).value() + val sendSMS = preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank() if (insulinAfterConstraints > 0) { actions.add( @@ -161,7 +166,7 @@ class TreatmentDialog : DialogFragmentWithDate() { ) if (recordOnlyChecked) actions.add(rh.gs(app.aaps.core.ui.R.string.bolus_recorded_only).formatColor(context, rh, app.aaps.core.ui.R.attr.warningColor)) - else if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) + else if (sendSMS) actions.add( rh.gs( app.aaps.core.ui.R.string.sms_bolus_notification @@ -196,9 +201,9 @@ class TreatmentDialog : DialogFragmentWithDate() { detailedBolusInfo.insulin = insulinAfterConstraints detailedBolusInfo.carbs = carbsAfterConstraints.toDouble() detailedBolusInfo.context = context - if (recordOnlyChecked) { + if (recordOnlyChecked || sendSMS) { if (detailedBolusInfo.insulin > 0) - if (preferences.get(BooleanKey.SmsAllowRemoteCommands) && !phoneNumber.isNullOrBlank()) + if (sendSMS) smsCommunicator.sendSMS(Sms(phoneNumber, rh.gs(app.aaps.core.ui.R.string.bolus) + " " + detailedBolusInfo.insulin)) else disposable += persistenceLayer.insertOrUpdateBolus( From e5319cc0f543c321fd8a28e0361c2de27248f62d Mon Sep 17 00:00:00 2001 From: mushroom-dev Date: Tue, 10 Dec 2024 21:25:25 +0100 Subject: [PATCH 11/11] compilation fix --- .../main/general/smsCommunicator/SmsCommunicatorPlugin.kt | 2 +- ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/smsCommunicator/SmsCommunicatorPlugin.kt b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/smsCommunicator/SmsCommunicatorPlugin.kt index 6ce0c81854e..60f2317aa1d 100644 --- a/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/plugins/main/src/main/kotlin/app/aaps/plugins/main/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -933,7 +933,7 @@ class SmsCommunicatorPlugin @Inject constructor( if (divided.size == 3 && !isMeal) { sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.wrong_format))) } else if (bolus > 0.0) { - val iob = (iobCobCalculator.calculateIobFromBolus() + iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).round() + val iob = iobCobCalculator.calculateIobFromBolus().round().iob + iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended().round().basaliob val passCode = generatePassCode() val reply = if (isMeal) rh.gs(R.string.smscommunicator_meal_bolus_reply_with_code, bolus, passCode, iob) diff --git a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt index c3b047befc7..58df02788ad 100644 --- a/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt @@ -130,7 +130,8 @@ class InsulinDialog : DialogFragmentWithDate() { val pump = activePlugin.activePump if (config.NSCLIENT) { - // If SmsAllowRemoteCommands is True, then user might use either SMS command or record only, otherwise hardcode record_only option + // If SmsAllowRemoteCommands is True and valid phone number is provided. then user might use either SMS command or record only. + // Hardcode record_only option otherwise val allowSms = preferences.get(BooleanKey.SmsAllowRemoteCommands) if(allowSms) { binding.recordOnly.isEnabled = !preferences.get(StringKey.SmsReceiverNumber).isNullOrBlank()