mirror of
https://github.com/home-assistant/android
synced 2024-10-04 15:19:30 +00:00
Update shortcut tile add/remove + destroy handling (#3974)
- Updates the shortcut tile's handling of add/remove event + destroying the service, just like the camera tile, to prevent the service scope being cancelled while the app is still storing tile added/removed - (this service already didn't overwrite existing tile data when onTileAddEvent was called again)
This commit is contained in:
parent
d143da9ea3
commit
73c928d6e4
|
@ -42,7 +42,8 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.guava.future
|
import kotlinx.coroutines.guava.future
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
@ -146,8 +147,8 @@ class ShortcutsTile : TileService() {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTileAddEvent(requestParams: EventBuilders.TileAddEvent) {
|
override fun onTileAddEvent(requestParams: EventBuilders.TileAddEvent): Unit = runBlocking {
|
||||||
serviceScope.launch {
|
withContext(Dispatchers.IO) {
|
||||||
/**
|
/**
|
||||||
* When the app is updated from an older version (which only supported a single Shortcut Tile),
|
* When the app is updated from an older version (which only supported a single Shortcut Tile),
|
||||||
* and the user is adding a new Shortcuts Tile, we can't tell for sure if it's the 1st or 2nd Tile.
|
* and the user is adding a new Shortcuts Tile, we can't tell for sure if it's the 1st or 2nd Tile.
|
||||||
|
@ -167,8 +168,8 @@ class ShortcutsTile : TileService() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTileRemoveEvent(requestParams: EventBuilders.TileRemoveEvent) {
|
override fun onTileRemoveEvent(requestParams: EventBuilders.TileRemoveEvent): Unit = runBlocking {
|
||||||
serviceScope.launch {
|
withContext(Dispatchers.IO) {
|
||||||
wearPrefsRepository.removeTileShortcuts(requestParams.tileId)
|
wearPrefsRepository.removeTileShortcuts(requestParams.tileId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue