Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f89956ae authored by Ellen Poe's avatar Ellen Poe
Browse files

Merge branch 'ellenhp/fallback_to_recent_location' into 'main'

If no location is available, use last known location

See merge request e/os/cardinal!19
parents 471dbc78 82c1b449
Loading
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ class LocationRepository @Inject constructor(

    private companion object {
        private const val LOCATION_REQUEST_INTERVAL_MS = 15000L // 15 seconds
        private const val LOCATION_REQUEST_TIMEOUT_MS = 10000L // 10 seconds
        private const val LOCATION_REQUEST_TIMEOUT_MS = 5000L // 5 seconds
        private const val CONTINUOUS_LOCATION_UPDATE_INTERVAL_MS = 5000L // 5 seconds
        private const val CONTINUOUS_LOCATION_UPDATE_DISTANCE_M = 5f // 5 meters
        private const val FUSED_PROVIDER_TIMEOUT_MS =
@@ -458,13 +458,14 @@ class LocationRepository @Inject constructor(
    ) {
        kotlinx.coroutines.MainScope().launch {
            kotlinx.coroutines.delay(LOCATION_REQUEST_TIMEOUT_MS)
            val lastKnownLocation = getLastKnownLocation(locationManager)
            if (locationDeferred.isActive) {
                try {
                    locationManager.removeUpdates(locationListener)
                } catch (_: Exception) {
                    // Ignore exceptions during cleanup
                }
                locationDeferred.complete(null)
                locationDeferred.complete(lastKnownLocation)
            }
        }
    }