diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-11 04:12:45 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-11 04:12:45 -0600 |
commit | 8878254a4a3af9d15262fd2553c7b2db0a7bd8bc (patch) | |
tree | 4918c7ad01bf2c74bf5492f3c443408c733b0ab6 /androidApp/src/main/java/mx/trackermap/TrackerMap/android/units | |
parent | 7629861e4e2b7e52b93f817426cb940c8f075b59 (diff) | |
download | etbsa-trackermap-mobile-8878254a4a3af9d15262fd2553c7b2db0a7bd8bc.tar.gz etbsa-trackermap-mobile-8878254a4a3af9d15262fd2553c7b2db0a7bd8bc.tar.bz2 etbsa-trackermap-mobile-8878254a4a3af9d15262fd2553c7b2db0a7bd8bc.zip |
Implemented polygon geofences
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/units')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt | 14 |
1 files changed, 14 insertions, 0 deletions
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<List<UnitInformation>>() private var _selectedUnit = MutableLiveData<UnitInformation?>() + private var _geofences = MutableLiveData<Map<Int, Geofence>>() val searchQuery: LiveData<String> get() = _searchQuery val unitsDisplayMode: LiveData<UnitsDisplayMode> get() = _unitsDisplayMode val units: LiveData<List<UnitInformation>> get() = _units val selectedUnit: LiveData<UnitInformation?> get() = _selectedUnit + val geofences: LiveData<Map<Int, Geofence>> 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) |