From 5472556161c2f781e7a0dabe48301f3b665641b1 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 18 Jan 2022 11:17:44 -0600 Subject: Show and hide fragments instead of replacing, so transition between map and list views is a lot faster --- .../trackermap/TrackerMap/android/units/UnitsActivity.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'androidApp/src') diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt index 9fcef7f..58147e4 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt @@ -66,6 +66,10 @@ class UnitsActivity : AppCompatActivity() { } private fun setupViews() { + supportFragmentManager.commit { + add(R.id.displayContainer, mapFragment) + add(R.id.displayContainer, devicesFragment) + } TooltipCompat.setTooltipText(binding.userButton, getString(R.string.open_profile)) TooltipCompat.setTooltipText(binding.mapLayerToggle, getString(R.string.switch_layer)) } @@ -148,9 +152,15 @@ class UnitsActivity : AppCompatActivity() { UnitsViewModel.UnitsDisplayMode.MAP -> mapFragment else -> mapFragment } + val oldFragment = + when (displayMode) { + UnitsViewModel.UnitsDisplayMode.LIST -> mapFragment + UnitsViewModel.UnitsDisplayMode.MAP -> devicesFragment + else -> devicesFragment + } supportFragmentManager.commit { - replace(R.id.displayContainer, newFragment) - setTransition(TRANSIT_FRAGMENT_FADE) + show(newFragment) + hide(oldFragment) } } unitsViewModel.selectedUnit.observe(this) { -- cgit v1.2.3