aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-17 15:51:47 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-17 15:51:47 -0600
commit7ab652acd172963b2f36085eb9be6927cb21fc71 (patch)
tree4e826c625fa12315280454bb57db43dde9dde13d /androidApp
parentd91688765774ccb9153a5236edf359a8fa3a0f62 (diff)
downloadetbsa-trackermap-mobile-7ab652acd172963b2f36085eb9be6927cb21fc71.tar.gz
etbsa-trackermap-mobile-7ab652acd172963b2f36085eb9be6927cb21fc71.tar.bz2
etbsa-trackermap-mobile-7ab652acd172963b2f36085eb9be6927cb21fc71.zip
Fixed reports fragment map data display, and added geofences
Diffstat (limited to 'androidApp')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt57
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt14
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt5
3 files changed, 62 insertions, 14 deletions
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 92a94b1..1f1bb15 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
@@ -24,6 +24,7 @@ import mx.trackermap.TrackerMap.android.details.UnitDetailsAdapter
import mx.trackermap.TrackerMap.android.map.MapFragment
import mx.trackermap.TrackerMap.android.shared.MarkerTransformations
import mx.trackermap.TrackerMap.client.models.EventInformation
+import mx.trackermap.TrackerMap.client.models.Geofence
import mx.trackermap.TrackerMap.client.models.Position
import mx.trackermap.TrackerMap.client.models.Stop
import mx.trackermap.TrackerMap.controllers.ReportController
@@ -162,6 +163,10 @@ class UnitReportsFragment : Fragment() {
}
)
}
+
+ unitReportsViewModel.geofences.observe(viewLifecycleOwner) { geofences ->
+ display(geofences)
+ }
}
private fun removeObservers() {
@@ -193,15 +198,22 @@ class UnitReportsFragment : Fragment() {
}
private fun display(positions: Array<Position>) {
- Log.d("UnitReportsFragment", "Displaying positions: $positions")
+ if (reportsMapFragment.hasStarted) {
+ Log.d("UnitReportsFragment", "Displaying positions: $positions")
- binding.eventsScroll.visibility = View.GONE
- binding.reportsMapContainer.visibility = View.VISIBLE
+ binding.eventsScroll.visibility = View.GONE
+ binding.reportsMapContainer.visibility = View.VISIBLE
- reportsMapFragment.display(
- positions.mapNotNull(MarkerTransformations::positionToMarker).toTypedArray(),
- isReport = true
- )
+ reportsMapFragment.display(
+ positions.mapNotNull(MarkerTransformations::positionToMarker).toTypedArray(),
+ isReport = true
+ )
+ } else {
+ reportsMapFragment.setupCallbacks.clear()
+ reportsMapFragment.setupCallbacks.add {
+ display(positions)
+ }
+ }
}
private fun display(events: Array<EventInformation>) {
@@ -271,15 +283,32 @@ class UnitReportsFragment : Fragment() {
}
private fun display(stops: Array<Stop>) {
- Log.d("UnitReportsFragment", "Displaying stops: $stops")
+ if (reportsMapFragment.hasStarted) {
+ Log.d("UnitReportsFragment", "Displaying stops: $stops")
- binding.eventsScroll.visibility = View.GONE
- binding.reportsMapContainer.visibility = View.VISIBLE
+ binding.eventsScroll.visibility = View.GONE
+ binding.reportsMapContainer.visibility = View.VISIBLE
- reportsMapFragment.display(
- stops.mapNotNull(MarkerTransformations::stopToMarker).toTypedArray(),
- isReport = true
- )
+ reportsMapFragment.display(
+ stops.mapNotNull(MarkerTransformations::stopToMarker).toTypedArray(),
+ isReport = true
+ )
+ } else {
+ reportsMapFragment.setupCallbacks.add {
+ display(stops)
+ }
+ }
+ }
+
+ private fun display(geofences: Array<Geofence>) {
+ if (reportsMapFragment.hasStarted) {
+ Log.d("UnitReportsFragment", "Displaying geofences: $geofences")
+ reportsMapFragment.displayGeofences(geofences)
+ } else {
+ reportsMapFragment.setupCallbacks.add {
+ display(geofences)
+ }
+ }
}
private fun loading() {
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
index 0c8a6ac..a957435 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsViewModel.kt
@@ -5,6 +5,8 @@ import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import mx.trackermap.TrackerMap.client.models.EventInformation
+import mx.trackermap.TrackerMap.client.models.Geofence
+import mx.trackermap.TrackerMap.controllers.GeofencesController
import mx.trackermap.TrackerMap.controllers.ReportController
import mx.trackermap.TrackerMap.utils.ReportDates
import org.koin.core.component.KoinComponent
@@ -15,6 +17,7 @@ class UnitReportsViewModel(
savedStateHandle: SavedStateHandle
) : ViewModel(), KoinComponent {
+ private val geofencesController: GeofencesController by inject()
private val reportController: ReportController by inject()
private var _deviceId = savedStateHandle.getLiveData("deviceId", 0)
@@ -22,11 +25,13 @@ class UnitReportsViewModel(
private val _reportPeriod: MutableLiveData<ReportDates.ReportPeriod> =
savedStateHandle.getLiveData("reportPeriod", null)
private val _report: MutableLiveData<ReportController.Report> = MutableLiveData()
+ private val _geofences: MutableLiveData<Array<Geofence>> = MutableLiveData()
val deviceId: LiveData<Int> get() = _deviceId
val reportType: LiveData<ReportController.ReportType> get() = _reportType
val reportPeriod: LiveData<ReportDates.ReportPeriod> get() = _reportPeriod
val report: LiveData<ReportController.Report> get() = _report
+ val geofences: LiveData<Array<Geofence>> get() = _geofences
init {
viewModelScope.launch {
@@ -38,6 +43,9 @@ class UnitReportsViewModel(
viewModelScope.launch {
setupReportObserver()
}
+ viewModelScope.launch {
+ setupGeofenceObserver()
+ }
}
private suspend fun setupTypeObserver() {
@@ -58,6 +66,12 @@ class UnitReportsViewModel(
}
}
+ private suspend fun setupGeofenceObserver() {
+ geofencesController.geofencesFlow.collect {
+ _geofences.value = it.values.toTypedArray()
+ }
+ }
+
fun setDeviceId (id: Int) {
_deviceId.value = id
}
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 cd1778a..1ba8fd6 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
@@ -24,6 +24,7 @@ import mx.trackermap.TrackerMap.client.models.MapLayer
import mx.trackermap.TrackerMap.utils.MapCalculus
import mx.trackermap.TrackerMap.utils.MarkerType
+typealias SetupCallback = () -> Unit
typealias MarkerCallback = (Int?) -> Unit
class MapFragment : GlobeMapFragment() {
@@ -38,6 +39,8 @@ class MapFragment : GlobeMapFragment() {
val type: MarkerType = MarkerType.DEFAULT
)
+ var hasStarted: Boolean = false
+ val setupCallbacks = mutableListOf<SetupCallback>()
var markerCallback: MarkerCallback? = null
private val objects = mutableListOf<ComponentObject>()
@@ -65,6 +68,8 @@ class MapFragment : GlobeMapFragment() {
override fun controlHasStarted() {
Log.d("MapFragment", "controlHasStarted")
+ hasStarted = true
+ setupCallbacks.forEach { it() }
if (tileInfo == null) {
val layer = MapLayer.defaultLayer