Fix crash if there's no weather data

This commit is contained in:
MM20 2022-01-03 22:52:14 +01:00
parent 2a01bccb62
commit c5803b7e75
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -21,6 +21,7 @@ class WeatherWidgetWM : ViewModel(), KoinComponent {
private var selectedDayIndex = 0
set(value) {
field = min(value, forecasts.lastIndex)
if (field < 0) return
selectedForecastIndex = min(
selectedForecastIndex,
forecasts[value].hourlyForecasts.lastIndex
@ -32,6 +33,7 @@ class WeatherWidgetWM : ViewModel(), KoinComponent {
private var selectedForecastIndex = 0
set(value) {
if (selectedDayIndex < 0) return
field = min(value, forecasts[selectedDayIndex].hourlyForecasts.lastIndex)
currentForecast.postValue(getCurrentlySelectedForecast())
}