From 9256b5671b87d9935c36e852534e6d741f6ecbcb Mon Sep 17 00:00:00 2001 From: Maxime Naturel Date: Fri, 4 Mar 2022 09:16:12 +0100 Subject: [PATCH] Show options menu on top of the map --- .../location/LocationSharingFragment.kt | 28 ++++++++++++++++--- .../location/LocationSharingViewState.kt | 1 + .../vector/app/features/location/MapState.kt | 4 ++- .../app/features/location/MapTilerMapView.kt | 2 ++ .../res/layout/fragment_location_sharing.xml | 6 ++-- 5 files changed, 34 insertions(+), 7 deletions(-) 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 b1033f2797..941782b385 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 @@ -114,9 +114,9 @@ class LocationSharingFragment @Inject constructor( } override fun invalidate() = withState(viewModel) { state -> - views.mapView.render(state.toMapState()) - views.shareLocationGpsLoading.isGone = state.lastKnownLocation != null + updateMap(state) updateUserAvatar(state.userItem) + views.shareLocationGpsLoading.isGone = state.lastKnownLocation != null } private fun handleLocationNotAvailableError() { @@ -132,8 +132,10 @@ class LocationSharingFragment @Inject constructor( private fun initOptionsPicker() { // TODO - // change the options dynamically depending on the current chosen location - views.shareLocationOptionsPicker.render(LocationSharingOption.USER_CURRENT) + // change the pin dynamically depending on the current chosen location: cf. LocationPinProvider + // make the pin stay at the center of the map: selected location is the center of the map + // need changes in the event sent when this is a pin drop location? + // need changes in the parsing of events when receiving pin drop location?: should it be shown with user avatar or with pin? views.shareLocationOptionsPicker.optionPinned.debouncedClicks { // TODO } @@ -145,6 +147,24 @@ class LocationSharingFragment @Inject constructor( } } + private fun updateMap(state: LocationSharingViewState) { + // first update the options view + if (state.isUserLocation) { + // TODO activate USER_LIVE option when implemented + views.shareLocationOptionsPicker.render( + LocationSharingOption.USER_CURRENT + ) + } else { + views.shareLocationOptionsPicker.render( + LocationSharingOption.PINNED + ) + } + val mapState = state + .toMapState() + .copy(logoMarginBottom = views.shareLocationOptionsPicker.height) + views.mapView.render(mapState) + } + private fun updateUserAvatar(userItem: MatrixItem.UserItem?) { userItem?.takeUnless { hasRenderedUserAvatar } ?.let { diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewState.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewState.kt index e63206f515..dc18c028f6 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewState.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewState.kt @@ -30,6 +30,7 @@ enum class LocationSharingMode(@StringRes val titleRes: Int) { data class LocationSharingViewState( val roomId: String, val mode: LocationSharingMode, + val isUserLocation: Boolean = false, val userItem: MatrixItem.UserItem? = null, val lastKnownLocation: LocationData? = null, val pinDrawable: Drawable? = null diff --git a/vector/src/main/java/im/vector/app/features/location/MapState.kt b/vector/src/main/java/im/vector/app/features/location/MapState.kt index d001457e4f..f4e2ce7f5b 100644 --- a/vector/src/main/java/im/vector/app/features/location/MapState.kt +++ b/vector/src/main/java/im/vector/app/features/location/MapState.kt @@ -17,10 +17,12 @@ package im.vector.app.features.location import android.graphics.drawable.Drawable +import androidx.annotation.Px data class MapState( val zoomOnlyOnce: Boolean, val pinLocationData: LocationData? = null, val pinId: String, - val pinDrawable: Drawable? = null + val pinDrawable: Drawable? = null, + @Px val logoMarginBottom: Int = 0 ) 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 dd80f701f6..85cbeda805 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 @@ -68,6 +68,8 @@ class MapTilerMapView @JvmOverloads constructor( pendingState = state } + safeMapRefs.map.uiSettings.setLogoMargins(0, 0, 0, state.logoMarginBottom) + state.pinDrawable?.let { pinDrawable -> if (!safeMapRefs.style.isFullyLoaded || safeMapRefs.style.getImage(state.pinId) == null) { diff --git a/vector/src/main/res/layout/fragment_location_sharing.xml b/vector/src/main/res/layout/fragment_location_sharing.xml index 3d07e4438d..f54cefb4ee 100644 --- a/vector/src/main/res/layout/fragment_location_sharing.xml +++ b/vector/src/main/res/layout/fragment_location_sharing.xml @@ -7,10 +7,12 @@