From ad440740d2777aa091bfc131a8f317df3872e992 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Tue, 11 Jan 2022 14:21:56 +0100 Subject: [PATCH] Wear: tile add msg wear control disabled --- .../info/nightscout/androidaps/tile/TileBase.kt | 16 ++++++++++++++-- wear/src/main/res/values/strings.xml | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) 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 b3b1aa8fb7..53c415957d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt +++ b/wear/src/main/java/info/nightscout/androidaps/tile/TileBase.kt @@ -77,12 +77,14 @@ abstract open class TileBase : TileService() { ): ListenableFuture = serviceScope.future { Log.i(TAG, "onTileRequest: ") val actionsSelected = getSelectedActions() + val wearControlEnabled = hasWearControl() + Tile.Builder() .setResourcesVersion(resourceVersion) .setTimeline( Timeline.Builder().addTimelineEntry( TimelineEntry.Builder().setLayout( - Layout.Builder().setRoot(layout(actionsSelected, requestParams.deviceParameters!!)).build() + Layout.Builder().setRoot(layout(wearControlEnabled, actionsSelected, requestParams.deviceParameters!!)).build() ).build() ).build() ) @@ -124,7 +126,12 @@ abstract open class TileBase : TileService() { .addContent(action(action2, deviceParameters)) .build() - private fun layout(actions: List, deviceParameters: DeviceParameters): LayoutElement { + private fun layout(enabled: Boolean, actions: List, deviceParameters: DeviceParameters): LayoutElement { + if (!enabled) { + return Text.Builder() + .setText(resources.getString(R.string.wear_control_not_enabled)) + .build() + } if (actions.isNotEmpty()) { val b = Column.Builder() if (actions.size == 1 || actions.size == 3) { @@ -213,6 +220,11 @@ abstract open class TileBase : TileService() { ) .build() + private fun hasWearControl(): Boolean { + val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this) + return sharedPrefs.getBoolean("wearcontrol", false) + } + private fun getSelectedActions(): List { val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this) setDefaultSettings(sharedPrefs) diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index cd2dd60ef3..86a939f6de 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -172,6 +172,7 @@ Manual Cancel None - No tile config available + No config available + Wear control disabled