diff options
author | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-11 18:09:42 -0600 |
---|---|---|
committer | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-11 18:09:42 -0600 |
commit | cd3c9d93053241b48051ca20d301e4768a576456 (patch) | |
tree | 6a1cedaed75b7edcf36217038470b66c1664f3fb /androidApp/src/main/java/mx/trackermap/TrackerMap | |
parent | 04c2889895483f5925c90ed7a856d38391fcab45 (diff) | |
download | etbsa-trackermap-mobile-cd3c9d93053241b48051ca20d301e4768a576456.tar.gz etbsa-trackermap-mobile-cd3c9d93053241b48051ca20d301e4768a576456.tar.bz2 etbsa-trackermap-mobile-cd3c9d93053241b48051ca20d301e4768a576456.zip |
Adds the search behaviour
- Updates units_activity to include a search input
- Adds the search functionality to the Units VM
- Adds the required events to the Units Activity to perform the search
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt | 8 | ||||
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt index 6e9bc83..c895f31 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt @@ -2,6 +2,7 @@ package mx.trackermap.TrackerMap.android.units import android.os.Bundle import androidx.appcompat.app.AppCompatActivity +import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.commit import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.UnitsActivityBinding @@ -35,6 +36,13 @@ class UnitsActivity : AppCompatActivity() { binding.displayModeToggle.setOnClickListener { unitsViewModel.toggleDisplayMode() } + binding.searchInput.doAfterTextChanged { + unitsViewModel.searchQuery.value = it.toString() + } + binding.searchInput.setOnEditorActionListener { _, _, _ -> + unitsViewModel.search() + true + } } private fun setupObservers() { 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 7ac6e28..5d7d469 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 @@ -15,7 +15,7 @@ import org.koin.core.component.inject @DelicateCoroutinesApi class UnitsViewModel( - private val savedStateHandle: SavedStateHandle + savedStateHandle: SavedStateHandle ) : ViewModel(), KoinComponent { enum class UnitsDisplayMode { @@ -24,6 +24,7 @@ class UnitsViewModel( private val unitsController: UnitsController by inject() + var searchQuery = savedStateHandle.getLiveData("searchQuery", "") var unitsDisplayMode = MutableLiveData(UnitsDisplayMode.MAP) var units = MutableLiveData<List<UnitInformation>>() @@ -52,7 +53,7 @@ class UnitsViewModel( unitsDisplayMode.postValue(newDisplayMode) } - fun search(query: String) { - unitsController.search(query) + fun search() { + unitsController.search(searchQuery.value!!) } }
\ No newline at end of file |