diff --git a/app/src/main/java/com/kylecorry/trail_sense/settings/ui/CalibrateBarometerFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/settings/ui/CalibrateBarometerFragment.kt index 1019eefc4..a2fb00241 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/settings/ui/CalibrateBarometerFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/settings/ui/CalibrateBarometerFragment.kt @@ -25,6 +25,7 @@ import com.kylecorry.trail_sense.shared.UserPreferences import com.kylecorry.trail_sense.shared.sensors.SensorService import com.kylecorry.trail_sense.tools.weather.domain.RawWeatherObservation import com.kylecorry.trail_sense.tools.weather.domain.WeatherObservation +import com.kylecorry.trail_sense.tools.weather.infrastructure.WeatherLogger import com.kylecorry.trail_sense.tools.weather.infrastructure.subsystem.WeatherSubsystem import java.time.Duration import java.time.Instant @@ -54,6 +55,14 @@ class CalibrateBarometerFragment : AndromedaPreferenceFragment() { private val runner = CoroutineQueueRunner() + private val logger by lazy { + WeatherLogger( + requireContext(), + Duration.ofSeconds(30), + Duration.ofMillis(500), + ) + } + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.barometer_calibration, rootKey) @@ -186,11 +195,13 @@ class CalibrateBarometerFragment : AndromedaPreferenceFragment() { override fun onResume() { super.onResume() updateTimer.interval(200) + logger.start() } override fun onPause() { super.onPause() updateTimer.stop() + logger.stop() } private fun update() { diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/weather/infrastructure/WeatherLogger.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/weather/infrastructure/WeatherLogger.kt index a3927b60d..29b4c3adf 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/weather/infrastructure/WeatherLogger.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/weather/infrastructure/WeatherLogger.kt @@ -12,23 +12,23 @@ import java.time.Duration class WeatherLogger( context: Context, private val interval: Duration, - private val intialDelay: Duration = Duration.ZERO, - private val loadingIndicator: ILoadingIndicator + private val initialDelay: Duration = Duration.ZERO, + private val loadingIndicator: ILoadingIndicator? = null ) { private val weather = WeatherSubsystem.getInstance(context) private val runner = CoroutineQueueRunner() private val timer = CoroutineTimer { onIO { runner.skipIfRunning { - onMain { loadingIndicator.show() } + onMain { loadingIndicator?.show() } weather.updateWeather() - onMain { loadingIndicator.hide() } + onMain { loadingIndicator?.hide() } } } } fun start() { - timer.interval(interval, intialDelay) + timer.interval(interval, initialDelay) } fun stop() {