Skip to content

Commit

Permalink
Fixed Global search regressions
Browse files Browse the repository at this point in the history
- Closes : LawnchairLauncher#4438
- Fixes crash :
java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:221)
	at app.lawnchair.search.algorithms.LawnchairLocalSearchAlgorithm.getResult(LawnchairLocalSearchAlgorithm.kt:179)
	at app.lawnchair.search.algorithms.LawnchairLocalSearchAlgorithm.access$getResult(LawnchairLocalSearchAlgorithm.kt:63)
	at app.lawnchair.search.algorithms.LawnchairLocalSearchAlgorithm$getResult$1.invokeSuspend(Unknown Source:15)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at android.os.Handler.handleCallback(Handler.java:959)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at android.os.Looper.loopOnce(Looper.java:232)
	at android.os.Looper.loop(Looper.java:317)
	at android.app.ActivityThread.main(ActivityThread.java:8501)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@bb7af8b, Dispatchers.Main]
  • Loading branch information
MrSluffy committed Jun 8, 2024
1 parent dfa7645 commit c64e205
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ class LawnchairAppSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm(c
}

if (appResults.size == 1 && context.isDefaultLauncher()) {
val singleAppResult = appResults.first()
val shortcuts = getShortcuts(singleAppResult)
if (shortcuts.isNotEmpty()) {
searchTargets.add(generateSearchTarget.getHeaderTarget(SPACE))
searchTargets.add(createSearchTarget(singleAppResult, true))
searchTargets.addAll(shortcuts.map(::createSearchTarget))
val singleAppResult = appResults.firstOrNull()
val shortcuts = singleAppResult?.let { getShortcuts(it) }
if (shortcuts != null) {
if (shortcuts.isNotEmpty()) {
searchTargets.add(generateSearchTarget.getHeaderTarget(SPACE))
searchTargets.add(createSearchTarget(singleAppResult, true))
searchTargets.addAll(shortcuts.map(::createSearchTarget))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
}

if (appResults.size == 1 && searchApps && context.isDefaultLauncher()) {
val singleAppResult = appResults.first()
val shortcuts = getShortcuts(singleAppResult)
if (shortcuts.isNotEmpty()) {
searchTargets.add(generateSearchTarget.getHeaderTarget(SPACE))
searchTargets.add(createSearchTarget(singleAppResult, true))
searchTargets.addAll(shortcuts.map(::createSearchTarget))
val singleAppResult = appResults.firstOrNull()
val shortcuts = singleAppResult?.let { getShortcuts(it) }
if (shortcuts != null) {
if (shortcuts.isNotEmpty()) {
searchTargets.add(generateSearchTarget.getHeaderTarget(SPACE))
searchTargets.add(createSearchTarget(singleAppResult, true))
searchTargets.addAll(shortcuts.map(::createSearchTarget))
}
}
}

Expand All @@ -176,9 +178,9 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
searchTargets.addAll(suggestions.map { generateSearchTarget.getSuggestionTarget(it.resultData as String) })
}

val calculator = filterByType(localSearchResults, CALCULATOR).first()
val calcData = calculator.resultData as Calculation
if (calcData.isValid) {
val calculator = filterByType(localSearchResults, CALCULATOR).firstOrNull()
val calcData = calculator?.resultData as? Calculation
if (calcData != null && calcData.isValid) {
val calculatorHeader = generateSearchTarget.getHeaderTarget(context.getString(R.string.all_apps_search_result_calculator))
searchTargets.add(calculatorHeader)
searchTargets.add(
Expand Down Expand Up @@ -321,8 +323,12 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
}

val settingsDeferred = async {
findSettingsByNameAndAction(query, maxSettingsEntryCount)
.map { SearchResult(SETTINGS, it) }
if (prefs.searchResultSettingsEntry.get()) {
findSettingsByNameAndAction(query, maxSettingsEntryCount)
.map { SearchResult(SETTINGS, it) }
} else {
emptyList()
}
}

val startPageSuggestionsDeferred = async {
Expand Down

0 comments on commit c64e205

Please sign in to comment.