For #3869 - Creates a SearchLocalizationProvider that sets the region to get the correct default search engine based on a locale

nightly-build-test
Jeff Boek 5 years ago
parent 29402a297e
commit 20993462e9

@ -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()

Loading…
Cancel
Save