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

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAlcerreca committed Oct 23, 2022
1 parent b4444a0 commit 90ce589
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fun LocationScreenForecast(
onLocationChange: (String) -> Unit,
modifier: Modifier = Modifier
) {
val expandedDays = remember { mutableStateMapOf<String, Int>() }
val expandedDays = rememberSaveable(saver = indexSaver) { mutableStateMapOf<String, Int>() }
LocationScreenForecast(
forecast = locationForecast,
onLocationChange = onLocationChange,
Expand Down Expand Up @@ -154,11 +154,13 @@ fun LocationScreenForecast(
contentDescription = label
}) {
val index = 0
WeekForecastRow(
forecast.forecastWeek[index],
expanded = index == expandedDayIndex,
onClick = { onExpandedChanged(if (expandedDayIndex == index) -1 else index) }
)
forecast.forecastWeek.forEachIndexed { index, forecastDay ->
WeekForecastRow(
forecast.forecastWeek[index],
expanded = index == expandedDayIndex,
onClick = { onExpandedChanged(if (expandedDayIndex == index) -1 else index) }
)
}
}
}
}
Expand All @@ -175,19 +177,19 @@ fun TopAppBar(
title = {
Row(verticalAlignment = Alignment.CenterVertically) {
IconButton(
onClick = { onLocationChange("Mountain View") }
onClick = { onLocationChange("Sunnyvale") }
) {
Icon(
Icons.Default.KeyboardArrowLeft,
stringResource(R.string.prev_location)
)
}
Text(
"//TODO",
locationName,
modifier = Modifier.padding(horizontal = 32.dp)
)
IconButton(
onClick = { onLocationChange("Sunnyvale") }
onClick = { onLocationChange("Mountain View") }
) {
Icon(
Icons.Default.KeyboardArrowRight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class LocationViewModel @Inject constructor(
val uiState = locationId.flatMapLatest { location ->
forecastRepository.getForecast(location)
.map<Forecast, LocationUiState> { Success(it) }
.catch { emit(Error(it)) }
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), Loading)

fun changeLocation(id: String) {
Expand Down

0 comments on commit 90ce589

Please sign in to comment.