diff --git a/vector/src/main/java/im/vector/app/features/location/Config.kt b/vector/src/main/java/im/vector/app/features/location/Config.kt index 6f947290e2..b65b5517d1 100644 --- a/vector/src/main/java/im/vector/app/features/location/Config.kt +++ b/vector/src/main/java/im/vector/app/features/location/Config.kt @@ -22,5 +22,3 @@ const val DEFAULT_PIN_ID = "DEFAULT_PIN_ID" const val INITIAL_MAP_ZOOM_IN_PREVIEW = 15.0 const val INITIAL_MAP_ZOOM_IN_TIMELINE = 17.0 -const val MIN_TIME_TO_UPDATE_LOCATION_MILLIS = 5 * 1_000L // every 5 seconds -const val MIN_DISTANCE_TO_UPDATE_LOCATION_METERS = 10f diff --git a/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt b/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt index 079a65d9b9..966a2600b4 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt @@ -36,6 +36,10 @@ import kotlinx.coroutines.launch import timber.log.Timber import javax.inject.Inject import javax.inject.Singleton +import kotlin.time.Duration.Companion.seconds + +@VisibleForTesting +const val MIN_DISTANCE_TO_UPDATE_LOCATION_METERS = 10f @Singleton class LocationTracker @Inject constructor( @@ -64,6 +68,9 @@ class LocationTracker @Inject constructor( private var firstLocationHandled = false private val _locations = MutableSharedFlow(replay = 1) + @VisibleForTesting + val minDurationToUpdateLocationMillis = 5.seconds.inWholeMilliseconds + /** * SharedFlow to collect location updates. */ @@ -71,7 +78,7 @@ class LocationTracker @Inject constructor( .onEach { Timber.d("new location emitted") } .debounce { if (firstLocationHandled) { - MIN_TIME_TO_UPDATE_LOCATION_MILLIS + minDurationToUpdateLocationMillis } else { firstLocationHandled = true 0 @@ -103,7 +110,7 @@ class LocationTracker @Inject constructor( locationManager.requestLocationUpdates( provider, - MIN_TIME_TO_UPDATE_LOCATION_MILLIS, + minDurationToUpdateLocationMillis, MIN_DISTANCE_TO_UPDATE_LOCATION_METERS, this ) diff --git a/vector/src/test/java/im/vector/app/features/location/LocationTrackerTest.kt b/vector/src/test/java/im/vector/app/features/location/LocationTrackerTest.kt index 454a73cd70..d6d6410c99 100644 --- a/vector/src/test/java/im/vector/app/features/location/LocationTrackerTest.kt +++ b/vector/src/test/java/im/vector/app/features/location/LocationTrackerTest.kt @@ -75,19 +75,19 @@ class LocationTrackerTest { verifyOrder { fakeLocationManager.instance.requestLocationUpdates( LocationManager.FUSED_PROVIDER, - MIN_TIME_TO_UPDATE_LOCATION_MILLIS, + locationTracker.minDurationToUpdateLocationMillis, MIN_DISTANCE_TO_UPDATE_LOCATION_METERS, locationTracker ) fakeLocationManager.instance.requestLocationUpdates( LocationManager.GPS_PROVIDER, - MIN_TIME_TO_UPDATE_LOCATION_MILLIS, + locationTracker.minDurationToUpdateLocationMillis, MIN_DISTANCE_TO_UPDATE_LOCATION_METERS, locationTracker ) fakeLocationManager.instance.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, - MIN_TIME_TO_UPDATE_LOCATION_MILLIS, + locationTracker.minDurationToUpdateLocationMillis, MIN_DISTANCE_TO_UPDATE_LOCATION_METERS, locationTracker ) @@ -154,7 +154,7 @@ class LocationTrackerTest { locationTracker.onLocationChanged(fusedLocation) locationTracker.onLocationChanged(gpsLocation) locationTracker.onLocationChanged(networkLocation) - advanceTimeBy(MIN_TIME_TO_UPDATE_LOCATION_MILLIS + 1) + advanceTimeBy(locationTracker.minDurationToUpdateLocationMillis + 1) val expectedLocationData = LocationData( latitude = 1.0, @@ -188,7 +188,7 @@ class LocationTrackerTest { locationTracker.onLocationChanged(gpsLocation) locationTracker.onLocationChanged(networkLocation) - advanceTimeBy(MIN_TIME_TO_UPDATE_LOCATION_MILLIS + 1) + advanceTimeBy(locationTracker.minDurationToUpdateLocationMillis + 1) val expectedLocationData = LocationData( latitude = 1.0, @@ -217,7 +217,7 @@ class LocationTrackerTest { val resultUpdates = locationTracker.locations.test(this) locationTracker.onLocationChanged(networkLocation) - advanceTimeBy(MIN_TIME_TO_UPDATE_LOCATION_MILLIS + 1) + advanceTimeBy(locationTracker.minDurationToUpdateLocationMillis + 1) val expectedLocationData = LocationData( latitude = 1.0, @@ -243,7 +243,7 @@ class LocationTrackerTest { val resultUpdates = locationTracker.locations.test(this) locationTracker.requestLastKnownLocation() - advanceTimeBy(MIN_TIME_TO_UPDATE_LOCATION_MILLIS + 1) + advanceTimeBy(locationTracker.minDurationToUpdateLocationMillis + 1) val expectedLocationData = LocationData( latitude = A_LATITUDE,