From 5de7bd235b51a5197f0e58dee1292bcd04d21fe7 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Tue, 6 Aug 2024 15:18:03 +0200 Subject: [PATCH 1/2] feat(tiles/dimmer): restart cycle when torch is disabled externally Changes the DimmerSettingsTile to always start from the dimmest mode if the toch is disabled. Previously it would continue from the last mode, which was confusing to the user, since suddenly the tile acted different when tapped. --- .../com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt b/app/src/main/kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt index abcd065..e088ee5 100644 --- a/app/src/main/kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt +++ b/app/src/main/kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt @@ -28,11 +28,15 @@ import com.cyb3rko.flashdim.utils.Safe class DimmerSettingsTile : TileService() { private var description = "" + private var enabled = false override fun onClick() { if (qsTile.state == Tile.STATE_UNAVAILABLE) return Safe.initialize(applicationContext) - val mode = Safe.getInt(Safe.QUICKTILE_DIM_MODE, DIMMER_MIN) + var mode = Safe.getInt(Safe.QUICKTILE_DIM_MODE, DIMMER_MIN) + if (!enabled) + // torch was disabled externally, continue again from initial state + mode = DIMMER_MIN description = mode.description() val maxLevel = Safe.getInt(Safe.MAX_LEVEL, -1) @@ -73,6 +77,7 @@ class DimmerSettingsTile : TileService() { if (description.isNotEmpty()) qsTile.subtitle = "State: $description" qsTile.state = if (enabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE qsTile.updateTile() + this@DimmerSettingsTile.enabled = enabled } }, Handler(Looper.getMainLooper()) From 02f06e0879b9756ab4a7fa086a1951d5634d3230 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Tue, 6 Aug 2024 15:21:16 +0200 Subject: [PATCH 2/2] fix(Tiles/Dimmer): always display off state if torch is disabled Fixes an issue, where if the torch was externally disabled, the mode should continue to show the (now outdated) mode instead of off. --- .../kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt b/app/src/main/kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt index e088ee5..e7d45af 100644 --- a/app/src/main/kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt +++ b/app/src/main/kotlin/com/cyb3rko/flashdim/tiles/DimmerSettingsTile.kt @@ -74,7 +74,9 @@ class DimmerSettingsTile : TileService() { object : CameraManager.TorchCallback() { override fun onTorchModeChanged(cameraId: String, enabled: Boolean) { if (qsTile == null) return - if (description.isNotEmpty()) qsTile.subtitle = "State: $description" + qsTile.subtitle = + if (description.isNotEmpty() && enabled) "State: $description" + else "State: ${DIMMER_OFF.description()}" qsTile.state = if (enabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE qsTile.updateTile() this@DimmerSettingsTile.enabled = enabled