Recompute location comparison on new user location

This commit is contained in:
Maxime Naturel 2022-03-08 15:02:42 +01:00
parent 125b8d2058
commit 8d1822da96
1 changed files with 7 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvid
import im.vector.app.features.location.domain.usecase.CompareLocationsUseCase import im.vector.app.features.location.domain.usecase.CompareLocationsUseCase
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.lastOrNull
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -156,10 +157,15 @@ class LocationSharingViewModel @AssistedInject constructor(
} }
override fun onLocationUpdate(locationData: LocationData) { override fun onLocationUpdate(locationData: LocationData) {
// TODO compare location with lastTargetLocation => need to save info into the ViewState
setState { setState {
copy(lastKnownUserLocation = locationData) copy(lastKnownUserLocation = locationData)
} }
viewModelScope.launch {
// recompute location comparison using last received target location
locationTargetFlow.lastOrNull()?.let {
locationTargetFlow.emit(it)
}
}
} }
override fun onLocationProviderIsNotAvailable() { override fun onLocationProviderIsNotAvailable() {