From 39b6463f5bf49e142f651a0cdfa7bd8205878f62 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Tue, 30 Jun 2020 12:01:20 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/12081 - Properly installs searchengines when MLS completes --- .../searchengine/FenixSearchEngineProvider.kt | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/searchengine/FenixSearchEngineProvider.kt b/app/src/main/java/org/mozilla/fenix/components/searchengine/FenixSearchEngineProvider.kt index 0f8b1a9fba..6d61f24408 100644 --- a/app/src/main/java/org/mozilla/fenix/components/searchengine/FenixSearchEngineProvider.kt +++ b/app/src/main/java/org/mozilla/fenix/components/searchengine/FenixSearchEngineProvider.kt @@ -19,7 +19,6 @@ import mozilla.components.browser.search.provider.SearchEngineList import mozilla.components.browser.search.provider.SearchEngineProvider import mozilla.components.browser.search.provider.filter.SearchEngineFilter import mozilla.components.browser.search.provider.localization.LocaleSearchLocalizationProvider -import mozilla.components.browser.search.provider.localization.SearchLocalization import mozilla.components.browser.search.provider.localization.SearchLocalizationProvider import mozilla.components.service.location.LocationService import mozilla.components.service.location.MozillaLocationService @@ -98,14 +97,6 @@ open class FenixSearchEngineProvider( fallbackEngines } - private val region: Deferred - get() = - if (loadedRegion.isCompleted) { - loadedRegion - } else { - fallbackRegion - } - fun getDefaultEngine(context: Context): SearchEngine { val engines = installedSearchEngines(context) val selectedName = context.settings().defaultSearchEngineName @@ -207,12 +198,6 @@ open class FenixSearchEngineProvider( val prefs = prefs(context) val installedEnginesKey = localeAwareInstalledEnginesKey() - if (installedEnginesKey != prefs.getString(CURRENT_LOCALE_KEY, "")) { - updateBaseSearchEngines() - reload() - prefs.edit().putString(CURRENT_LOCALE_KEY, installedEnginesKey).apply() - } - if (!prefs.contains(installedEnginesKey)) { val searchEngines = if (baseSearchEngines.isCompleted) baseSearchEngines @@ -234,12 +219,20 @@ open class FenixSearchEngineProvider( @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) suspend fun localeAwareInstalledEnginesKey(): String { - val tag = region.await().let { - val region = it.region?.let { region -> - if (region.isEmpty()) "" else "-$region" + val tag = if (loadedRegion.isCompleted) { + val localization = loadedRegion.await() + val region = localization.region?.let { + if (it.isEmpty()) "" else "-$it" } - "${it.languageTag}$region" + "${localization.languageTag}$region" + } else { + val localization = fallbackRegion.await() + val region = localization.region?.let { + if (it.isEmpty()) "" else "-$it" + } + + "${localization.languageTag}$region-fallback" } return "$INSTALLED_ENGINES_KEY-$tag"