Setting 5 seconds for min period of update for location tracking

This commit is contained in:
Maxime NATUREL 2022-07-27 15:48:40 +02:00
parent 1411fdd99f
commit 004f40bff5
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -61,6 +61,7 @@ class LocationTracker @Inject constructor(
@VisibleForTesting
var hasLocationFromGPSProvider = false
private var firstLocationHandled = false
private val _locations = MutableSharedFlow<Location>(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() }