aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-05-20 23:21:37 -0500
committerIván Ávalos <avalos@disroot.org>2022-05-20 23:21:37 -0500
commitec157026deea7b72ff233a20c0ed40fa548f75d6 (patch)
tree71f0ebb5c358fc53130edad39436b0c7b698f818 /androidApp/src/main/java/mx/trackermap
parent22d2b3ed3569925fc3835dd5b53c6aacde86278a (diff)
downloadetbsa-trackermap-mobile-ec157026deea7b72ff233a20c0ed40fa548f75d6.tar.gz
etbsa-trackermap-mobile-ec157026deea7b72ff233a20c0ed40fa548f75d6.tar.bz2
etbsa-trackermap-mobile-ec157026deea7b72ff233a20c0ed40fa548f75d6.zip
- [shared] unitsFlow exposed to allow access to unfiltered units.
- [android] Improved memory usage by using unitsFlow in map. - [ios] Not rewritten yet, filter won't work.
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)
}
}