Dismiss forecasts that are more than 7 days in the future

This commit is contained in:
MM20
2025-10-12 18:13:20 +02:00
parent 423caa8879
commit 19a5acdf43
3 changed files with 11 additions and 3 deletions

View File

@@ -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()
}

View File

@@ -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() })
}
}

View File

@@ -55,7 +55,7 @@ There are three types of locations:
- <a href="/reference/plugins/sdk/de.mm20.launcher2.sdk.weather/-weather-location/-managed/index.html" target="_blank">`WeatherLocation.Managed`</a>:
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 <a href="/reference/plugins/sdk/de.mm20.launcher2.sdk.weather/-forecast/index
s. If an error occurs, you can throw an exception or return `null`, in this case the launcher will
keep the old data and start another attempt at a later time.
> [!NOTE]
> You should at most return weather data for the next 7 days. Everything after will be dismissed by
> the launcher.
`Forecast` objects need at least a `timestamp` (unix time in millis), a `temperature`,
a `condition`, an `icon`, a `location` name, and a `provider` name.