Skip to content

Commit

Permalink
- improve sms option placement in menu
Browse files Browse the repository at this point in the history
- fix this option to work only on aapsclient, only when it's enabledd
  • Loading branch information
mushroom-dev committed Nov 1, 2024
1 parent 1a40163 commit 4e2b327
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,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))
}
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<string name="remove_bg_readings">Remove BG readings</string>
<string name="identification_not_set">Identification not set in dev mode</string>
<string name="a11y_dialog">dialog</string>
<!-- AAPS client 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 AAPS client to send SMS with bolus command</string>
<!-- WEAR OS-->
<string name="wear_unknown_action_string">Unknown action command:</string>
<string name="remove_selected_items">Remove selected items</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,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))
Expand Down Expand Up @@ -546,7 +546,7 @@ class BolusWizard @Inject constructor(
ValueWithUnit.Minute(carbTime).takeIf { carbTime != 0 })
)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,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))
Expand Down
4 changes: 1 addition & 3 deletions plugins/main/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<resources>

<!-- SMS Communicator & OTP Authenticator -->

<string name="smscommunicator">SMS Communicator</string>
<string name="smscommunicator_shortname">SMS</string>
<string name="description_sms_communicator">Remote control AAPS using SMS commands.</string>
Expand Down Expand Up @@ -186,7 +185,7 @@
<string name="statuslights_patch_pump_age">patch pump age</string>
<string name="patch_pump">Patch pump</string>

<!-- Overview -->
<!-- Overview Preferences -->
<string name="show_statuslights">Show status lights on home screen</string>
<string name="statuslights_cage_warning">Threshold warning cannula age [h]</string>
<string name="statuslights_cage_critical">Threshold critical cannula age [h]</string>
Expand Down Expand Up @@ -270,7 +269,6 @@
<string name="short_tabtitles">Shorten tab titles</string>
<string name="overview_show_notes_field_in_dialogs_title">Show notes field in treatment dialogs</string>
<string name="deliverpartofboluswizard">Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm.</string>
<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="deliver_part_of_boluswizard_reset_time">Deliver full bolus (100%) if glycemia is older than</string>
<string name="enable_bolus_advisor">Enable bolus advisor</string>
<string name="enable_bolus_advisor_summary">Use reminder to start eating later instead of wizard result during high glycemia ("pre-bolus")</string>
Expand Down
10 changes: 7 additions & 3 deletions ui/src/main/kotlin/app/aaps/ui/dialogs/InsulinDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions ui/src/main/kotlin/app/aaps/ui/dialogs/TreatmentDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4e2b327

Please sign in to comment.