2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/9425 - SearchFragment now reacts to undo operation for base engines

This commit is contained in:
Mihai Branescu 2020-05-13 17:48:02 +03:00
parent 6e66943b3c
commit ef5b875e24
4 changed files with 11 additions and 14 deletions

View File

@ -124,6 +124,6 @@ object CustomSearchEngineStore {
}
}
const val PREF_KEY_CUSTOM_SEARCH_ENGINES = "pref_custom_search_engines"
private const val PREF_KEY_CUSTOM_SEARCH_ENGINES = "pref_custom_search_engines"
const val PREF_FILE_SEARCH_ENGINES = "custom-search-engines"
}

View File

@ -183,7 +183,7 @@ open class FenixSearchEngineProvider(
}
private fun prefs(context: Context) = context.getSharedPreferences(
PREF_FILE,
PREF_FILE_SEARCH_ENGINES,
Context.MODE_PRIVATE
)
@ -229,7 +229,7 @@ open class FenixSearchEngineProvider(
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
companion object {
val BUNDLED_SEARCH_ENGINES = listOf("reddit", "youtube")
const val PREF_FILE = "fenix-search-engine-provider"
const val PREF_FILE_SEARCH_ENGINES = "fenix-search-engine-provider"
const val INSTALLED_ENGINES_KEY = "fenix-installed-search-engines"
const val CURRENT_LOCALE_KEY = "fenix-current-locale"
}

View File

@ -47,6 +47,7 @@ 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.components.searchengine.FenixSearchEngineProvider
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getSpannable
import org.mozilla.fenix.ext.hideToolbar
@ -130,7 +131,8 @@ class SearchFragment : Fragment(), UserInteractionHandler {
awesomeBarView = AwesomeBarView(view.scrollable_area, searchInteractor,
view.findViewById(R.id.awesomeBar))
setShortcutsChangedListener()
setShortcutsChangedListener(CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES)
setShortcutsChangedListener(FenixSearchEngineProvider.PREF_FILE_SEARCH_ENGINES)
view.scrollView.setOnScrollChangeListener {
_: NestedScrollView, _: Int, _: Int, _: Int, _: Int ->
@ -168,16 +170,14 @@ class SearchFragment : Fragment(), UserInteractionHandler {
return (speechIntent.resolveActivity(requireContext().packageManager) != null)
}
private fun setShortcutsChangedListener() {
private fun setShortcutsChangedListener(preferenceFileName: String) {
requireContext().getSharedPreferences(
CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES,
preferenceFileName,
Context.MODE_PRIVATE
).registerOnSharedPreferenceChangeListener(viewLifecycleOwner) { _, key ->
if (key == CustomSearchEngineStore.PREF_KEY_CUSTOM_SEARCH_ENGINES) {
).registerOnSharedPreferenceChangeListener(viewLifecycleOwner) { _, _ ->
awesomeBarView.update(searchStore.state)
}
}
}
private fun launchVoiceSearch() {
// Note if a user disables speech while the app is on the search fragment

View File

@ -3,13 +3,10 @@ package org.mozilla.fenix.components.searchengine
import android.content.Context
import io.mockk.every
import io.mockk.mockk
import android.graphics.Bitmap
import io.mockk.Runs
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkObject
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
@ -85,7 +82,7 @@ class FenixSearchEngineProviderTest {
@Test
fun `GIVEN sharedprefs contains installed engines WHEN installedSearchEngineIdentifiers THEN defaultEngines + customEngines ids are returned`() = runBlockingTest {
val sp = testContext.getSharedPreferences(FenixSearchEngineProvider.PREF_FILE, Context.MODE_PRIVATE)
val sp = testContext.getSharedPreferences(FenixSearchEngineProvider.PREF_FILE_SEARCH_ENGINES, Context.MODE_PRIVATE)
sp.edit().putStringSet(fenixSearchEngineProvider.localeAwareInstalledEnginesKey(), persistedInstalledEngines).apply()
val expectedStored = persistedInstalledEngines