From 2d5c6d222b73a3d254befdc1dc631e783a4fcdfe Mon Sep 17 00:00:00 2001 From: Christopher Jakob Date: Mon, 27 Nov 2017 16:39:35 +0100 Subject: [PATCH] Update State of Tile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - State is now „synced“ when the tile is added or the quicksettings are expanded refs #41 --- .../flashlight/helpers/MyTileService.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyTileService.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyTileService.kt index 0516804..89f9cf0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyTileService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyTileService.kt @@ -10,13 +10,24 @@ class MyTileService : TileService() { override fun onClick() { MyCameraImpl.newInstance(this).toggleFlashlight() - - qsTile.state = if (MyCameraImpl.isFlashlightOn) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE - qsTile.updateTile() + updateTile() } override fun onTileRemoved() { if (MyCameraImpl.isFlashlightOn) MyCameraImpl.newInstance(this).toggleFlashlight() } -} \ No newline at end of file + + override fun onStartListening() { + updateTile() + } + + override fun onTileAdded() { + updateTile() + } + + private fun updateTile() { + qsTile.state = if (MyCameraImpl.isFlashlightOn) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE + qsTile.updateTile() + } +}