Wear: support tt presets

This commit is contained in:
Andries Smit 2022-01-11 13:58:59 +01:00
parent c5c4064c8b
commit 6321758634
3 changed files with 11 additions and 12 deletions

View file

@ -144,6 +144,7 @@ class ActionStringHandler @Inject constructor(
}
rAction += "bolus $insulinAfterConstraints $carbsAfterConstraints"
} else if ("temptarget" == act[0]) { ///////////////////////////////////////////////////////// TEMPTARGET
aapsLogger.info(LTag.WEAR, "temptarget received:" + act)
if ("cancel" == act[1]) {
rMessage += rh.gs(R.string.wear_action_tempt_cancel_message)
rAction = "temptarget true 0 0 0"
@ -156,15 +157,13 @@ class ActionStringHandler @Inject constructor(
val reason = rh.gs(R.string.activity)
rMessage += rh.gs(R.string.wear_action_tempt_preset_message, reason, activityTT, activityTTDuration)
rAction = "temptarget $presetIsMGDL $activityTTDuration $activityTT $activityTT"
}
if ("hypo" == preset) {
} else if ("hypo" == preset) {
val hypoTTDuration = defaultValueHelper.determineHypoTTDuration()
val hypoTT = defaultValueHelper.determineHypoTT()
val reason = rh.gs(R.string.hypo)
rMessage += rh.gs(R.string.wear_action_tempt_preset_message, reason, hypoTT, hypoTTDuration)
rAction = "temptarget $presetIsMGDL $hypoTTDuration $hypoTT $hypoTT"
}
if ("eating" == preset) {
} else if ("eating" == preset) {
val eatingSoonTTDuration = defaultValueHelper.determineEatingSoonTTDuration()
val eatingSoonTT = defaultValueHelper.determineEatingSoonTT()
val reason = rh.gs(R.string.eatingsoon)

View file

@ -14,8 +14,8 @@ object TempTargetSource : TileSource {
iconRes = R.drawable.ic_target_activity,
activityClass = TempTargetActivity::class.java.getName(),
background = true,
actionString = "temptarget false 90 8.0 8.0",
// actionString = "temptarget preset activity",
// actionString = "temptarget false 90 8.0 8.0",
actionString = "temptarget preset activity",
),
Action(
id = 1,
@ -24,8 +24,8 @@ object TempTargetSource : TileSource {
iconRes = R.drawable.ic_target_eatingsoon,
activityClass = TempTargetActivity::class.java.getName(),
background = true,
actionString = "temptarget false 45 4.5 4.5",
//actionString = "temptarget preset eating",
// actionString = "temptarget false 45 4.5 4.5",
actionString = "temptarget preset eating",
),
Action(
id = 2,
@ -34,8 +34,8 @@ object TempTargetSource : TileSource {
iconRes = R.drawable.ic_target_hypo,
activityClass = TempTargetActivity::class.java.getName(),
background = true,
actionString = "temptarget false 45 7.0 7.0",
// actionString = "temptarget preset hypo",
// actionString = "temptarget false 45 7.0 7.0",
actionString = "temptarget preset hypo",
),
Action(
id = 3,

View file

@ -234,12 +234,12 @@ abstract open class TileBase : TileService() {
private fun getActionFromPreference(sharedPrefs: SharedPreferences, index: Int): Action? {
val actionPref = sharedPrefs?.getString(preferencePrefix + index, "none")
return source.getActions().find { a -> a.settingName == actionPref }
return source.getActions().find { action -> action.settingName == actionPref }
}
fun setDefaultSettings(sharedPrefs: SharedPreferences) {
val defaults = source.getDefaultConfig()
val firstKey = defaults.firstNotNullOf { d -> d.key }
val firstKey = defaults.firstNotNullOf { settings -> settings.key }
if (!sharedPrefs.contains(firstKey)) {
Log.i(TAG, "setDefaultSettings: set defaults")
val editor = sharedPrefs.edit()