From 19a5acdf431f0d8b048c06f80386952470671d1a Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sun, 12 Oct 2025 18:13:20 +0200 Subject: [PATCH] Dismiss forecasts that are more than 7 days in the future --- .../java/de/mm20/launcher2/weather/WeatherRepository.kt | 3 ++- .../mm20/launcher2/weather/breezy/BreezyWeatherProvider.kt | 4 +++- docs/docs/developer-guide/plugins/plugin-types/weather.md | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/data/weather/src/main/java/de/mm20/launcher2/weather/WeatherRepository.kt b/data/weather/src/main/java/de/mm20/launcher2/weather/WeatherRepository.kt index bc9aa811d..ec0884336 100644 --- a/data/weather/src/main/java/de/mm20/launcher2/weather/WeatherRepository.kt +++ b/data/weather/src/main/java/de/mm20/launcher2/weather/WeatherRepository.kt @@ -244,8 +244,9 @@ class WeatherUpdateWorker( Result.retry() } else { Log.i("WeatherUpdateWorker", "Weather update succeeded") + val in7Days = System.currentTimeMillis() + Duration.ofDays(7).toMillis() appDatabase.weatherDao() - .replaceAll(weatherData.map { it.toDatabaseEntity() }) + .replaceAll(weatherData.takeWhile { it.timestamp < in7Days }.map { it.toDatabaseEntity() }) settings.setLastUpdate(System.currentTimeMillis()) Result.success() } diff --git a/data/weather/src/main/java/de/mm20/launcher2/weather/breezy/BreezyWeatherProvider.kt b/data/weather/src/main/java/de/mm20/launcher2/weather/breezy/BreezyWeatherProvider.kt index 9a51ec523..2427c75b5 100644 --- a/data/weather/src/main/java/de/mm20/launcher2/weather/breezy/BreezyWeatherProvider.kt +++ b/data/weather/src/main/java/de/mm20/launcher2/weather/breezy/BreezyWeatherProvider.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.koin.core.component.KoinComponent import org.koin.core.component.inject +import java.time.Duration import kotlin.time.Duration.Companion.days class BreezyWeatherProvider( @@ -112,8 +113,9 @@ class BreezyWeatherProvider( } withContext(Dispatchers.IO) { + val in7Days = System.currentTimeMillis() + Duration.ofDays(7).toMillis() database.weatherDao() - .replaceAll(result.map { it.toDatabaseEntity() }) + .replaceAll(result.takeWhile { it.timestamp < in7Days }.map { it.toDatabaseEntity() }) } } diff --git a/docs/docs/developer-guide/plugins/plugin-types/weather.md b/docs/docs/developer-guide/plugins/plugin-types/weather.md index 68d3ea34f..3f7e195a5 100644 --- a/docs/docs/developer-guide/plugins/plugin-types/weather.md +++ b/docs/docs/developer-guide/plugins/plugin-types/weather.md @@ -55,7 +55,7 @@ There are three types of locations: - `WeatherLocation.Managed`: a special location that indicates that the plugin should determine the location itself. -## Featch weather data +## Fetch weather data Implement both `getWeatherData` methods: @@ -81,6 +81,11 @@ of