Skip to content

Commit

Permalink
- move sms related settings to Button menu
Browse files Browse the repository at this point in the history
- enable phone number verification in settings
- fix issues
- update AAPS response for SMS bolus request to include IOB
  • Loading branch information
mushroom-dev committed Dec 14, 2024
1 parent b093f7f commit 9f2a45e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
<string name="authorizationfailed">Authorization failed</string>
<string name="cannula">Cannula</string>
<string name="identification_not_set">Identification not set in dev mode</string>
<string name="a11y_dialog">dialog</string>
<!-- AAPSClient sms -->
<string name="sms_receiver_number_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.</string>
<string name="client_allow_sms">Allow AAPSClient to send SMS with bolus command</string>
<string name="client_allow_sms_warning">"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."</string>
<!-- WEAR OS-->
<string name="remove_selected_items">Remove selected items</string>
<string name="count_selected">%1$d selected</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 7 additions & 3 deletions plugins/main/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<string name="sms_timeout_while_waiting">Timeout while waiting for finish of previous pump communication</string>
<string name="smscommunicator_allowednumbers">Allowed phone numbers</string>
<string name="smscommunicator_allowednumbers_summary">+XXXXXXXXXX;+YYYYYYYYYY</string>
<string name="smscommunicator_bolus_reply_with_code">To deliver bolus %1$.2fU reply with code %2$s</string>
<string name="smscommunicator_meal_bolus_reply_with_code">To deliver meal bolus %1$.2fU reply with code %2$s</string>
<string name="smscommunicator_bolus_reply_with_code">To deliver bolus %1$.2fU reply with code %2$s. Current IOB is %3$.2fU</string>
<string name="smscommunicator_meal_bolus_reply_with_code">To deliver meal bolus %1$.2fU reply with code %2$s. Current IOB is %3$.2fU</string>
<string name="smscommunicator_temptarget_with_code">To set the Temp Target %1$s reply with code %2$s</string>
<string name="smscommunicator_temptarget_cancel">To cancel Temp Target reply with code %1$s</string>
<string name="smscommunicator_stops_ns_with_code">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.</string>
Expand Down Expand Up @@ -275,8 +275,12 @@
<string name="enablebolusreminder">Enable bolus reminder</string>
<string name="enablebolusreminder_summary">Use reminder to bolus later with wizard ("post-bolus")</string>
<string name="run_question">Run %s?</string>
<!-- AAPSClient sms related settings-->
<string name="sms_receiver_number_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.</string>
<string name="client_allow_sms">Allow AAPSClient to send SMS with bolus command</string>
<string name="client_allow_sms_warning">"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."</string>

<!-- OverviewMenu-->
<!-- OverviewMenu-->
<string name="key_graph_config" translatable="false">graphconfig</string>
<string name="overview_show_predictions">Predictions</string>
<string name="overview_show_treatments">Treatments</string>
Expand Down
14 changes: 10 additions & 4 deletions ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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(
Expand All @@ -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))
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 9 additions & 4 deletions ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -150,6 +154,7 @@ class TreatmentDialog : DialogFragmentWithDate() {
val actions: LinkedList<String?> = 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(
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9f2a45e

Please sign in to comment.