diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 53f0feb04c..e220f50382 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -101,6 +101,12 @@ Always remember to pay attention to [the quest guidelines](https://github.com/st Inheritance and class hierarchy should be avoided if possible. It is preferable to extract shared code to helper file such as [KerbUtil.kt](app/src/main/java/de/westnordost/streetcomplete/osm/kerb/KerbUtil.kt). +### Hints for more active people + +See ["Efficiently working together"](https://github.com/streetcomplete/StreetComplete/discussions/3450) which is addressed to people highly active in this project. + +If you are making your first issue or pull request then you can definitely skip reading it. + ## StreetComplete-related projects ### Dependencies diff --git a/app/src/main/java/de/westnordost/streetcomplete/location/FineLocationManager.kt b/app/src/main/java/de/westnordost/streetcomplete/location/FineLocationManager.kt index 86bb54554f..020745f2ce 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/location/FineLocationManager.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/location/FineLocationManager.kt @@ -21,7 +21,9 @@ class FineLocationManager(context: Context, locationUpdateCallback: (Location) - private val mainExecutor = ContextCompat.getMainExecutor(context) private val currentLocationConsumer = Consumer { if (it != null) { - locationUpdateCallback(it) + if (!networkCancellationSignal.isCanceled && !gpsCancellationSignal.isCanceled) { + locationUpdateCallback(it) + } } } private var gpsCancellationSignal = CancellationSignal() @@ -33,7 +35,6 @@ class FineLocationManager(context: Context, locationUpdateCallback: (Location) - private val locationListener = object : LocationUpdateListener { override fun onLocationChanged(location: Location) { - if (networkCancellationSignal.isCanceled || gpsCancellationSignal.isCanceled) return if (!isBetterLocation(location, lastLocation)) return lastLocation = location @@ -41,6 +42,17 @@ class FineLocationManager(context: Context, locationUpdateCallback: (Location) - } } + // Both signals are refreshed regardless of whether the device has both providers, because + // they are both canceled in removeUpdates and both checked in the locationListener + private fun refreshCancellationSignals() { + if (gpsCancellationSignal.isCanceled) { + gpsCancellationSignal = CancellationSignal() + } + if (networkCancellationSignal.isCanceled) { + networkCancellationSignal = CancellationSignal() + } + } + @RequiresPermission(ACCESS_FINE_LOCATION) fun requestUpdates(minTime: Long, minDistance: Float) { if (deviceHasGPS) @@ -51,18 +63,13 @@ class FineLocationManager(context: Context, locationUpdateCallback: (Location) - @RequiresPermission(ACCESS_FINE_LOCATION) @Synchronized fun getCurrentLocation() { + refreshCancellationSignals() if (deviceHasGPS) { - if (gpsCancellationSignal.isCanceled) { - gpsCancellationSignal = CancellationSignal() - } LocationManagerCompat.getCurrentLocation( locationManager, GPS_PROVIDER, gpsCancellationSignal, mainExecutor, currentLocationConsumer ) } if (deviceHasNetworkLocationProvider) { - if (networkCancellationSignal.isCanceled) { - networkCancellationSignal = CancellationSignal() - } LocationManagerCompat.getCurrentLocation( locationManager, NETWORK_PROVIDER, networkCancellationSignal, mainExecutor, currentLocationConsumer )