diff options
Diffstat (limited to 'androidApp')
3 files changed, 29 insertions, 25 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt index bceb113..2fb94f3 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt @@ -21,13 +21,8 @@ import kotlinx.coroutines.DelicateCoroutinesApi import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitDetailsReportsBinding import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter -import mx.trackermap.TrackerMap.android.map.MapFragment import mx.trackermap.TrackerMap.android.map.MapWrapperFragment -import mx.trackermap.TrackerMap.android.shared.MarkerTransformations import mx.trackermap.TrackerMap.client.models.EventInformation -import mx.trackermap.TrackerMap.client.models.Geofence -import mx.trackermap.TrackerMap.client.models.Position -import mx.trackermap.TrackerMap.client.models.Stop import mx.trackermap.TrackerMap.controllers.ReportController import mx.trackermap.TrackerMap.utils.Formatter import mx.trackermap.TrackerMap.utils.ReportDates @@ -44,7 +39,9 @@ class UnitReportsFragment : Fragment() { private val binding get() = _binding!! private val unitReportsViewModel: UnitReportsViewModel by viewModel() - private lateinit var reportsMapFragment: MapWrapperFragment + private val mapFragment: MapWrapperFragment by lazy { + MapWrapperFragment() + } override fun onCreateView( inflater: LayoutInflater, @@ -61,12 +58,12 @@ class UnitReportsFragment : Fragment() { unitReportsViewModel.setDeviceId( arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) ?: 0) setupEvents() + initializeMap() } override fun onResume() { super.onResume() - initializeMap() setupObservers() } @@ -74,7 +71,6 @@ class UnitReportsFragment : Fragment() { super.onPause() removeObservers() - removeMap() if (unitReportsViewModel.report.value == null) { unitReportsViewModel.fetchReport() @@ -88,16 +84,8 @@ class UnitReportsFragment : Fragment() { private fun initializeMap() { Log.d("UnitReportsFragment", "initializeMap()") - reportsMapFragment = MapWrapperFragment() - childFragmentManager.commit { - replace(R.id.reportsMapContainer, reportsMapFragment) - } - } - - private fun removeMap() { - Log.d("UnitReportsFragment", "removeMap()") childFragmentManager.commit { - remove(reportsMapFragment) + replace(R.id.reportsMapContainer, mapFragment) } } @@ -128,8 +116,8 @@ class UnitReportsFragment : Fragment() { when (report) { is ReportController.Report.PositionsReport -> { - reportsMapFragment.display(report.positions, isReport = true, center = true) - reportsMapFragment.display(unitReportsViewModel.geofences.value!!) + mapFragment.display(unitReportsViewModel.geofences.value!!) + mapFragment.display(report.positions, isReport = true, center = true) showMap(true) } is ReportController.Report.EventsReport -> { @@ -137,8 +125,8 @@ class UnitReportsFragment : Fragment() { showMap(false) } is ReportController.Report.StopsReport -> { - reportsMapFragment.display(report.stops) - reportsMapFragment.display(unitReportsViewModel.geofences.value!!) + mapFragment.display(unitReportsViewModel.geofences.value!!) + mapFragment.display(report.stops) showMap(true) } is ReportController.Report.XlsxReport -> { @@ -168,7 +156,7 @@ class UnitReportsFragment : Fragment() { } unitReportsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> - reportsMapFragment.display(geofences) + mapFragment.display(geofences) } } @@ -272,7 +260,7 @@ class UnitReportsFragment : Fragment() { binding.reportsMapContainer.visibility = View.GONE childFragmentManager.commit { - hide(reportsMapFragment) + hide(mapFragment) } } @@ -284,9 +272,9 @@ class UnitReportsFragment : Fragment() { childFragmentManager.commit { if (shouldShowMap) { - show(reportsMapFragment) + show(mapFragment) } else { - hide(reportsMapFragment) + hide(mapFragment) } } } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt index 8f9af3f..2b28a06 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt @@ -55,6 +55,15 @@ class MapWrapperFragment: Fragment() { val layer = MapLayer.defaultLayer binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0) + + if (mapFragment.hasStarted) { + binding.mapLoading.root.visibility = View.GONE + } else { + binding.mapLoading.root.visibility = View.VISIBLE + mapFragment.setupCallbacks.add { + binding.mapLoading.root.visibility = View.GONE + } + } } private fun removeMap() { diff --git a/androidApp/src/main/res/layout/fragment_map_wrapper.xml b/androidApp/src/main/res/layout/fragment_map_wrapper.xml index f63f74e..949cc10 100644 --- a/androidApp/src/main/res/layout/fragment_map_wrapper.xml +++ b/androidApp/src/main/res/layout/fragment_map_wrapper.xml @@ -82,4 +82,11 @@ </androidx.constraintlayout.widget.ConstraintLayout> + <include + android:id="@+id/mapLoading" + layout="@layout/loading_indicator" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:visibility="gone"/> + </FrameLayout>
\ No newline at end of file |