From 008e07d03efb3c5989fc7f2c89cc2c3af0b4b03f Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 1 Aug 2022 16:05:42 +0200 Subject: [PATCH] Handling map loading error in live location maximized map --- .../live/map/LiveLocationMapAction.kt | 1 + .../live/map/LiveLocationMapViewFragment.kt | 24 ++++++++++++++++++- .../live/map/LiveLocationMapViewModel.kt | 5 ++++ .../live/map/LiveLocationMapViewState.kt | 3 ++- .../fragment_live_location_map_view.xml | 7 ++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapAction.kt b/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapAction.kt index 2a07934146..295d6b5d41 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapAction.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapAction.kt @@ -22,4 +22,5 @@ sealed class LiveLocationMapAction : VectorViewModelAction { data class AddMapSymbol(val key: String, val value: Long) : LiveLocationMapAction() data class RemoveMapSymbol(val key: String) : LiveLocationMapAction() object StopSharing : LiveLocationMapAction() + object ShowMapLoadingError : LiveLocationMapAction() } diff --git a/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewFragment.kt b/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewFragment.kt index 283774dbc6..9eab20742f 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewFragment.kt @@ -71,11 +71,13 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment? = null + private var mapView: MapView? = null private var symbolManager: SymbolManager? = null private var mapStyle: Style? = null private val pendingLiveLocations = mutableListOf() private var isMapFirstUpdate = true private var onSymbolClickListener: OnSymbolClickListener? = null + private var mapLoadingErrorListener: MapView.OnDidFailLoadingMapListener? = null override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLiveLocationMapViewBinding { return FragmentLiveLocationMapViewBinding.inflate(layoutInflater, container, false) @@ -106,6 +108,13 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment + (mapFragment.view as? MapView)?.let(::listenMapLoadingError) lifecycleScope.launch { mapboxMap.setStyle(urlMapProvider.getMapUrl()) { style -> mapStyle = style @@ -141,6 +151,13 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment - updateMap(viewState.userLocations) + if(viewState.loadingMapHasFailed) { + views.mapPreviewLoadingError.isVisible = true + } else { + views.mapPreviewLoadingError.isGone = true + updateMap(viewState.userLocations) + } updateUserListBottomSheet(viewState.userLocations) } diff --git a/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewModel.kt b/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewModel.kt index 280789e4c6..33c584ff85 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewModel.kt @@ -61,6 +61,7 @@ class LiveLocationMapViewModel @AssistedInject constructor( is LiveLocationMapAction.AddMapSymbol -> handleAddMapSymbol(action) is LiveLocationMapAction.RemoveMapSymbol -> handleRemoveMapSymbol(action) LiveLocationMapAction.StopSharing -> handleStopSharing() + LiveLocationMapAction.ShowMapLoadingError -> handleShowMapLoadingError() } } @@ -87,6 +88,10 @@ class LiveLocationMapViewModel @AssistedInject constructor( } } + private fun handleShowMapLoadingError() { + setState { copy(loadingMapHasFailed = true) } + } + override fun onLocationServiceRunning(roomIds: Set) { // NOOP } diff --git a/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewState.kt b/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewState.kt index 615b4381e2..459e2797d0 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewState.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationMapViewState.kt @@ -27,7 +27,8 @@ data class LiveLocationMapViewState( /** * Map to keep track of symbol ids associated to each user Id. */ - val mapSymbolIds: Map = emptyMap() + val mapSymbolIds: Map = emptyMap(), + val loadingMapHasFailed: Boolean = false ) : MavericksState { constructor(liveLocationMapViewArgs: LiveLocationMapViewArgs) : this( roomId = liveLocationMapViewArgs.roomId diff --git a/vector/src/main/res/layout/fragment_live_location_map_view.xml b/vector/src/main/res/layout/fragment_live_location_map_view.xml index 81db466dab..369404ddbd 100644 --- a/vector/src/main/res/layout/fragment_live_location_map_view.xml +++ b/vector/src/main/res/layout/fragment_live_location_map_view.xml @@ -17,6 +17,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> + +