diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-17 04:10:08 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-17 04:10:08 -0600 |
commit | 5d49e5e3ba5c9765a9cddd2d9a6c8867d8d7c2dd (patch) | |
tree | 9acdefcf7233f914216468ecd96f314a30308f65 /androidApp/src/main/java/mx/trackermap/TrackerMap/android | |
parent | 021e0618575d549d896d65948b2a66e4c56d65de (diff) | |
parent | 540c124865ab5eb582ac7a4430ca9af01c19e273 (diff) | |
download | etbsa-trackermap-mobile-5d49e5e3ba5c9765a9cddd2d9a6c8867d8d7c2dd.tar.gz etbsa-trackermap-mobile-5d49e5e3ba5c9765a9cddd2d9a6c8867d8d7c2dd.tar.bz2 etbsa-trackermap-mobile-5d49e5e3ba5c9765a9cddd2d9a6c8867d8d7c2dd.zip |
Merge branch 'main' of https://git.sr.ht/~avalos/trackermap-mobile
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android')
3 files changed, 51 insertions, 3 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt index cd8d7af..9d12608 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/commands/UnitCommandsFragment.kt @@ -42,10 +42,21 @@ class UnitCommandsFragment: Fragment() { super.onViewCreated(view, savedInstanceState) binding.reportLoading.root.visibility = View.VISIBLE - setupObservers() setupEvents() } + override fun onResume() { + super.onResume() + + setupObservers() + } + + override fun onStop() { + super.onStop() + + removeObservers() + } + override fun onDestroyView() { super.onDestroyView() _binding = null @@ -86,6 +97,10 @@ class UnitCommandsFragment: Fragment() { unitCommandsViewModel.fetchCommands(id) } + private fun removeObservers() { + unitCommandsViewModel.commands.removeObservers(viewLifecycleOwner) + } + private fun setupEvents() { binding.commandsList.setOnItemClickListener { _, _, index, _ -> Log.d("UnitCommandsFragment", "Selected item at index - $index") diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt index ab94547..f046ccc 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/information/UnitInformationFragment.kt @@ -47,10 +47,21 @@ class UnitInformationFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - setupObservers() fetchInformation() } + override fun onResume() { + super.onResume() + + setupObservers() + } + + override fun onStop() { + super.onStop() + + removeObservers() + } + override fun onDestroyView() { super.onDestroyView() _binding = null @@ -66,6 +77,10 @@ class UnitInformationFragment : Fragment() { } } + private fun removeObservers() { + unitInformationViewModel.unit.removeObservers(viewLifecycleOwner) + } + private fun fetchInformation() { val id = arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) val name = arguments?.getString(UnitDetailsAdapter.DEVICE_NAME_ARG) 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 d3e008f..600cfe1 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 @@ -60,17 +60,29 @@ class UnitReportsFragment : Fragment() { unitReportsViewModel.setDeviceId( arguments?.getInt(UnitDetailsAdapter.DEVICE_ID_ARG) ?: 0) - initializeMap() setupEvents() + initializeMap() + } + + override fun onResume() { + super.onResume() + setupObservers() } + override fun onStop() { + super.onStop() + + removeObservers() + } + override fun onDestroyView() { super.onDestroyView() _binding = null } private fun initializeMap() { + Log.d("UnitReportsFragment", "initializeMap()") childFragmentManager.commit { replace(R.id.reportsMapContainer, reportsMapFragment) } @@ -140,6 +152,11 @@ class UnitReportsFragment : Fragment() { } } + private fun removeObservers() { + unitReportsViewModel.report.removeObservers(viewLifecycleOwner) + unitReportsViewModel.reportPeriod.removeObservers(viewLifecycleOwner) + } + private fun showPeriodPopUp(view: View) { val popOver = PopupMenu(context, view) popOver.menuInflater.inflate(R.menu.report_period_options, popOver.menu) @@ -262,6 +279,7 @@ class UnitReportsFragment : Fragment() { } private fun showMap(shouldShowMap: Boolean) { + Log.d("UnitReportsFragment", "showMap($shouldShowMap)") binding.reportLoading.root.visibility = View.GONE binding.eventsScroll.visibility = if (shouldShowMap) View.GONE else View.VISIBLE binding.reportsMapContainer.visibility = if (shouldShowMap) View.VISIBLE else View.GONE |