diff options
author | Iván Ávalos <avalos@disroot.org> | 2021-12-30 22:05:55 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2021-12-30 22:05:55 -0600 |
commit | 5477efa8a11409610619f6dac3ca9303d308c3e4 (patch) | |
tree | 0f0cdd76a77d99db08004e3a968d98c07e95ef8e /androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt | |
parent | 4be0f818e17320145ea7508d89bb21d0e0e7c0bf (diff) | |
download | etbsa-trackermap-mobile-5477efa8a11409610619f6dac3ca9303d308c3e4.tar.gz etbsa-trackermap-mobile-5477efa8a11409610619f6dac3ca9303d308c3e4.tar.bz2 etbsa-trackermap-mobile-5477efa8a11409610619f6dac3ca9303d308c3e4.zip |
- ViewModel LiveData no longer externally mutable.
- Observers in fragments now owned by viewLifecycleOwner.
- Disabled center animation on MapFragment startup
- Search filter now triggered automatically.
- Case insensitive filter logic.
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt | 30 |
1 files changed, 16 insertions, 14 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 bb4efde..d8d7ea1 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 @@ -1,10 +1,7 @@ package mx.trackermap.TrackerMap.android.units import android.util.Log -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.SavedStateHandle -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope +import androidx.lifecycle.* import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch @@ -24,10 +21,15 @@ class UnitsViewModel( private val unitsController: UnitsController by inject() - var searchQuery = savedStateHandle.getLiveData("searchQuery", "") - var unitsDisplayMode = MutableLiveData(UnitsDisplayMode.LIST) - var units = MutableLiveData<List<UnitInformation>>() - var selectedUnit = MutableLiveData<UnitInformation?>() + private var _searchQuery = savedStateHandle.getLiveData("searchQuery", "") + private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.LIST) + private var _units = MutableLiveData<List<UnitInformation>>() + private var _selectedUnit = MutableLiveData<UnitInformation?>() + + 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 init { Log.d("UnitsViewModel", "Initializing Units View Model") @@ -39,19 +41,19 @@ class UnitsViewModel( private suspend fun setupObservers() { Log.d("UnitsViewModel", "Setup observers") unitsController.displayedUnitsFlow.collect { units -> - this.units.value = units + this._units.value = units } } fun selectUnit(unit: UnitInformation) { Log.d("UnitsViewModel", "Selecting unit ${unit.device.name}") - selectedUnit.postValue(unit) + _selectedUnit.postValue(unit) setDisplayMode(UnitsDisplayMode.MAP) } fun setDisplayMode(displayMode: UnitsDisplayMode) { Log.d("UnitsViewModel", "Setting Display mode to $displayMode") - unitsDisplayMode.postValue(displayMode) + _unitsDisplayMode.postValue(displayMode) } fun toggleDisplayMode() { @@ -62,10 +64,10 @@ class UnitsViewModel( } else { UnitsDisplayMode.MAP } - unitsDisplayMode.postValue(newDisplayMode) + _unitsDisplayMode.postValue(newDisplayMode) } - fun search() { - unitsController.search(searchQuery.value!!) + fun search(query: String) { + unitsController.search(query) } }
\ No newline at end of file |