Bug 1823085 - NoSuchElementException fix (#1420) (#1688)

* Bug 1823085 - NoSuchElementException fix - the search engines list does not contain any element matching the conditions, so calling first on that list will throw an exception

* Bug 1823085 - NoSuchElementException fix - the search engines list does not contain any element matching the conditions, so calling first on that list will throw an exception

(cherry picked from commit 284d0be312bf95f317f218831530fd044ae0cb03)

Co-authored-by: Alexandra Virvara <127850062+Alexandra-Virvara@users.noreply.github.com>
fenix/112.2.0
mergify[bot] 1 year ago committed by GitHub
parent 2798961b61
commit ee252b35b2

@ -171,16 +171,25 @@ class RadioSearchEngineListPreference @JvmOverloads constructor(
) {
val selectedOrDefaultSearchEngine = context.components.core.store.state.search.selectedOrDefaultSearchEngine
if (selectedOrDefaultSearchEngine == engine) {
val nextSearchEngine = if (context.settings().showUnifiedSearchFeature) {
context.components.core.store.state.search.searchEngines.first {
it.id != engine.id && (it.isGeneral || it.type == SearchEngine.Type.CUSTOM)
}
} else {
context.components.core.store.state.search.searchEngines.first {
it.id != engine.id
val nextSearchEngine =
if (context.settings().showUnifiedSearchFeature) {
context.components.core.store.state.search.searchEngines.firstOrNull {
it.id != engine.id && (it.isGeneral || it.type == SearchEngine.Type.CUSTOM)
}
?: context.components.core.store.state.search.searchEngines.firstOrNull {
it.id != engine.id
}
} else {
context.components.core.store.state.search.searchEngines.firstOrNull {
it.id != engine.id
}
}
nextSearchEngine?.let {
context.components.useCases.searchUseCases.selectSearchEngine(
nextSearchEngine,
)
}
context.components.useCases.searchUseCases.selectSearchEngine(nextSearchEngine)
}
context.components.useCases.searchUseCases.removeSearchEngine(engine)

Loading…
Cancel
Save