From 419f8953643ccf27142afa033c99f79abab26e09 Mon Sep 17 00:00:00 2001 From: ekager Date: Fri, 11 Dec 2020 12:27:47 -0800 Subject: [PATCH] For #16973 - Use controller handled action instead of toolbar focus --- .../org/mozilla/fenix/search/SearchDialogFragment.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt index 9dec261dc..f6ce42fc5 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchDialogFragment.kt @@ -82,6 +82,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler { private val qrFeature = ViewBoundFeatureWrapper() private val speechIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH) + private var dialogHandledAction = false override fun onStart() { super.onStart() @@ -146,8 +147,12 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler { navController = findNavController(), settings = requireContext().settings(), metrics = requireComponents.analytics.metrics, - dismissDialog = { dismissAllowingStateLoss() }, + dismissDialog = { + dialogHandledAction = true + dismissAllowingStateLoss() + }, clearToolbarFocus = { + dialogHandledAction = true toolbarView.view.hideKeyboard() toolbarView.view.clearFocus() }, @@ -345,8 +350,8 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler { * is also dismissing. For example, when clicking a top site on home while this dialog is showing. */ private fun hideDeviceKeyboard() { - // If the controller has handled a search event itself, it will clear the focus. - if (toolbarView.view.hasFocus()) { + // If the interactor/controller has handled a search event itself, it will hide the keyboard. + if (!dialogHandledAction) { val imm = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)