diff --git a/.github/workflows/build_and_local_tests.yml b/.github/workflows/build_and_local_tests.yml index 779887e..0f83824 100644 --- a/.github/workflows/build_and_local_tests.yml +++ b/.github/workflows/build_and_local_tests.yml @@ -19,6 +19,14 @@ jobs: java-version: '11' distribution: 'temurin' cache: gradle + + - name: Prevent changes in test/ + uses: xalvarez/prevent-file-change-action@v1 + if: github.event_name == 'pull_request' + with: + githubToken: ${{ secrets.GITHUB_TOKEN }} + pattern: ^app/src/test/ + #trustedAuthors: JoseAlcerreca - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationScreen.kt b/app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationScreen.kt index ed77a60..69a0fe2 100644 --- a/app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationScreen.kt +++ b/app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationScreen.kt @@ -112,7 +112,7 @@ fun LocationScreenForecast( onLocationChange: (String) -> Unit, modifier: Modifier = Modifier ) { - val expandedDays = remember { mutableStateMapOf() } + val expandedDays = rememberSaveable(saver = indexSaver) { mutableStateMapOf() } LocationScreenForecast( forecast = locationForecast, onLocationChange = onLocationChange, @@ -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) } + ) + } } } } @@ -175,7 +177,7 @@ fun TopAppBar( title = { Row(verticalAlignment = Alignment.CenterVertically) { IconButton( - onClick = { onLocationChange("Mountain View") } + onClick = { onLocationChange("Sunnyvale") } ) { Icon( Icons.Default.KeyboardArrowLeft, @@ -183,11 +185,11 @@ fun TopAppBar( ) } Text( - "//TODO", + locationName, modifier = Modifier.padding(horizontal = 32.dp) ) IconButton( - onClick = { onLocationChange("Sunnyvale") } + onClick = { onLocationChange("Mountain View") } ) { Icon( Icons.Default.KeyboardArrowRight, diff --git a/app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationViewModel.kt b/app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationViewModel.kt index b9f141c..720d490 100644 --- a/app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationViewModel.kt +++ b/app/src/main/java/com/google/ads22/speedchallenge/ui/location/LocationViewModel.kt @@ -45,6 +45,7 @@ class LocationViewModel @Inject constructor( val uiState = locationId.flatMapLatest { location -> forecastRepository.getForecast(location) .map { Success(it) } + .catch { emit(Error(it)) } }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), Loading) fun changeLocation(id: String) {