From 8878254a4a3af9d15262fd2553c7b2db0a7bd8bc Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 11 Jan 2022 04:12:45 -0600 Subject: Implemented polygon geofences --- .../trackermap/TrackerMap/android/units/UnitsViewModel.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/units') diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt index ca05736..c0dc7c6 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt @@ -5,7 +5,9 @@ import androidx.lifecycle.* import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch +import mx.trackermap.TrackerMap.client.models.Geofence import mx.trackermap.TrackerMap.client.models.UnitInformation +import mx.trackermap.TrackerMap.controllers.GeofencesController import mx.trackermap.TrackerMap.controllers.UnitsController import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -20,22 +22,28 @@ class UnitsViewModel( } private val unitsController: UnitsController by inject() + private val geofenceController: GeofencesController by inject() private var _searchQuery = savedStateHandle.getLiveData("searchQuery", "") private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.LIST) private var _units = MutableLiveData>() private var _selectedUnit = MutableLiveData() + private var _geofences = MutableLiveData>() val searchQuery: LiveData get() = _searchQuery val unitsDisplayMode: LiveData get() = _unitsDisplayMode val units: LiveData> get() = _units val selectedUnit: LiveData get() = _selectedUnit + val geofences: LiveData> get() = _geofences init { Log.d("UnitsViewModel", "Initializing Units View Model") viewModelScope.launch { setupObservers() } + viewModelScope.launch { + setupGeofenceObserver() + } } private suspend fun setupObservers() { @@ -45,6 +53,12 @@ class UnitsViewModel( } } + private suspend fun setupGeofenceObserver() { + geofenceController.geofencesFlow.collect { + this._geofences.postValue(it) + } + } + fun selectUnit(unit: UnitInformation) { Log.d("UnitsViewModel", "Selecting unit ${unit.device.name}") _selectedUnit.postValue(unit) -- cgit v1.2.3