For #9425 - SearchFragment now reacts to undo operation for custom engines
When you remove a search engine from our list, an undo snackbar that outlives the fragment is shown. If you go back to the search fragment and press undo, now the shortcut list gets updatedmaster
parent
46c1c130da
commit
e6e3166d2d
|
@ -6,7 +6,6 @@ package org.mozilla.fenix.components.searchengine
|
|||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import mozilla.components.browser.icons.IconRequest
|
||||
import mozilla.components.browser.search.SearchEngine
|
||||
import mozilla.components.browser.search.SearchEngineParser
|
||||
|
@ -125,7 +124,6 @@ object CustomSearchEngineStore {
|
|||
}
|
||||
}
|
||||
|
||||
private const val PREF_KEY_CUSTOM_SEARCH_ENGINES = "pref_custom_search_engines"
|
||||
@VisibleForTesting
|
||||
const val PREF_KEY_CUSTOM_SEARCH_ENGINES = "pref_custom_search_engines"
|
||||
const val PREF_FILE_SEARCH_ENGINES = "custom-search-engines"
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue