Skip to content

Commit

Permalink
Invalidate Auto home on favorite state change (home-assistant#3736)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpelgrom authored Jul 31, 2023
1 parent 670b17e commit 644c4ad
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -45,8 +44,7 @@ class MainVehicleScreen(
private const val TAG = "MainVehicleScreen"
}

private var favoriteEntities = flowOf<List<Entity<*>>>()
private var entityList: List<Entity<*>> = listOf()
private var favoritesEntities: List<Entity<*>> = listOf()
private var favoritesList = emptyList<String>()
private var isLoggedIn: Boolean? = null
private val domains = mutableSetOf<String>()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 644c4ad

Please sign in to comment.