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 | 774f8876d6c61a8dd434ed67f1ee5bc801ee7eb5 (patch) | |
tree | 6a1cedaed75b7edcf36217038470b66c1664f3fb | |
parent | fabb451dbdbd28b0f09b91ee193d6d62ed027df7 (diff) | |
download | etbsa-trackermap-mobile-774f8876d6c61a8dd434ed67f1ee5bc801ee7eb5.tar.gz etbsa-trackermap-mobile-774f8876d6c61a8dd434ed67f1ee5bc801ee7eb5.tar.bz2 etbsa-trackermap-mobile-774f8876d6c61a8dd434ed67f1ee5bc801ee7eb5.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
4 files changed, 40 insertions, 5 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 diff --git a/androidApp/src/main/res/layout/units_activity.xml b/androidApp/src/main/res/layout/units_activity.xml index fa98bfc..750e00f 100644 --- a/androidApp/src/main/res/layout/units_activity.xml +++ b/androidApp/src/main/res/layout/units_activity.xml @@ -16,6 +16,32 @@ app:layout_constraintBottom_toBottomOf="parent" android:background="@color/colorPrimary"/> + <com.google.android.material.card.MaterialCardView + android:layout_width="0dp" + android:layout_height="0dp" + app:layout_constraintTop_toTopOf="@id/displayModeToggle" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toStartOf="@id/displayModeToggle" + app:layout_constraintBottom_toBottomOf="@id/displayModeToggle" + android:layout_marginVertical="4dp" + android:layout_marginStart="16dp" + android:layout_marginEnd="8dp" + app:cardCornerRadius="25dp" + app:cardElevation="5dp"> + + <com.google.android.material.textfield.TextInputEditText + android:id="@+id/searchInput" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:hint="Type to search" + android:paddingHorizontal="16dp" + android:background="@null" + android:inputType="text" + android:lines="1" + android:imeOptions="actionSearch" /> + + </com.google.android.material.card.MaterialCardView> + <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/displayModeToggle" android:layout_width="wrap_content" diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt index 9c11b79..29c84f4 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt @@ -30,7 +30,7 @@ class UnitsController( } } - suspend fun fetchUnits() { + private suspend fun fetchUnits() { val devices = devicesApi.devicesGet() val positions = positionsApi.positionsGet() val positionsMap: MutableMap<Int, Position> = mutableMapOf() @@ -51,7 +51,7 @@ class UnitsController( queryFlow.value = query } - suspend fun setupFlows() { + private suspend fun setupFlows() { unitsFlow.combine(queryFlow) { units, query -> units.filter { unit -> unit.device.name.contains(query) || |