Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #3869 - Creates a SearchLocalizationProvider that sets the region…
Browse files Browse the repository at this point in the history
… to get the correct default search engine based on a locale
  • Loading branch information
boek authored and st3fan committed Jul 4, 2019
1 parent e70ef3c commit f459908
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/src/main/java/org/mozilla/fenix/components/Search.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,27 @@ import android.content.Context
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.
Expand All @@ -21,7 +40,9 @@ class Search(private val context: Context) {
* This component provides access to a centralized registry of search engines.
*/
val searchEngineManager by lazy {
SearchEngineManager().apply {
SearchEngineManager(coroutineContext = IO, providers = listOf(
AssetsSearchEngineProvider(FenixLocaleSearchLocalizationProvider())
)).apply {
registerForLocaleUpdates(context)
GlobalScope.launch {
loadAsync(context).await()
Expand Down

0 comments on commit f459908

Please sign in to comment.