aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp')
-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
-rw-r--r--androidApp/src/main/res/layout/fragment_map_wrapper.xml20
-rw-r--r--androidApp/src/main/res/layout/unit_map_fragment.xml20
5 files changed, 51 insertions, 35 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 ->
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" />
+ <!-- Attribution -->
+ <FrameLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:background="@color/colorAttributionBackground"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent">
+
+ <TextView
+ android:id="@+id/attributionText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ tools:text="Copyright (C) OpenStreetMap"
+ android:textSize="@dimen/attribution_text_size"
+ android:textColor="@color/colorAttributionText"
+ android:layout_margin="6dp" />
+
+ </FrameLayout>
+
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> \ 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 @@
</androidx.cardview.widget.CardView>
- <!-- Attribution -->
- <FrameLayout
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:background="@color/colorAttributionBackground"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintBottom_toBottomOf="parent">
-
- <TextView
- android:id="@+id/attributionText"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- tools:text="Copyright (C) OpenStreetMap"
- android:textSize="@dimen/attribution_text_size"
- android:textColor="@color/colorAttributionText"
- android:layout_margin="6dp" />
-
- </FrameLayout>
-
</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file