DevicePoseProvider: improve getLocation() (#1454)

* Only take updated location when it is of better quality

* Rename to AndroidLocation for clarification

* be pedantic about licenses

* fix race condition in DevicePoseProvider.kt

* add possibility to explicitly skip cache upon requesting location updates for WeatherRepository.kt

* LocationsRepository.kt: use getLocation() in combineTransform() to properly wait for & update on new locations

* LocationItem.kt: fix getAzimuthDegrees() usage for userHeading
This commit is contained in:
shtrophic
2025-07-04 11:55:20 +02:00
committed by GitHub
parent dd14c6cbaa
commit 31a1580db9
7 changed files with 119 additions and 54 deletions
@@ -25,9 +25,7 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.time.Duration
import java.util.*
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.toJavaDuration
interface WeatherRepository {
fun getActiveProvider(): Flow<WeatherProviderInfo?>
@@ -263,8 +261,9 @@ class WeatherUpdateWorker(
}
@OptIn(FlowPreview::class)
private suspend fun getLastKnownLocation(): LatLon? =
locationProvider.getLocation().timeout(10.minutes).firstOrNull().or {
locationProvider.lastLocation
}?.let { LatLon(it.latitude, it.longitude) }
private suspend fun getLastKnownLocation(): LatLon? = locationProvider.getLocation(skipCache = true)
.timeout(10.minutes)
.firstOrNull()
.or { locationProvider.lastCachedLocation }
?.let { LatLon(it.latitude, it.longitude) }
}