Hide soft keyboard after submitting search query throughout app (#5837)

* Clear focus from SearchView when submitting a search query in BrowseSourceController

* Revert "Clear focus from SearchView when submitting a search query"

* Implement SearchView focus clearing in Tachiyomi's subclass to enable feature throughout app

* Add support for keyboard Enter key

Pressing enter on a keyboard (when using the emulator for example) now also submits the query
This commit is contained in:
Hunter Nickel 2021-09-25 12:32:19 -06:00 committed by GitHub
parent b284384f0a
commit 82f14a7d59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.widget
import android.content.Context
import android.util.AttributeSet
import android.view.inputmethod.EditorInfo
import androidx.appcompat.widget.SearchView
import androidx.core.view.inputmethod.EditorInfoCompat
import eu.kanade.tachiyomi.R
@ -39,6 +40,18 @@ class TachiyomiSearchView @JvmOverloads constructor(
}.launchIn(scope!!)
}
override fun setOnQueryTextListener(listener: OnQueryTextListener?) {
super.setOnQueryTextListener(listener)
val searchAutoComplete: SearchAutoComplete = findViewById(R.id.search_src_text)
searchAutoComplete.setOnEditorActionListener { _, actionID, _ ->
if (actionID == EditorInfo.IME_ACTION_SEARCH || actionID == EditorInfo.IME_NULL) {
clearFocus()
listener?.onQueryTextSubmit(query.toString())
true
} else false
}
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
scope?.cancel()