Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/weather #47

Merged
merged 19 commits into from
Mar 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Abdul Basit <33172684+SEAbdulbasit@users.noreply.github.com>
  • Loading branch information
AmeerAmjed and SEAbdulbasit committed Mar 15, 2024
commit 131cc1c14719e1d34aac799031543af3cc8af426
Original file line number Diff line number Diff line change
Expand Up @@ -94,42 +94,37 @@ class ListScreenViewModel {
}
}

@OptIn(ExperimentalResourceApi::class)
@OptIn(ExperimentalResourceApi::class)
private suspend fun updateSelectedIndices(
selectedCountryIndex: Int,
selectedTouristPlacesIndex: Int,
) {
with(state.value as ListScreenState.Success) {
countriesList[selectedCountryIndex].touristPlaces[selectedTouristPlacesIndex].weather?.let {
if (countriesList[selectedCountryIndex].touristPlaces[selectedTouristPlacesIndex].weather != null) {
state.emit(
this.copy(
selectedTouristPlacesIndex = selectedTouristPlacesIndex,
selectedCountryIndex = selectedCountryIndex,
)
)
}
?: countriesList[selectedCountryIndex].touristPlaces[selectedTouristPlacesIndex].location.let {
countriesApi.getWeather(it)
}.let { weather ->

val updatedCountriesList = countriesList.toMutableList()
val currentCountry = updatedCountriesList[selectedCountryIndex]
val updatedTouristPlaces = currentCountry.touristPlaces.toMutableList()
updatedTouristPlaces[selectedTouristPlacesIndex] =
updatedTouristPlaces[selectedTouristPlacesIndex].copy(weather = weather)
updatedCountriesList[selectedCountryIndex] =
currentCountry.copy(touristPlaces = updatedTouristPlaces)

state.emit(
} else {
val weather =
countriesApi.getWeather(countriesList[selectedCountryIndex].touristPlaces[selectedTouristPlacesIndex].location)
countriesList[selectedCountryIndex].touristPlaces[selectedTouristPlacesIndex].copy(
weather = weather
)
state.update {
this.copy(
selectedTouristPlacesIndex = selectedTouristPlacesIndex,
selectedCountryIndex = selectedCountryIndex,
countriesList = updatedCountriesList,
countriesList = countriesList
)
)
}
}
}
}


private suspend fun emitNewState(
actions: ListViewModelActions.OnCountrySelected,
Expand Down