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
1 changed files with 5 additions and 7 deletions

View File

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