For #6849 - Properly select a new default search engine when you delete the current one
Co-authored-by: Severin Rudie <Baron-Severin@users.noreply.github.com>master
parent
eb6e6b774f
commit
781b141bc7
|
@ -18,6 +18,7 @@ import mozilla.components.browser.search.provider.SearchEngineProvider
|
||||||
import mozilla.components.browser.search.provider.filter.SearchEngineFilter
|
import mozilla.components.browser.search.provider.filter.SearchEngineFilter
|
||||||
import mozilla.components.browser.search.provider.localization.LocaleSearchLocalizationProvider
|
import mozilla.components.browser.search.provider.localization.LocaleSearchLocalizationProvider
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
@SuppressWarnings("TooManyFunctions")
|
@SuppressWarnings("TooManyFunctions")
|
||||||
class FenixSearchEngineProvider(
|
class FenixSearchEngineProvider(
|
||||||
|
@ -49,7 +50,7 @@ class FenixSearchEngineProvider(
|
||||||
val engines = installedSearchEngines(context)
|
val engines = installedSearchEngines(context)
|
||||||
val selectedName = context.settings().defaultSearchEngineName
|
val selectedName = context.settings().defaultSearchEngineName
|
||||||
|
|
||||||
return engines.list.find { it.name == selectedName } ?: engines.list.first()
|
return engines.list.find { it.name == selectedName } ?: engines.default ?: engines.list.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun installedSearchEngines(context: Context): SearchEngineList = runBlocking {
|
fun installedSearchEngines(context: Context): SearchEngineList = runBlocking {
|
||||||
|
@ -59,7 +60,7 @@ class FenixSearchEngineProvider(
|
||||||
engineList.copy(
|
engineList.copy(
|
||||||
list = engineList.list.filter {
|
list = engineList.list.filter {
|
||||||
installedIdentifiers.contains(it.identifier)
|
installedIdentifiers.contains(it.identifier)
|
||||||
},
|
}.sortedBy { it.name.toLowerCase(Locale.getDefault()) },
|
||||||
default = engineList.default?.let {
|
default = engineList.default?.let {
|
||||||
if (installedIdentifiers.contains(it.identifier)) {
|
if (installedIdentifiers.contains(it.identifier)) {
|
||||||
it
|
it
|
||||||
|
|
Loading…
Reference in New Issue