Skip to content
This repository was archived by the owner on Dec 28, 2023. It is now read-only.

Commit 90ce589

Browse files
committed
solution
1 parent b4444a0 commit 90ce589

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationScreen.kt

+11-9
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fun LocationScreenForecast(
112112
onLocationChange: (String) -> Unit,
113113
modifier: Modifier = Modifier
114114
) {
115-
val expandedDays = remember { mutableStateMapOf<String, Int>() }
115+
val expandedDays = rememberSaveable(saver = indexSaver) { mutableStateMapOf<String, Int>() }
116116
LocationScreenForecast(
117117
forecast = locationForecast,
118118
onLocationChange = onLocationChange,
@@ -154,11 +154,13 @@ fun LocationScreenForecast(
154154
contentDescription = label
155155
}) {
156156
val index = 0
157-
WeekForecastRow(
158-
forecast.forecastWeek[index],
159-
expanded = index == expandedDayIndex,
160-
onClick = { onExpandedChanged(if (expandedDayIndex == index) -1 else index) }
161-
)
157+
forecast.forecastWeek.forEachIndexed { index, forecastDay ->
158+
WeekForecastRow(
159+
forecast.forecastWeek[index],
160+
expanded = index == expandedDayIndex,
161+
onClick = { onExpandedChanged(if (expandedDayIndex == index) -1 else index) }
162+
)
163+
}
162164
}
163165
}
164166
}
@@ -175,19 +177,19 @@ fun TopAppBar(
175177
title = {
176178
Row(verticalAlignment = Alignment.CenterVertically) {
177179
IconButton(
178-
onClick = { onLocationChange("Mountain View") }
180+
onClick = { onLocationChange("Sunnyvale") }
179181
) {
180182
Icon(
181183
Icons.Default.KeyboardArrowLeft,
182184
stringResource(R.string.prev_location)
183185
)
184186
}
185187
Text(
186-
"//TODO",
188+
locationName,
187189
modifier = Modifier.padding(horizontal = 32.dp)
188190
)
189191
IconButton(
190-
onClick = { onLocationChange("Sunnyvale") }
192+
onClick = { onLocationChange("Mountain View") }
191193
) {
192194
Icon(
193195
Icons.Default.KeyboardArrowRight,

app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationViewModel.kt

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class LocationViewModel @Inject constructor(
4545
val uiState = locationId.flatMapLatest { location ->
4646
forecastRepository.getForecast(location)
4747
.map<Forecast, LocationUiState> { Success(it) }
48+
.catch { emit(Error(it)) }
4849
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), Loading)
4950

5051
fun changeLocation(id: String) {

0 commit comments

Comments
 (0)