From 1d589e524617c02888edb419f400e28257e65afe Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sun, 2 Jan 2022 17:40:00 +0100 Subject: [PATCH] Don't force update weather data on every restart --- .../mm20/launcher2/weather/WeatherRepository.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/weather/src/main/java/de/mm20/launcher2/weather/WeatherRepository.kt b/weather/src/main/java/de/mm20/launcher2/weather/WeatherRepository.kt index dbf3eaa5..c399328c 100644 --- a/weather/src/main/java/de/mm20/launcher2/weather/WeatherRepository.kt +++ b/weather/src/main/java/de/mm20/launcher2/weather/WeatherRepository.kt @@ -110,18 +110,21 @@ class WeatherRepositoryImpl( var providerSetting: WeatherSettings.WeatherProvider? = null selectedProvider.collectLatest { if (it != providerSetting) { - providerSetting = it provider = get { parametersOf(it) } location.value = provider.getLocation() lastLocation.value = provider.getLastLocation() autoLocation.value = provider.autoLocation - provider.resetLastUpdate() - requestUpdate() + + // Force weather data update but only if provider has changed; not during + // initialization + if (providerSetting != null) { + provider.resetLastUpdate() + requestUpdate() + } + providerSetting = it } } } - - requestUpdate() } private fun groupForecastsPerDay(forecasts: List): List { @@ -175,7 +178,7 @@ class WeatherRepositoryImpl( class WeatherUpdateWorker(val context: Context, params: WorkerParameters) : CoroutineWorker(context, params), KoinComponent { - val repository: WeatherRepository by inject() + val repository: WeatherRepository by inject() override suspend fun doWork(): Result { Log.d("MM20", "Requesting weather data")