Handling press on pinned location option

This commit is contained in:
Maxime Naturel 2022-03-04 15:41:27 +01:00
parent a1d155df71
commit dec075faf3
3 changed files with 19 additions and 7 deletions

View File

@ -19,5 +19,6 @@ package im.vector.app.features.location
import im.vector.app.core.platform.VectorViewModelAction
sealed class LocationSharingAction : VectorViewModelAction {
object OnShareLocation : LocationSharingAction()
object CurrentUserLocationSharingAction : LocationSharingAction()
data class PinnedLocationSharingAction(val locationData: LocationData?) : LocationSharingAction()
}

View File

@ -147,10 +147,11 @@ class LocationSharingFragment @Inject constructor(
// set no option at start
views.shareLocationOptionsPicker.render()
views.shareLocationOptionsPicker.optionPinned.debouncedClicks {
// TODO
val selectedLocation = views.mapView.getLocationOfMapCenter()
viewModel.handle(LocationSharingAction.PinnedLocationSharingAction(selectedLocation))
}
views.shareLocationOptionsPicker.optionUserCurrent.debouncedClicks {
viewModel.handle(LocationSharingAction.OnShareLocation)
viewModel.handle(LocationSharingAction.CurrentUserLocationSharingAction)
}
views.shareLocationOptionsPicker.optionUserLive.debouncedClicks {
// TODO

View File

@ -71,12 +71,22 @@ class LocationSharingViewModel @AssistedInject constructor(
override fun handle(action: LocationSharingAction) {
when (action) {
LocationSharingAction.OnShareLocation -> handleShareLocation()
LocationSharingAction.CurrentUserLocationSharingAction -> handleCurrentUserLocationSharingAction()
is LocationSharingAction.PinnedLocationSharingAction -> handlePinnedLocationSharingAction(action)
}.exhaustive
}
private fun handleShareLocation() = withState { state ->
state.lastKnownUserLocation?.let { location ->
private fun handleCurrentUserLocationSharingAction() = withState { state ->
shareLocation(state.lastKnownUserLocation)
}
private fun handlePinnedLocationSharingAction(action: LocationSharingAction.PinnedLocationSharingAction) {
// TODO check if we can use the same api than for user location?
shareLocation(action.locationData)
}
private fun shareLocation(locationData: LocationData?) {
locationData?.let { location ->
room.sendLocation(
latitude = location.latitude,
longitude = location.longitude,