Moving setup of map in onViewCreated + moving reference assignment of MapView

This commit is contained in:
Maxime NATUREL 2022-08-03 17:14:21 +02:00
parent 2b8632ebe7
commit 65c6e578eb

View File

@ -86,6 +86,7 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
observeViewEvents()
setupMap()
views.liveLocationBottomSheetRecyclerView.configureWith(bottomSheetController, hasFixedSize = false, disableItemAnimation = true)
@ -119,15 +120,13 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
super.onDestroyView()
}
override fun onResume() {
super.onResume()
setupMap()
}
private fun setupMap() {
val mapFragment = getOrCreateSupportMapFragment()
mapFragment.getMapAsync { mapboxMap ->
(mapFragment.view as? MapView)?.let(::listenMapLoadingError)
(mapFragment.view as? MapView)?.let {
mapView = it
listenMapLoadingError(it)
}
lifecycleScope.launch {
mapboxMap.setStyle(urlMapProvider.getMapUrl()) { style ->
mapStyle = style
@ -148,7 +147,6 @@ class LiveLocationMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
}
private fun listenMapLoadingError(mapView: MapView) {
this.mapView = mapView
mapLoadingErrorListener = MapView.OnDidFailLoadingMapListener {
viewModel.handle(LiveLocationMapAction.ShowMapLoadingError)
}.also { mapView.addOnDidFailLoadingMapListener(it) }