aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
authorIsidro Henoch <imhenoch@protonmail.com>2022-01-17 15:21:45 -0600
committerIsidro Henoch <imhenoch@protonmail.com>2022-01-17 15:21:45 -0600
commitd91688765774ccb9153a5236edf359a8fa3a0f62 (patch)
tree5dda71a3762659f223a14e93cc51dd0e27d5a60a /androidApp
parent76747c473656ecc4f63f28212326f90dc1e53643 (diff)
downloadetbsa-trackermap-mobile-d91688765774ccb9153a5236edf359a8fa3a0f62.tar.gz
etbsa-trackermap-mobile-d91688765774ccb9153a5236edf359a8fa3a0f62.tar.bz2
etbsa-trackermap-mobile-d91688765774ccb9153a5236edf359a8fa3a0f62.zip
Tries to fix the report map issues
Diffstat (limited to 'androidApp')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt26
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt6
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt4
3 files changed, 29 insertions, 7 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 600cfe1..92a94b1 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
@@ -42,9 +42,7 @@ class UnitReportsFragment : Fragment() {
private val binding get() = _binding!!
private val unitReportsViewModel: UnitReportsViewModel by viewModel()
- private val reportsMapFragment: MapFragment by lazy {
- MapFragment()
- }
+ private lateinit var reportsMapFragment: MapFragment
override fun onCreateView(
inflater: LayoutInflater,
@@ -61,19 +59,24 @@ class UnitReportsFragment : Fragment() {
unitReportsViewModel.setDeviceId(
arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) ?: 0)
setupEvents()
- initializeMap()
}
override fun onResume() {
super.onResume()
+ initializeMap()
setupObservers()
}
- override fun onStop() {
- super.onStop()
+ override fun onPause() {
+ super.onPause()
removeObservers()
+ removeMap()
+
+ if (unitReportsViewModel.report.value == null) {
+ unitReportsViewModel.fetchReport()
+ }
}
override fun onDestroyView() {
@@ -83,11 +86,19 @@ class UnitReportsFragment : Fragment() {
private fun initializeMap() {
Log.d("UnitReportsFragment", "initializeMap()")
+ reportsMapFragment = MapFragment()
childFragmentManager.commit {
replace(R.id.reportsMapContainer, reportsMapFragment)
}
}
+ private fun removeMap() {
+ Log.d("UnitReportsFragment", "removeMap()")
+ childFragmentManager.commit {
+ remove(reportsMapFragment)
+ }
+ }
+
private fun setupEvents() {
binding.reportType.setOnPositionChangedListener { position ->
unitReportsViewModel.setReportType(
@@ -109,6 +120,7 @@ class UnitReportsFragment : Fragment() {
}
private fun setupObservers() {
+ Log.d("UnitReportsFragment", "Adding observers")
unitReportsViewModel.report.observe(viewLifecycleOwner) { report ->
Log.d("UnitReportsFragment", "Report available: $report")
@@ -153,8 +165,10 @@ class UnitReportsFragment : Fragment() {
}
private fun removeObservers() {
+ Log.d("UnitReportsFragment", "Removing observers")
unitReportsViewModel.report.removeObservers(viewLifecycleOwner)
unitReportsViewModel.reportPeriod.removeObservers(viewLifecycleOwner)
+ unitReportsViewModel.clearReport()
}
private fun showPeriodPopUp(view: View) {
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
index 7749b54..0c8a6ac 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
@@ -74,7 +74,11 @@ class UnitReportsViewModel(
fetchReport(true)
}
- private fun fetchReport(xlsx: Boolean = false) {
+ fun clearReport() {
+ _report.value = null
+ }
+
+ fun fetchReport(xlsx: Boolean = false) {
if (_reportType.value == null || _reportPeriod.value == null) {
return
}
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
index 17fc9d4..cd1778a 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
@@ -127,6 +127,10 @@ class MapFragment : GlobeMapFragment() {
}
private fun clear(geofences: Boolean = false) {
+ if (mapControl == null) {
+ return
+ }
+
if (geofences) {
mapControl.removeObjects(
geofenceObjects,