diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingAction.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingAction.kt index 3da5641c84..e575367c66 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingAction.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingAction.kt @@ -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() } diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt index 8107966de9..79c9daceb4 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewEvents.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewEvents.kt index 743daaf5e0..8d31db1119 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewEvents.kt @@ -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() } diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt index 5ad762adff..f5bf5f7eb0 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt @@ -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 { diff --git a/vector/src/main/java/im/vector/app/features/location/MapTilerMapView.kt b/vector/src/main/java/im/vector/app/features/location/MapTilerMapView.kt index 5e2c593240..b4638d6793 100644 --- a/vector/src/main/java/im/vector/app/features/location/MapTilerMapView.kt +++ b/vector/src/main/java/im/vector/app/features/location/MapTilerMapView.kt @@ -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))