From 73c928d6e4f2ee2966adcc0ee470409bb77f7f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Sat, 28 Oct 2023 17:14:55 +0200 Subject: [PATCH] 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) --- .../companion/android/tiles/ShortcutsTile.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/wear/src/main/java/io/homeassistant/companion/android/tiles/ShortcutsTile.kt b/wear/src/main/java/io/homeassistant/companion/android/tiles/ShortcutsTile.kt index cdf3423b0..c49a0689f 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/tiles/ShortcutsTile.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/tiles/ShortcutsTile.kt @@ -42,7 +42,8 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.guava.future -import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext import java.nio.ByteBuffer import javax.inject.Inject import kotlin.math.min @@ -146,8 +147,8 @@ class ShortcutsTile : TileService() { .build() } - override fun onTileAddEvent(requestParams: EventBuilders.TileAddEvent) { - serviceScope.launch { + override fun onTileAddEvent(requestParams: EventBuilders.TileAddEvent): Unit = runBlocking { + withContext(Dispatchers.IO) { /** * 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. @@ -167,8 +168,8 @@ class ShortcutsTile : TileService() { } } - override fun onTileRemoveEvent(requestParams: EventBuilders.TileRemoveEvent) { - serviceScope.launch { + override fun onTileRemoveEvent(requestParams: EventBuilders.TileRemoveEvent): Unit = runBlocking { + withContext(Dispatchers.IO) { wearPrefsRepository.removeTileShortcuts(requestParams.tileId) } }