From 82f14a7d59120e9de31351409f81d10671e4e394 Mon Sep 17 00:00:00 2001 From: Hunter Nickel Date: Sat, 25 Sep 2021 12:32:19 -0600 Subject: [PATCH] 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 --- .../kanade/tachiyomi/widget/TachiyomiSearchView.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt index 80e7850c6..6a971ce82 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt @@ -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()