Show options menu on top of the map

This commit is contained in:
Maxime Naturel 2022-03-04 09:16:12 +01:00
parent db0cfd4704
commit 9256b5671b
5 changed files with 34 additions and 7 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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
)

View File

@ -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) {

View File

@ -7,10 +7,12 @@
<im.vector.app.features.location.MapTilerMapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/shareLocationOptionsPicker"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:mapbox_renderTextureMode="true"
tools:background="#4F00" />