Update State of Tile

- State is now „synced“ when the tile is added or the quicksettings are expanded

refs #41
This commit is contained in:
Christopher Jakob 2017-11-27 16:39:35 +01:00
parent 0b665c8b8f
commit 2d5c6d222b

View File

@ -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()
}
}
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()
}
}