1
0
Fork 0

For #9425 - SearchFragment now reacts to undo operation for base engines

master
Mihai Branescu 2020-05-13 17:48:02 +03:00
parent e6e3166d2d
commit 93247e0b2f
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" 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( private fun prefs(context: Context) = context.getSharedPreferences(
PREF_FILE, PREF_FILE_SEARCH_ENGINES,
Context.MODE_PRIVATE Context.MODE_PRIVATE
) )
@ -229,7 +229,7 @@ open class FenixSearchEngineProvider(
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
companion object { companion object {
val BUNDLED_SEARCH_ENGINES = listOf("reddit", "youtube") 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 INSTALLED_ENGINES_KEY = "fenix-installed-search-engines"
const val CURRENT_LOCALE_KEY = "fenix-current-locale" 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.StoreProvider
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore 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.components
import org.mozilla.fenix.ext.getSpannable import org.mozilla.fenix.ext.getSpannable
import org.mozilla.fenix.ext.hideToolbar import org.mozilla.fenix.ext.hideToolbar
@ -130,7 +131,8 @@ class SearchFragment : Fragment(), UserInteractionHandler {
awesomeBarView = AwesomeBarView(view.scrollable_area, searchInteractor, awesomeBarView = AwesomeBarView(view.scrollable_area, searchInteractor,
view.findViewById(R.id.awesomeBar)) view.findViewById(R.id.awesomeBar))
setShortcutsChangedListener() setShortcutsChangedListener(CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES)
setShortcutsChangedListener(FenixSearchEngineProvider.PREF_FILE_SEARCH_ENGINES)
view.scrollView.setOnScrollChangeListener { view.scrollView.setOnScrollChangeListener {
_: NestedScrollView, _: Int, _: Int, _: Int, _: Int -> _: NestedScrollView, _: Int, _: Int, _: Int, _: Int ->
@ -168,16 +170,14 @@ class SearchFragment : Fragment(), UserInteractionHandler {
return (speechIntent.resolveActivity(requireContext().packageManager) != null) return (speechIntent.resolveActivity(requireContext().packageManager) != null)
} }
private fun setShortcutsChangedListener() { private fun setShortcutsChangedListener(preferenceFileName: String) {
requireContext().getSharedPreferences( requireContext().getSharedPreferences(
CustomSearchEngineStore.PREF_FILE_SEARCH_ENGINES, preferenceFileName,
Context.MODE_PRIVATE Context.MODE_PRIVATE
).registerOnSharedPreferenceChangeListener(viewLifecycleOwner) { _, key -> ).registerOnSharedPreferenceChangeListener(viewLifecycleOwner) { _, _ ->
if (key == CustomSearchEngineStore.PREF_KEY_CUSTOM_SEARCH_ENGINES) {
awesomeBarView.update(searchStore.state) awesomeBarView.update(searchStore.state)
} }
} }
}
private fun launchVoiceSearch() { private fun launchVoiceSearch() {
// Note if a user disables speech while the app is on the search fragment // 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 android.content.Context
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import android.graphics.Bitmap
import io.mockk.Runs import io.mockk.Runs
import io.mockk.coEvery import io.mockk.coEvery
import io.mockk.coVerify import io.mockk.coVerify
import io.mockk.every
import io.mockk.just import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkObject import io.mockk.mockkObject
import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
@ -85,7 +82,7 @@ class FenixSearchEngineProviderTest {
@Test @Test
fun `GIVEN sharedprefs contains installed engines WHEN installedSearchEngineIdentifiers THEN defaultEngines + customEngines ids are returned`() = runBlockingTest { 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() sp.edit().putStringSet(fenixSearchEngineProvider.localeAwareInstalledEnginesKey(), persistedInstalledEngines).apply()
val expectedStored = persistedInstalledEngines val expectedStored = persistedInstalledEngines