mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-17 19:58:57 +03:00
Handling press on pinned location option
This commit is contained in:
parent
a1d155df71
commit
dec075faf3
3 changed files with 19 additions and 7 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ class LocationSharingFragment @Inject constructor(
|
|||
override fun invalidate() = withState(viewModel) { state ->
|
||||
updateMap(state)
|
||||
updateUserAvatar(state.userItem)
|
||||
if(!hasUpdatedPin && state.pinDrawable != null) {
|
||||
if (!hasUpdatedPin && state.pinDrawable != null) {
|
||||
hasUpdatedPin = true
|
||||
updateStaticPin(state.pinDrawable)
|
||||
}
|
||||
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue