aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-17 22:03:48 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-17 22:03:48 -0600
commitaae38258ff929157ff35547e353265da01c80f9c (patch)
tree7677c64eebc6240c0675e2bbc3bb43727deb1286 /androidApp/src/main/java
parentc3c57a26e62857434830c9b22bb4757edda2b202 (diff)
downloadetbsa-trackermap-mobile-aae38258ff929157ff35547e353265da01c80f9c.tar.gz
etbsa-trackermap-mobile-aae38258ff929157ff35547e353265da01c80f9c.tar.bz2
etbsa-trackermap-mobile-aae38258ff929157ff35547e353265da01c80f9c.zip
Fixed zooming selected unit and refactored attribution into wrap
Diffstat (limited to 'androidApp/src/main/java')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt5
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt32
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt9
3 files changed, 31 insertions, 15 deletions
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<Position>, 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<UnitInformation>, 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<Stop>) {
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<Geofence>) {
- 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 ->