@ -46,6 +46,7 @@ import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getSpannable
import org.mozilla.fenix.ext.hideToolbar
@ -54,6 +55,7 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.search.awesomebar.AwesomeBarView
import org.mozilla.fenix.search.toolbar.ToolbarView
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.registerOnSharedPreferenceChangeListener
import org.mozilla.fenix.widget.VoiceSearchActivity.Companion.SPEECH_REQUEST_CODE
@Suppress ( " TooManyFunctions " , " LargeClass " )
@ -128,6 +130,8 @@ class SearchFragment : Fragment(), UserInteractionHandler {
awesomeBarView = AwesomeBarView ( view . scrollable _area , searchInteractor ,
view . findViewById ( R . id . awesomeBar ) )
setShortcutsChangedListener ( )
view . scrollView . setOnScrollChangeListener {
_ : NestedScrollView , _ : Int , _ : Int , _ : Int , _ : Int ->
view . hideKeyboard ( )
@ -164,6 +168,17 @@ class SearchFragment : Fragment(), UserInteractionHandler {
return ( speechIntent . resolveActivity ( requireContext ( ) . packageManager ) != null )
}
private fun setShortcutsChangedListener ( ) {
requireContext ( ) . getSharedPreferences (
CustomSearchEngineStore . PREF _FILE _SEARCH _ENGINES ,
Context . MODE _PRIVATE
) . registerOnSharedPreferenceChangeListener ( viewLifecycleOwner ) { _ , key ->
if ( key == CustomSearchEngineStore . PREF _KEY _CUSTOM _SEARCH _ENGINES ) {
awesomeBarView . update ( searchStore . state )
}
}
}
private fun launchVoiceSearch ( ) {
// Note if a user disables speech while the app is on the search fragment
// the voice button will still be available and *will* cause a crash if tapped,