Handling map loading error in live location maximized map
This commit is contained in:
parent
a30076a2ab
commit
008e07d03e
@ -22,4 +22,5 @@ sealed class LiveLocationMapAction : VectorViewModelAction {
|
|||||||
data class AddMapSymbol(val key: String, val value: Long) : LiveLocationMapAction()
|
data class AddMapSymbol(val key: String, val value: Long) : LiveLocationMapAction()
|
||||||
data class RemoveMapSymbol(val key: String) : LiveLocationMapAction()
|
data class RemoveMapSymbol(val key: String) : LiveLocationMapAction()
|
||||||
object StopSharing : LiveLocationMapAction()
|
object StopSharing : LiveLocationMapAction()
|
||||||
|
object ShowMapLoadingError : LiveLocationMapAction()
|
||||||
}
|
}
|
||||||
|
@ -71,11 +71,13 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
|
|||||||
private val viewModel: LiveLocationMapViewModel by fragmentViewModel()
|
private val viewModel: LiveLocationMapViewModel by fragmentViewModel()
|
||||||
|
|
||||||
private var mapboxMap: WeakReference<MapboxMap>? = null
|
private var mapboxMap: WeakReference<MapboxMap>? = null
|
||||||
|
private var mapView: MapView? = null
|
||||||
private var symbolManager: SymbolManager? = null
|
private var symbolManager: SymbolManager? = null
|
||||||
private var mapStyle: Style? = null
|
private var mapStyle: Style? = null
|
||||||
private val pendingLiveLocations = mutableListOf<UserLiveLocationViewState>()
|
private val pendingLiveLocations = mutableListOf<UserLiveLocationViewState>()
|
||||||
private var isMapFirstUpdate = true
|
private var isMapFirstUpdate = true
|
||||||
private var onSymbolClickListener: OnSymbolClickListener? = null
|
private var onSymbolClickListener: OnSymbolClickListener? = null
|
||||||
|
private var mapLoadingErrorListener: MapView.OnDidFailLoadingMapListener? = null
|
||||||
|
|
||||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLiveLocationMapViewBinding {
|
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentLiveLocationMapViewBinding {
|
||||||
return FragmentLiveLocationMapViewBinding.inflate(layoutInflater, container, false)
|
return FragmentLiveLocationMapViewBinding.inflate(layoutInflater, container, false)
|
||||||
@ -106,6 +108,13 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
mapLoadingErrorListener?.let { mapView?.removeOnDidFailLoadingMapListener(it) }
|
||||||
|
mapLoadingErrorListener = null
|
||||||
|
mapView = null
|
||||||
|
super.onDestroyView()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
setupMap()
|
setupMap()
|
||||||
@ -122,6 +131,7 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
|
|||||||
private fun setupMap() {
|
private fun setupMap() {
|
||||||
val mapFragment = getOrCreateSupportMapFragment()
|
val mapFragment = getOrCreateSupportMapFragment()
|
||||||
mapFragment.getMapAsync { mapboxMap ->
|
mapFragment.getMapAsync { mapboxMap ->
|
||||||
|
(mapFragment.view as? MapView)?.let(::listenMapLoadingError)
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
mapboxMap.setStyle(urlMapProvider.getMapUrl()) { style ->
|
mapboxMap.setStyle(urlMapProvider.getMapUrl()) { style ->
|
||||||
mapStyle = style
|
mapStyle = style
|
||||||
@ -141,6 +151,13 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun listenMapLoadingError(mapView: MapView) {
|
||||||
|
this.mapView = mapView
|
||||||
|
mapLoadingErrorListener = MapView.OnDidFailLoadingMapListener {
|
||||||
|
viewModel.handle(LocationLiveMapAction.ShowMapLoadingError)
|
||||||
|
}.also { mapView.addOnDidFailLoadingMapListener(it) }
|
||||||
|
}
|
||||||
|
|
||||||
private fun onSymbolClicked(symbol: Symbol?) {
|
private fun onSymbolClicked(symbol: Symbol?) {
|
||||||
symbol?.let {
|
symbol?.let {
|
||||||
mapboxMap
|
mapboxMap
|
||||||
@ -173,7 +190,12 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidate() = withState(viewModel) { viewState ->
|
override fun invalidate() = withState(viewModel) { viewState ->
|
||||||
|
if(viewState.loadingMapHasFailed) {
|
||||||
|
views.mapPreviewLoadingError.isVisible = true
|
||||||
|
} else {
|
||||||
|
views.mapPreviewLoadingError.isGone = true
|
||||||
updateMap(viewState.userLocations)
|
updateMap(viewState.userLocations)
|
||||||
|
}
|
||||||
updateUserListBottomSheet(viewState.userLocations)
|
updateUserListBottomSheet(viewState.userLocations)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ class LiveLocationMapViewModel @AssistedInject constructor(
|
|||||||
is LiveLocationMapAction.AddMapSymbol -> handleAddMapSymbol(action)
|
is LiveLocationMapAction.AddMapSymbol -> handleAddMapSymbol(action)
|
||||||
is LiveLocationMapAction.RemoveMapSymbol -> handleRemoveMapSymbol(action)
|
is LiveLocationMapAction.RemoveMapSymbol -> handleRemoveMapSymbol(action)
|
||||||
LiveLocationMapAction.StopSharing -> handleStopSharing()
|
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<String>) {
|
override fun onLocationServiceRunning(roomIds: Set<String>) {
|
||||||
// NOOP
|
// NOOP
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ data class LiveLocationMapViewState(
|
|||||||
/**
|
/**
|
||||||
* Map to keep track of symbol ids associated to each user Id.
|
* Map to keep track of symbol ids associated to each user Id.
|
||||||
*/
|
*/
|
||||||
val mapSymbolIds: Map<String, Long> = emptyMap()
|
val mapSymbolIds: Map<String, Long> = emptyMap(),
|
||||||
|
val loadingMapHasFailed: Boolean = false
|
||||||
) : MavericksState {
|
) : MavericksState {
|
||||||
constructor(liveLocationMapViewArgs: LiveLocationMapViewArgs) : this(
|
constructor(liveLocationMapViewArgs: LiveLocationMapViewArgs) : this(
|
||||||
roomId = liveLocationMapViewArgs.roomId
|
roomId = liveLocationMapViewArgs.roomId
|
||||||
|
@ -17,6 +17,13 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<im.vector.app.features.location.MapLoadingErrorView
|
||||||
|
android:id="@+id/mapPreviewLoadingError"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginBottom="180dp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/bottomSheet"
|
android:id="@+id/bottomSheet"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user