aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--androidApp/build.gradle.kts4
-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/UnitsActivity.kt38
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt20
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt2
5 files changed, 51 insertions, 15 deletions
diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts
index 1ef895a..d4869fc 100644
--- a/androidApp/build.gradle.kts
+++ b/androidApp/build.gradle.kts
@@ -44,9 +44,9 @@ val googleImplementation by configurations
dependencies {
implementation(project(":shared"))
- implementation("com.google.android.material:material:1.5.0")
+ implementation("com.google.android.material:material:1.6.0")
implementation("androidx.appcompat:appcompat:1.4.1")
- implementation("androidx.constraintlayout:constraintlayout:2.1.3")
+ implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.squareup.okhttp3:okhttp:4.9.1")
implementation("com.github.Zhuinden:live-event:1.2.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1")
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/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt
index 09bedbb..8a161c3 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
@@ -19,11 +19,13 @@ package mx.trackermap.TrackerMap.android.units
import android.content.Context
import android.content.Intent
+import android.os.Build
import android.os.Bundle
+import android.text.Editable
+import android.text.TextWatcher
import android.util.Log
import android.view.View
import android.view.inputmethod.InputMethodManager
-import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.TooltipCompat
import androidx.core.widget.doAfterTextChanged
@@ -36,6 +38,7 @@ import mx.trackermap.TrackerMap.android.map.UnitMapFragment
import mx.trackermap.TrackerMap.android.session.UserInformationActivity
import mx.trackermap.TrackerMap.android.shared.Utils
import org.koin.androidx.viewmodel.ext.android.viewModel
+import java.util.*
import kotlin.time.ExperimentalTime
@DelicateCoroutinesApi
@@ -100,13 +103,28 @@ class UnitsActivity : AppCompatActivity() {
binding.mapLayerToggle.setOnClickListener {
showLayersPopUp(it)
}
- binding.searchInput.doAfterTextChanged {
- Log.d("UnitsActivity", "Search changed to ${it.toString()}")
- if (unitsViewModel.unitsDisplayMode.value == UnitsViewModel.UnitsDisplayMode.MAP) {
- unitsViewModel.setDisplayMode(UnitsViewModel.UnitsDisplayMode.LIST)
+ binding.searchInput.addTextChangedListener(object: TextWatcher {
+ override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
+ override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
+
+ var timer = Timer()
+ val delay = 500L // milliseconds before doing search
+
+ override fun afterTextChanged(p0: Editable?) {
+ timer.cancel()
+ timer = Timer()
+ timer.schedule(object: TimerTask() {
+ override fun run() {
+ Log.d("UnitsActivity", "Search changed to $p0")
+ if (unitsViewModel.unitsDisplayMode.value == UnitsViewModel.UnitsDisplayMode.MAP) {
+ unitsViewModel.setDisplayMode(UnitsViewModel.UnitsDisplayMode.LIST)
+ }
+ unitsViewModel.search(p0.toString())
+ }
+ }, delay)
}
- unitsViewModel.search(it.toString())
- }
+
+ })
binding.searchInputLayout.setEndIconOnClickListener {
unfocusSearch(true)
}
@@ -119,7 +137,11 @@ class UnitsActivity : AppCompatActivity() {
}
private fun unfocusSearch(clearText: Boolean = false) {
- val manager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
+ val manager = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ this.getSystemService(InputMethodManager::class.java)
+ } else {
+ this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
+ }
manager.hideSoftInputFromWindow(binding.searchInput.windowToken, 0)
if (clearText) {
binding.searchInput.text?.clear()
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)
}
}
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 8c36d50..529ca1b 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt
@@ -46,7 +46,7 @@ class UnitsController(
}
val displayedUnitsFlow = MutableStateFlow<List<UnitInformation>>(emptyList())
- private val unitsFlow = MutableStateFlow<List<UnitInformation>>(emptyList())
+ val unitsFlow = MutableStateFlow<List<UnitInformation>>(emptyList())
private val queryFlow = MutableStateFlow("")
init {