aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt2
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt20
2 files changed, 18 insertions, 4 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
index e5143cb..6e1b1c6 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
@@ -90,7 +90,7 @@ class DevicesFragment : Fragment() {
@DelicateCoroutinesApi
private fun setupObservers() {
Log.d("DevicesFragment", "setupObservers()")
- unitsViewModel.units.observe(viewLifecycleOwner) { units ->
+ unitsViewModel.displayedUnits.observe(viewLifecycleOwner) { units ->
Log.d("DevicesFragment", "Success $units")
binding.infoLoading.root.visibility = View.GONE
(binding.devicesList.adapter as DevicesAdapter).setData(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 174d55e..b537c0b 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
@@ -54,6 +54,7 @@ class UnitsViewModel(
private var _searchQuery = savedStateHandle.getLiveData("searchQuery", "")
private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP)
private var _units = MutableLiveData<List<UnitInformation>>()
+ private var _displayedUnits = MutableLiveData<List<UnitInformation>>()
private var _oldSelectedUnit = MutableLiveData<UnitInformation?>()
private var _selectedUnit = MutableLiveData<UnitInformation?>()
private var _mapLayerType = MutableLiveData<MapLayer.Type>()
@@ -63,6 +64,7 @@ class UnitsViewModel(
val searchQuery: LiveData<String> get() = _searchQuery
val unitsDisplayMode: LiveData<UnitsDisplayMode> get() = _unitsDisplayMode
val units: LiveData<List<UnitInformation>> get() = _units
+ val displayedUnits: LiveData<List<UnitInformation>> get() = _displayedUnits
val oldSelectedUnit: LiveData<UnitInformation?> get() = _oldSelectedUnit
val selectedUnit: LiveData<UnitInformation?> get() = _selectedUnit
val mapLayerType: LiveData<MapLayer.Type> get() = _mapLayerType
@@ -73,16 +75,27 @@ class UnitsViewModel(
Log.d("UnitsViewModel", "Initializing Units View Model")
unitsController.fetchUnits(viewModelScope)
viewModelScope.launch {
- setupObservers()
+ setupUnitsObserver()
}
viewModelScope.launch {
+ setupDisplayedUnitsObserver()
+ }
+
+ viewModelScope.launch {
setupGeofenceObserver()
}
}
- private suspend fun setupObservers() {
- Log.d("UnitsViewModel", "Setup observers")
+ private suspend fun setupUnitsObserver() {
unitsController.displayedUnitsFlow.collect { units ->
+ Log.d("UnitsViewModel", "Collecting units")
+ this._displayedUnits.value = units
+ }
+ }
+
+ private suspend fun setupDisplayedUnitsObserver() {
+ unitsController.unitsFlow.collect { units ->
+ Log.d("UnitsViewModel", "Collecting displayed units")
this._units.value = units
updateSelectedUnit()
}
@@ -90,6 +103,7 @@ class UnitsViewModel(
private suspend fun setupGeofenceObserver() {
geofenceController.geofencesFlow.collect {
+ Log.d("UnitsViewModel", "Collecting geofences")
this._geofences.postValue(it)
}
}