aboutsummaryrefslogtreecommitdiff
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
commit059b32bbf408d65bb1b4b54bf84961bff6b4a02c (patch)
tree5dda71a3762659f223a14e93cc51dd0e27d5a60a
parent58ac7a17e76016fd2a257605c47cf5705f90c6e1 (diff)
downloadetbsa-trackermap-mobile-059b32bbf408d65bb1b4b54bf84961bff6b4a02c.tar.gz
etbsa-trackermap-mobile-059b32bbf408d65bb1b4b54bf84961bff6b4a02c.tar.bz2
etbsa-trackermap-mobile-059b32bbf408d65bb1b4b54bf84961bff6b4a02c.zip
Tries to fix the report map issues
-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,