Merge pull request #894 from Bnyro/master

fix search behavior
This commit is contained in:
Bnyro 2022-07-28 17:10:03 +02:00 committed by GitHub
commit e6e9f77b3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,7 +66,7 @@ class SearchFragment : Fragment() {
binding.clearSearchImageView.setOnClickListener { binding.clearSearchImageView.setOnClickListener {
binding.autoCompleteTextView.text.clear() binding.autoCompleteTextView.text.clear()
binding.historyRecycler.visibility = View.GONE binding.historyRecycler.adapter = null
showHistory() showHistory()
} }
@ -129,7 +129,7 @@ class SearchFragment : Fragment() {
} }
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (s!! != "") { if (s.toString() != "") {
binding.searchRecycler.adapter = null binding.searchRecycler.adapter = null
binding.searchRecycler.viewTreeObserver binding.searchRecycler.viewTreeObserver
@ -144,14 +144,15 @@ class SearchFragment : Fragment() {
override fun afterTextChanged(s: Editable?) { override fun afterTextChanged(s: Editable?) {
if (s!!.isEmpty()) { if (s!!.isEmpty()) {
binding.historyRecycler.adapter = null
showHistory() showHistory()
} }
} }
}) })
binding.autoCompleteTextView.setOnEditorActionListener( binding.autoCompleteTextView.setOnEditorActionListener(
OnEditorActionListener { _, actionId, _ -> OnEditorActionListener { textView, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) { if (actionId == EditorInfo.IME_ACTION_SEARCH && textView.text.toString() != "") {
view?.let { context?.hideKeyboard(it) } view.let { context?.hideKeyboard(it) }
binding.searchRecycler.visibility = VISIBLE binding.searchRecycler.visibility = VISIBLE
binding.historyRecycler.visibility = GONE binding.historyRecycler.visibility = GONE
fetchSearch(binding.autoCompleteTextView.text.toString()) fetchSearch(binding.autoCompleteTextView.text.toString())