From 6321758634ff184f37e2f2be90e6a1b0d7bce0af Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Tue, 11 Jan 2022 13:58:59 +0100 Subject: [PATCH] Wear: support tt presets --- .../plugins/general/wear/ActionStringHandler.kt | 7 +++---- .../nightscout/androidaps/tile/TempTargetSource.kt | 12 ++++++------ .../java/info/nightscout/androidaps/tile/TileBase.kt | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt index 8837105f47..db33722e31 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt @@ -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) diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/TempTargetSource.kt b/wear/src/main/java/info/nightscout/androidaps/tile/TempTargetSource.kt index 758ed45c5a..01c1e06936 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/TempTargetSource.kt +++ b/wear/src/main/java/info/nightscout/androidaps/tile/TempTargetSource.kt @@ -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, diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt b/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt index c1d2c18c0a..b3b1aa8fb7 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt +++ b/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt @@ -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()