From 20993462e977fdd5bf181643417c2d9e56a0c290 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Wed, 3 Jul 2019 07:37:35 -0700 Subject: [PATCH] For #3869 - Creates a SearchLocalizationProvider that sets the region to get the correct default search engine based on a locale --- .../org/mozilla/fenix/components/Search.kt | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/Search.kt b/app/src/main/java/org/mozilla/fenix/components/Search.kt index 45b38f05d7..d0640f6766 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Search.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Search.kt @@ -9,8 +9,27 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import mozilla.components.browser.search.SearchEngineManager +import mozilla.components.browser.search.provider.AssetsSearchEngineProvider +import mozilla.components.browser.search.provider.localization.SearchLocalizationProvider import org.mozilla.fenix.test.Mockable import org.mozilla.fenix.utils.Settings +import java.util.Locale + +// Create our own SearchLocalizationProivder that sets the region based on the country +// This is a temporary fix until we have a localization provider that can look up the users +// issue +// https://github.com/mozilla-mobile/fenix/issues/3869 +// https://github.com/mozilla-mobile/android-components/issues/3637 +class FenixLocaleSearchLocalizationProvider : SearchLocalizationProvider() { + override val language: String + get() = Locale.getDefault().language + + override val country: String + get() = Locale.getDefault().country + + override val region: String + get() = country +} /** * Component group for all search engine integration related functionality. @@ -22,7 +41,9 @@ class Search(private val context: Context) { * This component provides access to a centralized registry of search engines. */ val searchEngineManager by lazy { - SearchEngineManager(coroutineContext = IO).apply { + SearchEngineManager(coroutineContext = IO, providers = listOf( + AssetsSearchEngineProvider(FenixLocaleSearchLocalizationProvider()) + )).apply { registerForLocaleUpdates(context) GlobalScope.launch { loadAsync(context).await()