Compare commits
2 Commits
v1.40.2-ty
...
v1.40.2-ty
| Author | SHA1 | Date | |
|---|---|---|---|
| c56ea58fc5 | |||
| b0072f0fc2 |
@@ -34,8 +34,8 @@ android {
|
|||||||
applicationId = "de.mm20.launcher2"
|
applicationId = "de.mm20.launcher2"
|
||||||
minSdk = libs.versions.minSdk.get().toInt()
|
minSdk = libs.versions.minSdk.get().toInt()
|
||||||
targetSdk = libs.versions.targetSdk.get().toInt()
|
targetSdk = libs.versions.targetSdk.get().toInt()
|
||||||
versionCode = System.getenv("VERSION_CODE_OVERRIDE")?.toIntOrNull() ?: 2026091201
|
versionCode = System.getenv("VERSION_CODE_OVERRIDE")?.toIntOrNull() ?: 2026091202
|
||||||
versionName = "1.40.2-typing.8"
|
versionName = "1.40.2-typing.9"
|
||||||
signingConfig = signingConfigs.getByName("debug")
|
signingConfig = signingConfigs.getByName("debug")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ interface WeatherProvider {
|
|||||||
return 1000 * 60 * 60L
|
return 1000 * 60 * 60L
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this provider pushes weather updates on its own instead of being polled, and
|
||||||
|
* resolves its location itself. [WeatherUpdateWorker] then has nothing to pull and must not
|
||||||
|
* request a location for it.
|
||||||
|
*/
|
||||||
|
val isPushBased: Boolean
|
||||||
|
get() = false
|
||||||
|
|
||||||
suspend fun getWeatherData(location: WeatherLocation): List<Forecast>?
|
suspend fun getWeatherData(location: WeatherLocation): List<Forecast>?
|
||||||
suspend fun getWeatherData(lat: Double, lon: Double): List<Forecast>?
|
suspend fun getWeatherData(lat: Double, lon: Double): List<Forecast>?
|
||||||
suspend fun findLocation(query: String): List<WeatherLocation>
|
suspend fun findLocation(query: String): List<WeatherLocation>
|
||||||
|
|||||||
@@ -79,13 +79,12 @@ internal class WeatherRepositoryImpl(
|
|||||||
}
|
}
|
||||||
scope.launch {
|
scope.launch {
|
||||||
settings.collectLatest {
|
settings.collectLatest {
|
||||||
if (it.managedLocation) {
|
val provider = WeatherProvider.getInstance(it.provider)
|
||||||
// The provider resolves its own location and pushes weather updates, so there
|
if (provider.isPushBased) {
|
||||||
// is nothing to poll for.
|
// The provider sends its updates itself, so there is nothing to poll for.
|
||||||
WorkManager.getInstance(context).cancelUniqueWork("weather")
|
WorkManager.getInstance(context).cancelUniqueWork("weather")
|
||||||
return@collectLatest
|
return@collectLatest
|
||||||
}
|
}
|
||||||
val provider = WeatherProvider.getInstance(it.provider)
|
|
||||||
val weatherRequest =
|
val weatherRequest =
|
||||||
PeriodicWorkRequestBuilder<WeatherUpdateWorker>(Duration.ofMillis(provider.getUpdateInterval()))
|
PeriodicWorkRequestBuilder<WeatherUpdateWorker>(Duration.ofMillis(provider.getUpdateInterval()))
|
||||||
.build()
|
.build()
|
||||||
@@ -218,20 +217,19 @@ class WeatherUpdateWorker(
|
|||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
Log.d("WeatherUpdateWorker", "Requesting weather data")
|
Log.d("WeatherUpdateWorker", "Requesting weather data")
|
||||||
val settingsData = settings.first()
|
val settingsData = settings.first()
|
||||||
|
val provider = WeatherProvider.getInstance(settingsData.provider)
|
||||||
|
|
||||||
// A provider with a managed location resolves its position itself and pushes weather
|
// A push-based provider sends its updates on its own and resolves its own location
|
||||||
// updates instead of being polled (Breezy Weather does both). There is nothing to pull,
|
// (Breezy Weather does both), so there is nothing to pull here. Its getWeatherData()
|
||||||
// and its getWeatherData() always returns null - which used to make this worker request a
|
// always returns null, which used to make this worker request a location - registering
|
||||||
// location (holding GPS and network listeners for up to ten minutes at a time) and then
|
// GPS and network listeners and holding them for up to ten minutes - and then return
|
||||||
// return Result.retry() forever, without ever setting lastUpdate, so the update interval
|
// Result.retry() forever, without ever setting lastUpdate, so the interval check below
|
||||||
// check below could never short-circuit it either.
|
// could never short-circuit it either.
|
||||||
if (settingsData.managedLocation) {
|
if (provider.isPushBased) {
|
||||||
Log.d("WeatherUpdateWorker", "Provider manages its own location, nothing to pull")
|
Log.d("WeatherUpdateWorker", "Provider pushes updates, nothing to pull")
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
val provider = WeatherProvider.getInstance(settingsData.provider)
|
|
||||||
|
|
||||||
val updateInterval = provider.getUpdateInterval()
|
val updateInterval = provider.getUpdateInterval()
|
||||||
val lastUpdate = settingsData.lastUpdate
|
val lastUpdate = settingsData.lastUpdate
|
||||||
|
|
||||||
@@ -240,21 +238,26 @@ class WeatherUpdateWorker(
|
|||||||
return Result.failure()
|
return Result.failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
val weatherData = if (settingsData.autoLocation) {
|
val weatherData = when {
|
||||||
val latLon = getLastKnownLocation() ?: settingsData.lastLocation
|
// A managed location means the provider resolves the position itself, so requesting
|
||||||
if (latLon == null) {
|
// one here would be wasted work that holds the location stack open.
|
||||||
Log.e("WeatherUpdateWorker", "Could not get location")
|
settingsData.managedLocation || !settingsData.autoLocation -> {
|
||||||
return Result.failure()
|
val location = settings.location.first()
|
||||||
|
if (location == null) {
|
||||||
|
Log.e("WeatherUpdateWorker", "Location not set")
|
||||||
|
return Result.failure()
|
||||||
|
}
|
||||||
|
provider.getWeatherData(location)
|
||||||
}
|
}
|
||||||
settings.setLastLocation(latLon)
|
else -> {
|
||||||
provider.getWeatherData(latLon.lat, latLon.lon)
|
val latLon = getLastKnownLocation() ?: settingsData.lastLocation
|
||||||
} else {
|
if (latLon == null) {
|
||||||
val location = settings.location.first()
|
Log.e("WeatherUpdateWorker", "Could not get location")
|
||||||
if (location == null) {
|
return Result.failure()
|
||||||
Log.e("WeatherUpdateWorker", "Location not set")
|
}
|
||||||
return Result.failure()
|
settings.setLastLocation(latLon)
|
||||||
|
provider.getWeatherData(latLon.lat, latLon.lon)
|
||||||
}
|
}
|
||||||
provider.getWeatherData(location)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (weatherData == null) {
|
return if (weatherData == null) {
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ class BreezyWeatherProvider(
|
|||||||
) : WeatherProvider, KoinComponent {
|
) : WeatherProvider, KoinComponent {
|
||||||
private val database: AppDatabase by inject()
|
private val database: AppDatabase by inject()
|
||||||
|
|
||||||
|
// Breezy sends its weather data to us (see pushWeatherData) and manages its own location.
|
||||||
|
override val isPushBased: Boolean = true
|
||||||
|
|
||||||
override suspend fun getWeatherData(location: WeatherLocation): List<Forecast>? {
|
override suspend fun getWeatherData(location: WeatherLocation): List<Forecast>? {
|
||||||
// Noop implementation, because Breezy weather is handled in a special way
|
// Noop implementation, because Breezy weather is handled in a special way
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user