Zoom to user location action

This commit is contained in:
Maxime Naturel 2022-03-08 14:29:48 +01:00
parent 01aff36597
commit 125b8d2058
5 changed files with 16 additions and 4 deletions

View file

@ -22,4 +22,5 @@ sealed class LocationSharingAction : VectorViewModelAction {
object CurrentUserLocationSharingAction : LocationSharingAction()
data class PinnedLocationSharingAction(val locationData: LocationData?) : LocationSharingAction()
data class LocationTargetChangeAction(val locationData: LocationData) : LocationSharingAction()
object ZoomToUserLocationAction : LocationSharingAction()
}

View file

@ -78,6 +78,7 @@ class LocationSharingFragment @Inject constructor(
when (it) {
LocationSharingViewEvents.LocationNotAvailableError -> handleLocationNotAvailableError()
LocationSharingViewEvents.Close -> activity?.finish()
is LocationSharingViewEvents.ZoomToUserLocation -> handleZoomToUserLocationEvent(it)
}.exhaustive
}
}
@ -144,13 +145,16 @@ class LocationSharingFragment @Inject constructor(
private fun initLocateBtn() {
views.mapView.locateBtn.setOnClickListener {
// TODO retrieve user location and zoom to this location
viewModel.handle(LocationSharingAction.ZoomToUserLocationAction)
}
}
private fun handleZoomToUserLocationEvent(event: LocationSharingViewEvents.ZoomToUserLocation) {
views.mapView.zoomToLocation(event.userLocation.latitude, event.userLocation.longitude)
}
private fun initOptionsPicker() {
// TODO
// reset map to user location when clicking on reset icon
// changes in the event sent when this is a pinned location
// changes in the parsing of events when receiving pinned location: since we may present a different UI
// unit tests

View file

@ -21,4 +21,5 @@ import im.vector.app.core.platform.VectorViewEvents
sealed class LocationSharingViewEvents : VectorViewEvents {
object Close : LocationSharingViewEvents()
object LocationNotAvailableError : LocationSharingViewEvents()
data class ZoomToUserLocation(val userLocation: LocationData) : LocationSharingViewEvents()
}

View file

@ -117,6 +117,7 @@ class LocationSharingViewModel @AssistedInject constructor(
LocationSharingAction.CurrentUserLocationSharingAction -> handleCurrentUserLocationSharingAction()
is LocationSharingAction.PinnedLocationSharingAction -> handlePinnedLocationSharingAction(action)
is LocationSharingAction.LocationTargetChangeAction -> handleLocationTargetChangeAction(action)
LocationSharingAction.ZoomToUserLocationAction -> handleZoomToUserLocationAction()
}.exhaustive
}
@ -148,6 +149,12 @@ class LocationSharingViewModel @AssistedInject constructor(
}
}
private fun handleZoomToUserLocationAction() = withState { state ->
state.lastKnownUserLocation?.let { location ->
_viewEvents.post(LocationSharingViewEvents.ZoomToUserLocation(location))
}
}
override fun onLocationUpdate(locationData: LocationData) {
// TODO compare location with lastTargetLocation => need to save info into the ViewState
setState {

View file

@ -154,7 +154,6 @@ class MapTilerMapView @JvmOverloads constructor(
safeMapRefs.map.uiSettings.setLogoMargins(0, 0, 0, state.logoMarginBottom)
// TODO check conflict of rendering with preview location in timeline
val pinDrawable = state.pinDrawable ?: userLocationDrawable
pinDrawable?.let { drawable ->
if (!safeMapRefs.style.isFullyLoaded ||
@ -181,7 +180,7 @@ class MapTilerMapView @JvmOverloads constructor(
}
}
private fun zoomToLocation(latitude: Double, longitude: Double) {
fun zoomToLocation(latitude: Double, longitude: Double) {
Timber.d("## Location: zoomToLocation")
mapRefs?.map?.cameraPosition = CameraPosition.Builder()
.target(LatLng(latitude, longitude))