From 662d7cdddf6bfe9c62a06a4cae83ea22f709f678 Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Tue, 1 Sep 2020 01:59:33 +0200 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/14354: Update the search shortcuts icon on state update (https://github.com/mozilla-mobile/fenix/pull/14355) --- .../fenix/searchdialog/SearchDialogFragment.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt index c67ed7b96e..7d92d13a71 100644 --- a/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/searchdialog/SearchDialogFragment.kt @@ -40,6 +40,7 @@ import mozilla.components.feature.qr.QrFeature import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.support.base.feature.UserInteractionHandler import mozilla.components.support.base.feature.ViewBoundFeatureWrapper +import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.ktx.android.content.hasCamera import mozilla.components.support.ktx.android.content.res.getSpanned import mozilla.components.support.ktx.android.view.hideKeyboard @@ -254,6 +255,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler { updateSearchSuggestionsHintVisibility(it) updateClipboardSuggestion(it, requireContext().components.clipboardHandler.url) updateToolbarContentDescription(it) + updateSearchShortcutsIcon(it) toolbarView.update(it) awesomeBarView.update(it) firstUpdate = false @@ -416,6 +418,20 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler { urlView?.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO } + private fun updateSearchShortcutsIcon(searchState: SearchFragmentState) { + view?.apply { + search_engines_shortcut_button.isVisible = searchState.areShortcutsAvailable + + val showShortcuts = searchState.showSearchShortcuts + search_engines_shortcut_button.isChecked = showShortcuts + + val color = if (showShortcuts) R.attr.contrastText else R.attr.primaryText + search_engines_shortcut_button.compoundDrawables[0]?.setTint( + requireContext().getColorFromAttr(color) + ) + } + } + companion object { private const val REQUEST_CODE_CAMERA_PERMISSIONS = 1 }