Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@
<string name="search_provider_brave" translatable="false">Brave</string>
<string name="search_provider_github" translatable="false">GitHub</string>
<string name="search_provider_youtube" translatable="false">YouTube</string>
<string name="search_provider_pixel_search" translatable="false">Pixel Search</string>
<string name="search_provider_pixel_search" translatable="false">Pixel Search (third-party)</string>
<string name="search_provider_yandex" translatable="false">Yandex</string>
<string name="search_provider_fennec" translatable="false">Fennec</string>
<string name="search_provider_firefox" translatable="false">Firefox</string>
Expand Down
28 changes: 2 additions & 26 deletions android/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ import android.util.AttributeSet
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.ViewTreeObserver
import android.view.ViewTreeObserver.OnGlobalFocusChangeListener
import android.view.animation.DecelerateInterpolator
import android.widget.FrameLayout
import android.widget.TextView
import androidx.compose.animation.core.animateIntAsState
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -203,26 +200,6 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) :
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)

setContent {
var isFocused by remember(input) { mutableStateOf(input.hasFocus()) }

// Yes, this is a bit hacky, but it's the only way to ensure that
// we can check if the input has focus in Compose without wrestling
// with multiple global variables or state changes
DisposableEffect(input) {
val focusListener = OnGlobalFocusChangeListener { _, _ ->
isFocused = input.hasFocus()
}

val observer = input.viewTreeObserver
observer.addOnGlobalFocusChangeListener(focusListener)

onDispose {
if (observer.isAlive) {
observer.removeOnGlobalFocusChangeListener(focusListener)
}
}
}

val searchProviderPref by prefs2.hotseatQsbProvider.asState()
val searchProvider = remember(searchProviderPref, context) {
getSearchProvider(context, searchProviderPref)
Expand Down Expand Up @@ -253,9 +230,8 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) :
ColorTokens.SearchboxHighlight.resolveColor(context)
}

val backgroundAlpha by animateIntAsState(
if (isFocused || !queryEmpty) 0 else 100,
)
// Keep the pill visible while focused or typing, as Pixel does.
val backgroundAlpha = 100

// Ignore other theme attributes to preserve existing behavior
val style = buildQsbStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class PreferenceManager @Inject constructor(
val searchResultPeople = BoolPref("pref_searchResultPeople", false, recreate)
val searchResultPixelTips = BoolPref("pref_searchResultPixelTips", false)
val searchResultSettings = BoolPref("pref_searchResultSettings", false)
val searchResultCalculator = BoolPref("pref_searchResultCalculator", false)
val searchResultCalculator = BoolPref("pref_searchResultCalculator", true)

val searchResultApps = BoolPref("pref_searchResultApps", true, recreate)
val searchResultFilesToggle = BoolPref("pref_searchResultFiles", false, recreate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

Expand Down Expand Up @@ -68,17 +70,22 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm

currentJob?.cancel()
currentJob = coroutineScope.launch {
val calcResult = CalculatorSearchProvider.search(context, query)
.firstOrNull()
.orEmpty()
val actionResults = generateActionResults(query)

// Seed every provider with an empty result so apps, shortcuts and calculations
// show as soon as they are ready. Without the seed, combine() waits for the
// slowest provider (web suggestions go over the network) before the first frame.
val nonAppProvidersFlow = combine(
searchProviders.map { it.search(context, query) },
searchProviders.map { it.search(context, query).onStart { emit(emptyList()) } },
) { resultsArray ->
resultsArray.toList().flatten()
}

nonAppProvidersFlow.collect { nonAppResults ->
val calcResult = CalculatorSearchProvider.search(context, query)
.firstOrNull()

val allResults = appResults + shortcutResults + (calcResult ?: emptyList()) + nonAppResults + generateActionResults(query)
nonAppProvidersFlow.collectLatest { nonAppResults ->
val allResults = appResults + shortcutResults + calcResult + nonAppResults + actionResults

val searchTargets = translateToSearchTargets(query, allResults)
setFirstItemQuickLaunch(searchTargets)
Expand Down
Loading