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 4c2be8694f..b721adb93f 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 @@ -146,6 +146,7 @@ class LocationSharingViewModel @AssistedInject constructor( } override fun onLocationUpdate(locationData: LocationData) { + // TODO compare location with lastTargetLocation => need to save info into the ViewState setState { copy(lastKnownUserLocation = locationData) } 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 317bc5a721..e661ff0cc0 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 @@ -46,5 +46,6 @@ fun LocationSharingViewState.toMapState() = MapState( zoomOnlyOnce = true, userLocationData = lastKnownUserLocation, pinId = DEFAULT_PIN_ID, - pinDrawable = locationTargetDrawable + pinDrawable = null, + showPin = areTargetAndUserLocationEqual == false ) 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 fb6bac3ffe..c4325291a8 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 @@ -24,5 +24,6 @@ data class MapState( val userLocationData: LocationData? = null, val pinId: String, val pinDrawable: Drawable? = null, + val showPin: Boolean = true, @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 f8762d4670..903b88423a 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 @@ -18,6 +18,7 @@ package im.vector.app.features.location import android.content.Context import android.util.AttributeSet +import androidx.core.content.ContextCompat import com.mapbox.mapboxsdk.camera.CameraPosition import com.mapbox.mapboxsdk.geometry.LatLng import com.mapbox.mapboxsdk.maps.MapView @@ -26,6 +27,7 @@ import com.mapbox.mapboxsdk.maps.Style import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions import com.mapbox.mapboxsdk.style.layers.Property +import im.vector.app.R import timber.log.Timber class MapTilerMapView @JvmOverloads constructor( @@ -42,6 +44,9 @@ class MapTilerMapView @JvmOverloads constructor( val style: Style ) + private val userLocationDrawable by lazy { + ContextCompat.getDrawable(context, R.drawable.ic_location_user) + } private var mapRefs: MapRefs? = null private var initZoomDone = false @@ -88,13 +93,13 @@ class MapTilerMapView @JvmOverloads constructor( safeMapRefs.map.uiSettings.setLogoMargins(0, 0, 0, state.logoMarginBottom) - // TODO display a dot pin for userLocation instead of pinDrawable // TODO add reset to user location button // TODO check conflict of rendering with preview location in timeline - state.pinDrawable?.let { pinDrawable -> + val pinDrawable = state.pinDrawable ?: userLocationDrawable + pinDrawable?.let { drawable -> if (!safeMapRefs.style.isFullyLoaded || safeMapRefs.style.getImage(state.pinId) == null) { - safeMapRefs.style.addImage(state.pinId, pinDrawable) + safeMapRefs.style.addImage(state.pinId, drawable) } } @@ -105,12 +110,14 @@ class MapTilerMapView @JvmOverloads constructor( } safeMapRefs.symbolManager.deleteAll() - safeMapRefs.symbolManager.create( - SymbolOptions() - .withLatLng(LatLng(locationData.latitude, locationData.longitude)) - .withIconImage(state.pinId) - .withIconAnchor(Property.ICON_ANCHOR_BOTTOM) - ) + if(pinDrawable != null && state.showPin) { + safeMapRefs.symbolManager.create( + SymbolOptions() + .withLatLng(LatLng(locationData.latitude, locationData.longitude)) + .withIconImage(state.pinId) + .withIconAnchor(Property.ICON_ANCHOR_BOTTOM) + ) + } } } diff --git a/vector/src/main/res/drawable/ic_location_user.xml b/vector/src/main/res/drawable/ic_location_user.xml new file mode 100644 index 0000000000..dc6baca65e --- /dev/null +++ b/vector/src/main/res/drawable/ic_location_user.xml @@ -0,0 +1,14 @@ + + + + + + + + + +