Dismiss forecasts that are more than 7 days in the future
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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() })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user