diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/ActionSource.kt b/wear/src/main/java/info/nightscout/androidaps/tile/ActionSource.kt index f41d2df3cb..9c2ccfdf56 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/ActionSource.kt +++ b/wear/src/main/java/info/nightscout/androidaps/tile/ActionSource.kt @@ -13,55 +13,45 @@ object ActionSource : TileSource { return listOf( Action( id = 0, - settingName = "wizzard", + settingName = "wizard", nameRes = R.string.menu_wizard_short, iconRes = R.drawable.ic_calculator_green, - activityClass = WizardActivity::class.java.getName(), - background = false, - actionString = "", + activityClass = WizardActivity::class.java.name, ), Action( id = 1, settingName = "treatment", nameRes = R.string.menu_treatment_short, iconRes = R.drawable.ic_bolus_carbs, - activityClass = TreatmentActivity::class.java.getName(), - background = false, - actionString = "", + activityClass = TreatmentActivity::class.java.name, ), Action( id = 2, settingName = "bolus", nameRes = R.string.action_insulin, iconRes = R.drawable.ic_bolus, - activityClass = BolusActivity::class.java.getName(), - background = false, - actionString = "", + activityClass = BolusActivity::class.java.name, ), Action( id = 3, settingName = "carbs", nameRes = R.string.action_carbs, iconRes = R.drawable.ic_carbs_orange, - activityClass = ECarbActivity::class.java.getName(), - background = false, - actionString = "", + activityClass = ECarbActivity::class.java.name, ), Action( id = 4, settingName = "temp_target", nameRes = R.string.menu_tempt, iconRes = R.drawable.ic_temptarget_flat, - activityClass = TempTargetActivity::class.java.getName(), - background = false, - actionString = "", + activityClass = TempTargetActivity::class.java.name, ) ) } override fun getDefaultConfig(): Map { return mapOf( - "tile_action_1" to "wizzard", + "tile_action_1" to "wizard", "tile_action_2" to "treatment", "tile_action_3" to "carbs", "tile_action_4" to "temp_target" diff --git a/wear/src/main/java/info/nightscout/androidaps/tile/ActionsTileService.kt b/wear/src/main/java/info/nightscout/androidaps/tile/ActionsTileService.kt index 77cdd3af2b..da0dac33cb 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/ActionsTileService.kt +++ b/wear/src/main/java/info/nightscout/androidaps/tile/ActionsTileService.kt @@ -6,4 +6,5 @@ class ActionsTileService : TileBase() { override val resourceVersion = "1" override val idIconActionPrefix = "ic_action_" override val source = ActionSource + } 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 01c1e06936..234d35bcdf 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/TempTargetSource.kt +++ b/wear/src/main/java/info/nightscout/androidaps/tile/TempTargetSource.kt @@ -12,7 +12,7 @@ object TempTargetSource : TileSource { settingName = "activity", nameRes = R.string.temp_target_activity, iconRes = R.drawable.ic_target_activity, - activityClass = TempTargetActivity::class.java.getName(), + activityClass = TempTargetActivity::class.java.name, background = true, // actionString = "temptarget false 90 8.0 8.0", actionString = "temptarget preset activity", @@ -22,7 +22,7 @@ object TempTargetSource : TileSource { settingName = "eating_soon", nameRes = R.string.temp_target_eating_soon, iconRes = R.drawable.ic_target_eatingsoon, - activityClass = TempTargetActivity::class.java.getName(), + activityClass = TempTargetActivity::class.java.name, background = true, // actionString = "temptarget false 45 4.5 4.5", actionString = "temptarget preset eating", @@ -32,7 +32,7 @@ object TempTargetSource : TileSource { settingName = "hypo", nameRes = R.string.temp_target_hypo, iconRes = R.drawable.ic_target_hypo, - activityClass = TempTargetActivity::class.java.getName(), + activityClass = TempTargetActivity::class.java.name, background = true, // actionString = "temptarget false 45 7.0 7.0", actionString = "temptarget preset hypo", @@ -42,18 +42,16 @@ object TempTargetSource : TileSource { settingName = "manual", nameRes = R.string.temp_target_manual, iconRes = R.drawable.ic_target_manual, - activityClass = TempTargetActivity::class.java.getName(), - actionString = "", - background = false, + activityClass = TempTargetActivity::class.java.name, ), Action( id = 4, settingName = "cancel", nameRes = R.string.generic_cancel, iconRes = R.drawable.ic_target_cancel, - activityClass = TempTargetActivity::class.java.getName(), + activityClass = TempTargetActivity::class.java.name, actionString = "temptarget cancel", - background = false, + background = true, ) ) } 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 53c415957d..a491205b2b 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt +++ b/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt @@ -58,16 +58,17 @@ data class Action( @StringRes val nameRes: Int, val activityClass: String, @DrawableRes val iconRes: Int, - val background: Boolean?, - val actionString: String?, + val background: Boolean = false, + val actionString: String? = null, ) -abstract open class TileBase : TileService() { +abstract class TileBase : TileService() { - open val preferencePrefix = "tile_action_" open val resourceVersion = "1" open val idIconActionPrefix = "ic_action_" - open val source: TileSource = ActionSource + + abstract val preferencePrefix: String + abstract val source: TileSource private val serviceJob = Job() private val serviceScope = CoroutineScope(Dispatchers.IO + serviceJob) @@ -114,18 +115,6 @@ abstract open class TileBase : TileService() { .build() } - private fun addRowSingle(action1: Action, deviceParameters: DeviceParameters): LayoutElement = - Row.Builder() - .addContent(action(action1, deviceParameters)) - .build() - - private fun addRowDouble(action1: Action, action2: Action, deviceParameters: DeviceParameters): LayoutElement = - Row.Builder() - .addContent(action(action1, deviceParameters)) - .addContent(Spacer.Builder().setWidth(SPACING_ACTIONS).build()) - .addContent(action(action2, deviceParameters)) - .build() - private fun layout(enabled: Boolean, actions: List, deviceParameters: DeviceParameters): LayoutElement { if (!enabled) { return Text.Builder() @@ -154,18 +143,31 @@ abstract open class TileBase : TileService() { .build() } + private fun addRowSingle(action1: Action, deviceParameters: DeviceParameters): LayoutElement = + Row.Builder() + .addContent(action(action1, deviceParameters)) + .build() + + private fun addRowDouble(action1: Action, action2: Action, deviceParameters: DeviceParameters): LayoutElement = + Row.Builder() + .addContent(action(action1, deviceParameters)) + .addContent(Spacer.Builder().setWidth(SPACING_ACTIONS).build()) + .addContent(action(action2, deviceParameters)) + .build() + private fun doAction(action: Action): ActionBuilders.Action { - val ab = ActionBuilders.AndroidActivity.Builder() + val inBackground = ActionBuilders.AndroidBooleanExtra.Builder().setValue(action.background).build() + val builder = ActionBuilders.AndroidActivity.Builder() .setClassName(action.activityClass) .setPackageName(this.packageName) + .addKeyToExtraMapping("inBackground", inBackground) if (action.actionString != null) { - ab.addKeyToExtraMapping("actionString", ActionBuilders.AndroidStringExtra.Builder().setValue(action.actionString).build()) - } - if (action.background != null) { - ab.addKeyToExtraMapping("inBackground", ActionBuilders.AndroidBooleanExtra.Builder().setValue(action.background).build()) + val actionString = ActionBuilders.AndroidStringExtra.Builder().setValue(action.actionString).build() + builder.addKeyToExtraMapping("actionString", actionString) } + return ActionBuilders.LaunchAction.Builder() - .setAndroidActivity(ab.build()) + .setAndroidActivity(builder.build()) .build() } @@ -245,18 +247,18 @@ abstract open class TileBase : TileService() { } private fun getActionFromPreference(sharedPrefs: SharedPreferences, index: Int): Action? { - val actionPref = sharedPrefs?.getString(preferencePrefix + index, "none") + val actionPref = sharedPrefs.getString(preferencePrefix + index, "none") return source.getActions().find { action -> action.settingName == actionPref } } - fun setDefaultSettings(sharedPrefs: SharedPreferences) { + private fun setDefaultSettings(sharedPrefs: SharedPreferences) { val defaults = source.getDefaultConfig() val firstKey = defaults.firstNotNullOf { settings -> settings.key } if (!sharedPrefs.contains(firstKey)) { Log.i(TAG, "setDefaultSettings: set defaults") val editor = sharedPrefs.edit() for ((key, value) in defaults) { - println("$key = $value") + // println("$key = $value") editor.putString(key, value) } editor.apply() diff --git a/wear/src/main/res/values/arrays.xml b/wear/src/main/res/values/arrays.xml index 27e924a517..a70ec6e5ec 100644 --- a/wear/src/main/res/values/arrays.xml +++ b/wear/src/main/res/values/arrays.xml @@ -89,7 +89,7 @@ - wizzard + wizard treatment bolus carbs diff --git a/wear/src/main/res/xml/tile_configuration_activity.xml b/wear/src/main/res/xml/tile_configuration_activity.xml index 964d922f32..19abf54a05 100644 --- a/wear/src/main/res/xml/tile_configuration_activity.xml +++ b/wear/src/main/res/xml/tile_configuration_activity.xml @@ -5,7 +5,7 @@