From aae38258ff929157ff35547e353265da01c80f9c Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 17 Jan 2022 22:03:48 -0600 Subject: Fixed zooming selected unit and refactored attribution into wrap --- .../TrackerMap/android/map/MapFragment.kt | 5 ++-- .../TrackerMap/android/map/MapWrapperFragment.kt | 32 ++++++++++++++++++---- .../TrackerMap/android/map/UnitMapFragment.kt | 9 ++---- .../src/main/res/layout/fragment_map_wrapper.xml | 20 ++++++++++++++ .../src/main/res/layout/unit_map_fragment.xml | 20 -------------- 5 files changed, 51 insertions(+), 35 deletions(-) (limited to 'androidApp/src') 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 5304f8e..2c47677 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 @@ -68,8 +68,6 @@ open class MapFragment : GlobeMapFragment() { override fun controlHasStarted() { Log.d("MapFragment", "controlHasStarted") - hasStarted = true - setupCallbacks.forEach { it() } if (tileInfo == null) { val layer = MapLayer.defaultLayer @@ -96,6 +94,9 @@ open class MapFragment : GlobeMapFragment() { val latitude = 23.191 * Math.PI / 180 val longitude = -100.36 * Math.PI / 180 mapControl.setPositionGeo(longitude, latitude, 0.4) + + hasStarted = true + setupCallbacks.forEach { it() } } override fun onStop() { 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 51b0118..8f9af3f 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 @@ -5,6 +5,7 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.text.HtmlCompat import androidx.fragment.app.Fragment import androidx.fragment.app.commit import mx.trackermap.TrackerMap.android.R @@ -51,10 +52,13 @@ class MapWrapperFragment: Fragment() { childFragmentManager.commit { replace(R.id.mapContainer, mapFragment) } + + val layer = MapLayer.defaultLayer + binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0) } private fun removeMap() { - Log.d("UnitReportsFragment", "removeMap()") + Log.d("MapWrapperFragment", "removeMap()") childFragmentManager.commit { remove(mapFragment) } @@ -96,6 +100,7 @@ class MapWrapperFragment: Fragment() { height: Double = 0.00001, animated: Boolean = true ) { + Log.d("MapWrapperFragment", "Focusing on $latitude, $longitude") if (mapFragment.hasStarted) { mapFragment.focusOn(latitude, longitude, height, animated) } else { @@ -107,7 +112,7 @@ class MapWrapperFragment: Fragment() { fun display(positions: Array, isReport: Boolean, center: Boolean) { if (mapFragment.hasStarted) { - Log.d("UnitReportsFragment", "Displaying positions: $positions") + Log.d("MapWrapperFragment", "Displaying positions: $positions") mapFragment.display( positions.mapNotNull(MarkerTransformations::positionToMarker).toTypedArray(), @@ -115,16 +120,31 @@ class MapWrapperFragment: Fragment() { center = center ) } else { - mapFragment.setupCallbacks.clear() mapFragment.setupCallbacks.add { display(positions, isReport, center) } } } + fun display(units: Array, isReport: Boolean, center: Boolean) { + if (mapFragment.hasStarted) { + Log.d("MapWrapperFragment", "Displaying units: $units") + + mapFragment.display( + units.mapNotNull(MarkerTransformations::unitToMarker).toTypedArray(), + isReport = isReport, + center = center + ) + } else { + mapFragment.setupCallbacks.add { + display(units, isReport, center) + } + } + } + fun display(stops: Array) { if (mapFragment.hasStarted) { - Log.d("UnitReportsFragment", "Displaying stops: $stops") + Log.d("MapWrapperFragment", "Displaying stops: $stops") mapFragment.display( stops.mapNotNull(MarkerTransformations::stopToMarker).toTypedArray(), @@ -138,9 +158,8 @@ class MapWrapperFragment: Fragment() { } fun display(geofences: Array) { - Log.d("UnitReportsFragment", "Geofences: $geofences") if (mapFragment.hasStarted) { - Log.d("UnitReportsFragment", "Displaying geofences: $geofences") + Log.d("MapWrapperFragment", "Displaying geofences: $geofences") mapFragment.displayGeofences(geofences) } else { mapFragment.setupCallbacks.add { @@ -152,6 +171,7 @@ class MapWrapperFragment: Fragment() { fun updateLayer(layer: MapLayer.Type) { if (mapFragment.hasStarted) { mapFragment.updateLayer(layer) + binding.attributionText.text = MapLayer.layers[layer]?.attribution } else { mapFragment.setupCallbacks.add { updateLayer(layer) diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt index b67bca8..1a39ab1 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt @@ -61,13 +61,10 @@ class UnitMapFragment : Fragment() { } private fun initializeMap() { - shouldCenter = true + shouldCenter = shouldCenter && unitsViewModel.selectedUnit.value == null mapFragment = childFragmentManager.findFragmentById(R.id.unitsMap) as MapWrapperFragment mapFragment.setMarkerCallback(unitsViewModel::selectUnitWith) mapFragment.setOverlayPaddingTop(resources.getDimensionPixelSize(R.dimen.nav_height)) - - val layer = MapLayer.defaultLayer - binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0) } private fun setupObservers() { @@ -76,7 +73,7 @@ class UnitMapFragment : Fragment() { unitsViewModel.units.observe(viewLifecycleOwner) { units -> Log.d("UnitMapFragment", "Available units: $units") mapFragment.display( - units.mapNotNull { it.position }.toTypedArray(), + units.toTypedArray(), isReport = false, center = shouldCenter ) @@ -117,8 +114,6 @@ class UnitMapFragment : Fragment() { unitsViewModel.selectedUnit.value?.let { mapFragment.focusOn(it.position!!.latitude!!, it.position!!.longitude!!) } - val layer = MapLayer.layers[type]!! - binding.attributionText.text = HtmlCompat.fromHtml(layer.attribution, 0) } unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> diff --git a/androidApp/src/main/res/layout/fragment_map_wrapper.xml b/androidApp/src/main/res/layout/fragment_map_wrapper.xml index 479c855..f63f74e 100644 --- a/androidApp/src/main/res/layout/fragment_map_wrapper.xml +++ b/androidApp/src/main/res/layout/fragment_map_wrapper.xml @@ -60,6 +60,26 @@ app:layout_constraintTop_toBottomOf="@id/zoomOutButton" android:visibility="gone" /> + + + + + + + \ No newline at end of file diff --git a/androidApp/src/main/res/layout/unit_map_fragment.xml b/androidApp/src/main/res/layout/unit_map_fragment.xml index 9eb92de..da91e8c 100644 --- a/androidApp/src/main/res/layout/unit_map_fragment.xml +++ b/androidApp/src/main/res/layout/unit_map_fragment.xml @@ -143,24 +143,4 @@ - - - - - - - \ No newline at end of file -- cgit v1.2.3