From 644c4ad657306abb9917f488c789a4d124066717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Mon, 31 Jul 2023 21:18:24 +0200 Subject: [PATCH] Invalidate Auto home on favorite state change (#3736) --- .../android/vehicle/MainVehicleScreen.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/vehicle/MainVehicleScreen.kt b/app/src/main/java/io/homeassistant/companion/android/vehicle/MainVehicleScreen.kt index fe6ebe12ab7..dffb73cfe07 100644 --- a/app/src/main/java/io/homeassistant/companion/android/vehicle/MainVehicleScreen.kt +++ b/app/src/main/java/io/homeassistant/companion/android/vehicle/MainVehicleScreen.kt @@ -27,7 +27,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import io.homeassistant.companion.android.common.R as commonR @@ -45,8 +44,7 @@ class MainVehicleScreen( private const val TAG = "MainVehicleScreen" } - private var favoriteEntities = flowOf>>() - private var entityList: List> = listOf() + private var favoritesEntities: List> = listOf() private var favoritesList = emptyList() private var isLoggedIn: Boolean? = null private val domains = mutableSetOf() @@ -74,14 +72,16 @@ class MainVehicleScreen( .distinct() .filter { it in SUPPORTED_DOMAINS } .toSet() - if (newDomains.size != domains.size || newDomains != domains) { - domains.clear() - domains.addAll(newDomains) - invalidate() - } - entityList = getFavoritesList(entities) + var invalidate = newDomains.size != domains.size || newDomains != domains + domains.clear() + domains.addAll(newDomains) + + val newFavorites = getFavoritesList(entities) + invalidate = invalidate || (newFavorites.size != favoritesEntities.size || newFavorites.toSet() != favoritesEntities.toSet()) + favoritesEntities = newFavorites + + if (invalidate) invalidate() } - favoriteEntities = allEntities.map { getFavoritesList(it) } } } lifecycleScope.launch { @@ -113,9 +113,9 @@ class MainVehicleScreen( serverManager.integrationRepository(serverId.value), carContext.getString(commonR.string.favorites), domains, - favoriteEntities, + flowOf(), allEntities - ) { onChangeServer(it) }.getEntityGridItems(entityList) + ) { onChangeServer(it) }.getEntityGridItems(favoritesEntities) } else { var builder = ItemList.Builder() if (domains.isNotEmpty()) {