For #16973 - Use controller handled action instead of toolbar focus

This commit is contained in:
ekager 2020-12-11 12:27:47 -08:00
parent 2e87b640a9
commit 419f895364

View File

@ -82,6 +82,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
private val qrFeature = ViewBoundFeatureWrapper<QrFeature>() private val qrFeature = ViewBoundFeatureWrapper<QrFeature>()
private val speechIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH) private val speechIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
private var dialogHandledAction = false
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
@ -146,8 +147,12 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
navController = findNavController(), navController = findNavController(),
settings = requireContext().settings(), settings = requireContext().settings(),
metrics = requireComponents.analytics.metrics, metrics = requireComponents.analytics.metrics,
dismissDialog = { dismissAllowingStateLoss() }, dismissDialog = {
dialogHandledAction = true
dismissAllowingStateLoss()
},
clearToolbarFocus = { clearToolbarFocus = {
dialogHandledAction = true
toolbarView.view.hideKeyboard() toolbarView.view.hideKeyboard()
toolbarView.view.clearFocus() 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. * is also dismissing. For example, when clicking a top site on home while this dialog is showing.
*/ */
private fun hideDeviceKeyboard() { private fun hideDeviceKeyboard() {
// If the controller has handled a search event itself, it will clear the focus. // If the interactor/controller has handled a search event itself, it will hide the keyboard.
if (toolbarView.view.hasFocus()) { if (!dialogHandledAction) {
val imm = val imm =
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0) imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)