@@ -2,11 +2,13 @@ package io.homeassistant.companion.android.settings.vehicle.views
22
33import android.os.Build
44import androidx.annotation.RequiresApi
5+ import androidx.compose.foundation.layout.Box
56import androidx.compose.foundation.layout.PaddingValues
67import androidx.compose.foundation.layout.fillMaxWidth
78import androidx.compose.foundation.layout.padding
89import androidx.compose.foundation.lazy.LazyColumn
910import androidx.compose.foundation.lazy.rememberLazyListState
11+ import androidx.compose.material.CircularProgressIndicator
1012import androidx.compose.material.Text
1113import androidx.compose.runtime.Composable
1214import androidx.compose.runtime.LaunchedEffect
@@ -15,6 +17,7 @@ import androidx.compose.runtime.mutableIntStateOf
1517import androidx.compose.runtime.mutableStateOf
1618import androidx.compose.runtime.remember
1719import androidx.compose.runtime.setValue
20+ import androidx.compose.ui.Alignment
1821import androidx.compose.ui.Modifier
1922import androidx.compose.ui.res.stringResource
2023import androidx.compose.ui.text.font.FontWeight
@@ -77,62 +80,71 @@ fun AndroidAutoFavoritesSettings(
7780 )
7881 }
7982
80- if (serversList.size > 1 ) {
83+ if (androidAutoViewModel.isLoading ) {
8184 item {
82- ServerExposedDropdownMenu (
83- servers = serversList,
84- current = selectedServer,
85- onSelected = {
86- androidAutoViewModel.loadEntities(it)
87- selectedServer = it
88- },
89- modifier = Modifier .fillMaxWidth().padding(horizontal = 16 .dp).padding(bottom = 16 .dp),
90- )
85+ Box (modifier = Modifier .fillMaxWidth().padding(top = 16 .dp), contentAlignment = Alignment .Center ) {
86+ CircularProgressIndicator ()
87+ }
9188 }
92- }
93- item {
94- // TODO use new theme for Material3 components https://github.com/home-assistant/android/issues/6302
95- HATheme {
96- EntityPicker (
97- entities = validEntities,
98- selectedEntityId = null ,
99- onEntityCleared = { /* Nothing */ },
100- onEntitySelectedId = {
101- androidAutoViewModel.onEntitySelected(true , it, selectedServer)
102- },
103- addButtonText = stringResource(commonR.string.add_favorite),
104- entityRegistry = androidAutoViewModel.entityRegistry,
105- deviceRegistry = androidAutoViewModel.deviceRegistry,
106- areaRegistry = androidAutoViewModel.areaRegistry,
107- modifier = Modifier .padding(horizontal = 16 .dp).padding(bottom = 16 .dp),
108- )
89+ } else {
90+ if (serversList.size > 1 ) {
91+ item {
92+ ServerExposedDropdownMenu (
93+ servers = serversList,
94+ current = selectedServer,
95+ onSelected = {
96+ androidAutoViewModel.loadEntities(it)
97+ selectedServer = it
98+ },
99+ modifier = Modifier .fillMaxWidth().padding(horizontal = 16 .dp).padding(bottom = 16 .dp),
100+ )
101+ }
109102 }
110- }
111- if (favoriteEntities.isNotEmpty() && androidAutoViewModel.sortedEntities.isNotEmpty()) {
112- items(favoriteEntities.size, { favoriteEntities[it] }) { index ->
113- val favoriteEntity = favoriteEntities[index]
114- androidAutoViewModel.sortedEntities.firstOrNull {
115- it.entityId == favoriteEntity.entityId &&
116- favoriteEntity.serverId == selectedServer
117- }?.let {
118- ReorderableItem (
119- state = reorderState,
120- key = favoriteEntities[index],
121- ) { isDragging ->
122- FavoriteEntityRow (
123- entityName = it.friendlyName,
124- entityId = it.entityId,
125- onClick = {
126- androidAutoViewModel.onEntitySelected(
127- false ,
128- it.entityId,
129- selectedServer,
130- )
131- },
132- checked = true ,
133- draggable = true ,
134- isDragging = isDragging,
135- )
103+
104+ item {
105+ // TODO use new theme for Material3 components https://github.com/home-assistant/android/issues/6302
106+ HATheme {
107+ EntityPicker (
108+ entities = validEntities,
109+ selectedEntityId = null ,
110+ onEntityCleared = { /* Nothing */ },
111+ onEntitySelectedId = {
112+ androidAutoViewModel.onEntitySelected(true , it, selectedServer)
113+ },
114+ addButtonText = stringResource(commonR.string.add_favorite),
115+ entityRegistry = androidAutoViewModel.entityRegistry,
116+ deviceRegistry = androidAutoViewModel.deviceRegistry,
117+ areaRegistry = androidAutoViewModel.areaRegistry,
118+ modifier = Modifier .padding(horizontal = 16 .dp).padding(bottom = 16 .dp),
119+ )
120+ }
121+ }
122+ if (favoriteEntities.isNotEmpty() && androidAutoViewModel.sortedEntities.isNotEmpty()) {
123+ items(favoriteEntities.size, { favoriteEntities[it] }) { index ->
124+ val favoriteEntity = favoriteEntities[index]
125+ androidAutoViewModel.sortedEntities.firstOrNull {
126+ it.entityId == favoriteEntity.entityId &&
127+ favoriteEntity.serverId == selectedServer
128+ }?.let {
129+ ReorderableItem (
130+ state = reorderState,
131+ key = favoriteEntities[index],
132+ ) { isDragging ->
133+ FavoriteEntityRow (
134+ entityName = it.friendlyName,
135+ entityId = it.entityId,
136+ onClick = {
137+ androidAutoViewModel.onEntitySelected(
138+ false ,
139+ it.entityId,
140+ selectedServer,
141+ )
142+ },
143+ checked = true ,
144+ draggable = true ,
145+ isDragging = isDragging,
146+ )
147+ }
136148 }
137149 }
138150 }
0 commit comments