diff options
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt | 24 |
1 files changed, 17 insertions, 7 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 24d0e4b..e73d3a8 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 @@ -1,12 +1,13 @@ package mx.trackermap.TrackerMap.android.units +import android.content.Context import android.content.Intent import android.os.Bundle import android.util.Log import android.view.View +import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.PopupMenu -import androidx.core.content.ContextCompat import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.commit import kotlinx.coroutines.DelicateCoroutinesApi @@ -70,15 +71,12 @@ class UnitsActivity : AppCompatActivity() { } binding.searchInput.doAfterTextChanged { Log.d("UnitsActivity", "Search changed to ${it.toString()}") - /*binding.searchInput.setCompoundDrawablesRelativeWithIntrinsicBounds( - null, null, - if (it?.isEmpty() == true) null - else ContextCompat.getDrawable(this, R.drawable.icon_back), - null, - )*/ binding.searchInput unitsViewModel.search(it.toString()) } + binding.searchInputLayout.setEndIconOnClickListener { + unfocusSearch(true) + } } private fun showLayersPopUp(view: View) { @@ -98,6 +96,15 @@ class UnitsActivity : AppCompatActivity() { popOver.show() } + private fun unfocusSearch(clearText: Boolean = false) { + val manager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + manager.hideSoftInputFromWindow(binding.searchInput.windowToken, 0) + if (clearText) { + binding.searchInput.text?.clear() + } + binding.searchInput.clearFocus() + } + private fun setupObservers() { unitsViewModel.unitsDisplayMode.observe(this) { displayMode -> binding.displayModeToggle.setImageResource( @@ -132,6 +139,9 @@ class UnitsActivity : AppCompatActivity() { replace(R.id.displayContainer, newFragment) } } + unitsViewModel.selectedUnit.observe(this) { + unfocusSearch() + } } private fun removeObservers() { |