diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/astronomy/ui/AstronomyFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/astronomy/ui/AstronomyFragment.kt index 994103ec8..d4dd45286 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/astronomy/ui/AstronomyFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/astronomy/ui/AstronomyFragment.kt @@ -481,7 +481,7 @@ class AstronomyFragment : BoundFragment() { updateAstronomyDetails() } } - + effect("seek_details", currentSeekChartTime, displayDate, isSeeking, location) { if (!isSeeking) { return@effect diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/weather/ui/WeatherFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/weather/ui/WeatherFragment.kt index 17945c850..18c0d2dba 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/weather/ui/WeatherFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/weather/ui/WeatherFragment.kt @@ -7,6 +7,8 @@ import android.view.ViewGroup import androidx.core.view.isVisible import com.kylecorry.andromeda.alerts.dialog import com.kylecorry.andromeda.alerts.toast +import com.kylecorry.andromeda.core.coroutines.onIO +import com.kylecorry.andromeda.core.coroutines.onMain import com.kylecorry.andromeda.core.system.Resources import com.kylecorry.andromeda.core.topics.generic.asLiveData import com.kylecorry.andromeda.core.topics.generic.replay @@ -26,10 +28,8 @@ import com.kylecorry.trail_sense.shared.Units import com.kylecorry.trail_sense.shared.UserPreferences import com.kylecorry.trail_sense.shared.alerts.ResettableLoadingIndicator import com.kylecorry.trail_sense.shared.alerts.ViewLoadingIndicator -import com.kylecorry.trail_sense.shared.extensions.getOrNull import com.kylecorry.trail_sense.shared.debugging.isDebug -import com.kylecorry.andromeda.core.coroutines.onIO -import com.kylecorry.andromeda.core.coroutines.onMain +import com.kylecorry.trail_sense.shared.extensions.getOrNull import com.kylecorry.trail_sense.shared.permissions.RequestRemoveBatteryRestrictionCommand import com.kylecorry.trail_sense.tools.weather.domain.CurrentWeather import com.kylecorry.trail_sense.tools.weather.domain.WeatherObservation @@ -66,11 +66,11 @@ class WeatherFragment : BoundFragment() { private val formatService by lazy { FormatService.getInstance(requireContext()) } - private var history: List = listOf() - private var rawHistory: List> = listOf() + private var history by state>(emptyList()) + private var rawHistory by state>>(emptyList()) private val weatherSubsystem by lazy { WeatherSubsystem.getInstance(requireContext()) } - private var weather: CurrentWeather? = null + private var weather by state(null) private val loadingIndicator by lazy { ResettableLoadingIndicator( ViewLoadingIndicator(binding.weatherUpdating) @@ -136,6 +136,7 @@ class WeatherFragment : BoundFragment() { weatherSubsystem.enableMonitor() RequestRemoveBatteryRestrictionCommand(this).execute() } + null -> {} } } @@ -209,8 +210,23 @@ class WeatherFragment : BoundFragment() { weather = weatherSubsystem.getWeather() } - onMain { - update() + } + } + + override fun onUpdate() { + super.onUpdate() + + effect("chart", history, rawHistory) { + displayPressureChart(history, rawHistory) + } + + effect("list", weather) { + updateList() + } + + effect("forecast", weather) { + inBackground { + updateForecast() } } } @@ -232,15 +248,6 @@ class WeatherFragment : BoundFragment() { } } - private fun update() { - if (!isBound) return - displayPressureChart(history, rawHistory) - updateList() - inBackground { - updateForecast() - } - } - private fun displayPressureChart( readings: List, rawReadings: List>