aboutsummaryrefslogtreecommitdiff
path: root/androidApp
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-13 02:07:31 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-13 02:07:31 -0600
commitc031a94852402f3b4cc8a8cdbe349af6660d74ce (patch)
tree242053b13cfe72d3d9684e876a5d84e130c63329 /androidApp
parent63ab1aa022828b3cd98bf2bf199e601840c34f3c (diff)
downloadetbsa-trackermap-mobile-c031a94852402f3b4cc8a8cdbe349af6660d74ce.tar.gz
etbsa-trackermap-mobile-c031a94852402f3b4cc8a8cdbe349af6660d74ce.tar.bz2
etbsa-trackermap-mobile-c031a94852402f3b4cc8a8cdbe349af6660d74ce.zip
Hide keyboard and unfocus search filter when selecting unit in UnitsActivity
Diffstat (limited to 'androidApp')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt24
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() {