From 004f40bff568ca13d12077f9858e71f5ba474a1f Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 27 Jul 2022 15:48:40 +0200 Subject: [PATCH] Setting 5 seconds for min period of update for location tracking --- .../java/im/vector/app/features/location/Config.kt | 2 +- .../im/vector/app/features/location/LocationTracker.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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 c29e2e911a..6f947290e2 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,5 @@ 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 = 2 * 1_000L // every 2 seconds +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 aa05fe764b..079a65d9b9 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 @@ -61,6 +61,7 @@ class LocationTracker @Inject constructor( @VisibleForTesting var hasLocationFromGPSProvider = false + private var firstLocationHandled = false private val _locations = MutableSharedFlow(replay = 1) /** @@ -68,7 +69,14 @@ class LocationTracker @Inject constructor( */ val locations = _locations.asSharedFlow() .onEach { Timber.d("new location emitted") } - .debounce(MIN_TIME_TO_UPDATE_LOCATION_MILLIS) + .debounce { + if (firstLocationHandled) { + MIN_TIME_TO_UPDATE_LOCATION_MILLIS + } else { + firstLocationHandled = true + 0 + } + } .onEach { Timber.d("new location emitted after debounce") } .map { it.toLocationData() }