Skip to content

Commit

Permalink
Try to fix template config refresh in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
slovdahl committed Aug 25, 2023
1 parent 08f25dd commit 03fe581
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fun LoadHomePage(
}
composable("$ROUTE_TEMPLATE_TILE/$SCREEN_SELECT_TEMPLATE_TILE") {
SelectTemplateTileView(
templateTileIds = mainViewModel.templateTiles.keys.toList(),
templateTiles = mainViewModel.templateTiles,
onSelectTemplateTile = { tileId ->
swipeDismissableNavController.navigate("$ROUTE_TEMPLATE_TILE/$tileId/$SCREEN_SET_TILE_TEMPLATE")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.itemsIndexed
import androidx.wear.compose.material.rememberScalingLazyListState
import io.homeassistant.companion.android.common.data.prefs.impl.entities.TemplateTileConfig
import io.homeassistant.companion.android.theme.WearAppTheme
import io.homeassistant.companion.android.views.ListHeader
import io.homeassistant.companion.android.views.ThemeLazyColumn
import io.homeassistant.companion.android.common.R as commonR

@Composable
fun SelectTemplateTileView(
templateTileIds: List<Int?>,
templateTiles: Map<Int?, TemplateTileConfig>,
onSelectTemplateTile: (tileId: Int?) -> Unit
) {
val scalingLazyListState = rememberScalingLazyListState()
Expand All @@ -41,12 +42,12 @@ fun SelectTemplateTileView(
ListHeader(id = commonR.string.template_tile_select)
}
// TODO: make sure this refreshes whenever a new Template tile is added
if (templateTileIds.isEmpty()) {
if (templateTiles.isEmpty()) {
item {
Text(stringResource(commonR.string.template_tile_no_tiles_yet))
}
} else {
itemsIndexed(templateTileIds) { index, templateTileId ->
itemsIndexed(templateTiles.keys.toList()) { index, templateTileId ->
Chip(
modifier = Modifier
.fillMaxWidth(),
Expand All @@ -67,10 +68,10 @@ fun SelectTemplateTileView(
@Composable
private fun PreviewSelectTemplateTileView() {
SelectTemplateTileView(
templateTileIds = listOf(
null,
1111,
2222
templateTiles = mapOf(
null to TemplateTileConfig("Old template", 0),
1111 to TemplateTileConfig("New template #1", 10),
2222 to TemplateTileConfig("New template #2", 20)
),
onSelectTemplateTile = {}
)
Expand All @@ -80,7 +81,7 @@ private fun PreviewSelectTemplateTileView() {
@Composable
private fun PreviewSelectTemplateTileEmptyView() {
SelectTemplateTileView(
templateTileIds = emptyList(),
templateTiles = mapOf(),
onSelectTemplateTile = {}
)
}

0 comments on commit 03fe581

Please sign in to comment.