Merge pull request #915 from Bnyro/master

fix search
This commit is contained in:
Bnyro 2022-07-29 12:44:49 +02:00 committed by GitHub
commit 7683d0cb1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,6 @@ import android.view.ViewGroup
import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.TextView.GONE
import android.widget.TextView.OnEditorActionListener
import android.widget.TextView.VISIBLE
@ -128,7 +127,7 @@ class SearchFragment : Fragment() {
fetchNextSearchItems(binding.autoCompleteTextView.text.toString())
}
}
fetchSuggestions(s.toString(), binding.autoCompleteTextView)
fetchSuggestions(s.toString())
}
}
@ -153,7 +152,7 @@ class SearchFragment : Fragment() {
)
}
private fun fetchSuggestions(query: String, autoTextView: EditText) {
private fun fetchSuggestions(query: String) {
fun run() {
lifecycleScope.launchWhenCreated {
binding.searchRecycler.visibility = GONE
@ -168,9 +167,16 @@ class SearchFragment : Fragment() {
Log.e(TAG, "HttpException, unexpected response")
return@launchWhenCreated
}
val suggestionsAdapter =
SearchSuggestionsAdapter(response, autoTextView, this@SearchFragment)
binding.historyRecycler.adapter = suggestionsAdapter
// only load the suggestions if the input field didn't get cleared yet
if (binding.autoCompleteTextView.text.toString() != "") {
val suggestionsAdapter =
SearchSuggestionsAdapter(
response,
binding.autoCompleteTextView,
this@SearchFragment
)
binding.historyRecycler.adapter = suggestionsAdapter
}
}
}
if (!isFetchingSearch) run()