Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upstream' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Feb 2, 2024
2 parents b14e999 + aa431cf commit f34627d
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 75 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version "1.9.22"
id "com.google.devtools.ksp" version "1.9.22-1.0.17"
id 'com.google.protobuf' version "0.9.4"
id 'app.cash.licensee' version "1.8.0"
id 'app.cash.licensee' version "1.9.0"
id 'dev.rikka.tools.refine' version "4.4.0"
id 'org.gradle.android.cache-fix' version '3.0'
id 'com.diffplug.spotless' version '6.25.0'
Expand Down Expand Up @@ -362,7 +362,7 @@ dependencies {
implementation "com.google.accompanist:accompanist-insets-ui:$accompanistVersion"
implementation "com.google.accompanist:accompanist-permissions:$accompanistVersion"
implementation "com.google.android.material:material:1.11.0"
implementation "io.github.fornewid:material-motion-compose-core:1.1.1"
implementation "io.github.fornewid:material-motion-compose-core:1.2.0"
implementation 'dev.kdrag0n:colorkt:1.0.5'
implementation 'io.coil-kt:coil-compose:2.5.0'
implementation 'me.xdrop:fuzzywuzzy:1.4.0'
Expand Down
3 changes: 3 additions & 0 deletions lawnchair/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
<bool name="config_default_smartspace_show_date">true</bool>
<bool name="config_default_smartspace_show_time">false</bool>
<bool name="config_default_perform_wide_search">true</bool>
<bool name="config_default_enable_dot_pagination">true</bool>
<bool name="config_default_enable_material_u_popup">true</bool>

<item name="config_default_home_icon_size_factor" type="dimen" format="float">1.0</item>
<item name="config_default_folder_preview_background_opacity" type="dimen" format="float">1.0</item>
Expand All @@ -128,6 +130,7 @@
<item name="config_default_suggestion_max_result_count" type="dimen" format="integer">3</item>
<item name="config_default_settings_entry_max_result_count" type="dimen" format="integer">5</item>
<item name="config_default_recent_max_result_count" type="dimen" format="integer">2</item>
<item name="config_default_max_web_suggestion_delay" type="dimen" format="integer">200</item>
<item name="config_default_hotseat_bottom_factor" type="dimen" format="float">1.0</item>


Expand Down
10 changes: 9 additions & 1 deletion lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@
<string name="home_screen_lock_description">Prevents changes to the home screen layout.</string>
<string name="home_screen_unlock">Unlock Home Screen</string> <!-- used in popup menu-->
<string name="home_screen_locked">Home Screen is locked.</string>
<string name="show_dot_pagination_label">Show dot pagination</string>
<string name="show_dot_pagination_description">Enable showing dot pagination in workspace.</string>
<string name="show_material_u_popup_label">Show Material U Popup</string>
<string name="show_material_u_popup_description">Enable bouncy and slightly consolidated popup.</string>


<string name="popup_menu">Pop-up Menu</string>
<string name="home_screen_lock_toggle_from_home_popup">Show Lock Button</string>
Expand Down Expand Up @@ -347,8 +352,10 @@
<string name="max_suggestion_result_count_title">Max Suggestion Result Count</string>
<string name="max_settings_entry_result_count_title">Max Settings Entry Result Count</string>
<string name="max_recent_result_count_title">Max History Result Count</string>
<string name="max_web_suggestion_delay">Max Web Suggestion Delay</string>


<string name="clear_history">Clear</string>
<string name="clear_history">Clear</string>


<!-- <string name="grid" /> -->
Expand All @@ -358,6 +365,7 @@

<string name="perform_wide_search_title">Device Search</string>
<string name="perform_wide_search_file">Files</string>
<string name="pref_suggestion_label">Suggestions</string>
<string name="pref_suggestion_title">Web suggestions (via <xliff:g id="startpage">Startpage</xliff:g>)</string>
<string name="pref_advance_search_category">Advanced Search</string>
<string name="perform_wide_search_description">Search your contacts, files, and settings in app drawer search.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import app.lawnchair.util.AppInfo
import app.lawnchair.util.AppInfoHelper
import app.lawnchair.util.ImageViewWrapper
import com.android.app.search.LayoutType
import com.android.launcher3.DeviceProfile
import com.android.launcher3.R

class SearchResultRightLeftIcon(context: Context, attrs: AttributeSet?) :
LinearLayout(context, attrs), SearchResultView {

private val launcher = context.launcher
private var grid: DeviceProfile = launcher.deviceProfile
private lateinit var title: TextView
private lateinit var avatar: SearchResultIcon
private lateinit var call: ImageView
Expand Down Expand Up @@ -66,7 +68,7 @@ class SearchResultRightLeftIcon(context: Context, attrs: AttributeSet?) :
LayoutParams.MATCH_PARENT,
heightRes,
)
val horizontalMargin = 48
val horizontalMargin = grid.allAppsLeftRightMargin
layoutParams.leftMargin = horizontalMargin
layoutParams.rightMargin = horizontalMargin
this.layoutParams = layoutParams
Expand Down
5 changes: 3 additions & 2 deletions lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class PreferenceManager private constructor(private val context: Context) : Base
val fontBody = FontPref("pref_fontBody", fontCache.uiText, recreate)
val fontBodyMedium = FontPref("pref_fontBodyMedium", fontCache.uiTextMedium, recreate)

val deviceSearch = BoolPref("device_search", true, recreate)
val searchResultShortcuts = BoolPref("pref_searchResultShortcuts", true)
// TODO REMOVE
val deviceSearch = BoolPref("device_search", false, recreate)
val searchResultShortcuts = BoolPref("pref_searchResultShortcuts", false)
val searchResultPeople = BoolPref("pref_searchResultPeople", false, recreate)
val searchResultPixelTips = BoolPref("pref_searchResultPixelTips", false)
val searchResultSettings = BoolPref("pref_searchResultSettings", false)
Expand Down
17 changes: 17 additions & 0 deletions lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre
defaultValue = resourceProvider.getInt(R.dimen.config_default_people_max_result_count),
)

val maxWebSuggestionDelay = preference(
key = intPreferencesKey(name = "max_web_suggestion_delay"),
defaultValue = resourceProvider.getInt(R.dimen.config_default_max_web_suggestion_delay),
)

val maxSettingsEntryResultCount = preference(
key = intPreferencesKey(name = "max_settings_entry_result_count"),
defaultValue = resourceProvider.getInt(R.dimen.config_default_settings_entry_max_result_count),
Expand All @@ -395,6 +400,18 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre
onSet = { reloadHelper.restart() },
)

val enableDotPagination = preference(
key = booleanPreferencesKey(name = "enable_dot_pagination"),
defaultValue = context.resources.getBoolean(R.bool.config_default_enable_dot_pagination),
onSet = { reloadHelper.recreate() },
)

val enableMaterialUPopUp = preference(
key = booleanPreferencesKey(name = "enable_material_u_popup"),
defaultValue = context.resources.getBoolean(R.bool.config_default_enable_material_u_popup),
onSet = { reloadHelper.recreate() },
)

val enableFeed = preference(
key = booleanPreferencesKey(name = "enable_feed"),
defaultValue = context.resources.getBoolean(R.bool.config_default_enable_feed),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import app.lawnchair.allapps.SearchResultView
import app.lawnchair.allapps.SearchResultView.Companion.EXTRA_QUICK_LAUNCH
import app.lawnchair.search.data.SearchResultActionCallBack
import com.android.app.search.LayoutType
import com.android.launcher3.DeviceProfile
import com.android.launcher3.R
import com.android.launcher3.allapps.ActivityAllAppsContainerView
import com.android.launcher3.allapps.AllAppsGridAdapter
Expand Down Expand Up @@ -68,9 +69,10 @@ class LawnchairSearchAdapterProvider(
): BaseAllAppsAdapter.ViewHolder {
val view = layoutInflater.inflate(layoutIdMap[viewType], parent, false)

val grid: DeviceProfile = mLauncher.deviceProfile
if (viewType != SEARCH_RESULT_ICON) {
val layoutParams = ViewGroup.MarginLayoutParams(view.layoutParams)
val horizontalMargin = 48
val horizontalMargin = grid.allAppsLeftRightMargin
layoutParams.leftMargin = horizontalMargin
layoutParams.rightMargin = horizontalMargin
view.layoutParams = layoutParams
Expand Down
57 changes: 37 additions & 20 deletions lawnchair/src/app/lawnchair/search/LawnchairSearchAlgorithm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.async
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import kotlinx.coroutines.withTimeoutOrNull

sealed class LawnchairSearchAlgorithm(
protected val context: Context,
Expand Down Expand Up @@ -167,6 +167,7 @@ sealed class LawnchairSearchAlgorithm(
private var maxFilesCount = 3
private var maxSettingsEntryCount = 5
private var maxRecentResultCount = 2
private var maxWebSuggestionDelay = 200
val coroutineScope = CoroutineScope(context = Dispatchers.IO)
val pref2 = PreferenceManager2.getInstance(context)

Expand All @@ -186,41 +187,52 @@ sealed class LawnchairSearchAlgorithm(
pref2.maxRecentResultCount.onEach(launchIn = coroutineScope) {
maxRecentResultCount = it
}
pref2.maxWebSuggestionDelay.onEach(launchIn = coroutineScope) {
maxWebSuggestionDelay = it
}
}

protected suspend fun performDeviceWideSearch(query: String, prefs: PreferenceManager): MutableList<SearchResult> = withContext(Dispatchers.IO) {
val results = ArrayList<SearchResult>()

if (prefs.searchResultPeople.get()) {
if (requestContactPermissionGranted(context, prefs)) {
val contactResults = findContactsByName(context, query, maxPeopleCount)
results.addAll(contactResults.map { SearchResult(CONTACT, it) })
val contactDeferred = async {
if (prefs.searchResultPeople.get() && requestContactPermissionGranted(context, prefs)) {
findContactsByName(context, query, maxPeopleCount)
.map { SearchResult(CONTACT, it) }
} else {
emptyList()
}
}

if (prefs.searchResultFiles.get()) {
if (checkAndRequestFilesPermission(context, prefs)) {
val fileResults = queryFilesInMediaStore(context, keyword = query, maxResult = maxFilesCount).toList()
results.addAll(fileResults.map { SearchResult(FILES, it) })
val filesDeferred = async {
if (prefs.searchResultFiles.get() && checkAndRequestFilesPermission(context, prefs)) {
queryFilesInMediaStore(context, keyword = query, maxResult = maxFilesCount)
.toList()
.map { SearchResult(FILES, it) }
} else {
emptyList()
}
}

if (prefs.searchResultSettingsEntry.get()) {
val settingResult = findSettingsByNameAndAction(query, maxSettingsEntryCount)
results.addAll(settingResult.map { SearchResult(SETTING, it) })
val settingsDeferred = async {
findSettingsByNameAndAction(query, maxSettingsEntryCount)
.map { SearchResult(SETTING, it) }
}

if (prefs.searchResultStartPageSuggestion.get()) {
val startPageSuggestions = async {
try {
withTimeout(3000) {
getStartPageSuggestions(query, maxSuggestionCount)
val startPageSuggestionsDeferred = async {
try {
val timeout = maxWebSuggestionDelay.toLong()
val result = withTimeoutOrNull(timeout) {
if (prefs.searchResultStartPageSuggestion.get()) {
getStartPageSuggestions(query, maxSuggestionCount).map { SearchResult(SUGGESTION, it) }
} else {
emptyList()
}
} catch (e: TimeoutCancellationException) {
emptyList()
}
result ?: emptyList()
} catch (e: TimeoutCancellationException) {
emptyList()
}
results.addAll(startPageSuggestions.await().map { SearchResult(SUGGESTION, it) })
}

if (prefs.searchResulRecentSuggestion.get()) {
Expand All @@ -244,6 +256,11 @@ sealed class LawnchairSearchAlgorithm(
)
}

results.addAll(contactDeferred.await())
results.addAll(filesDeferred.await())
results.addAll(settingsDeferred.await())
results.addAll(startPageSuggestionsDeferred.await())

results
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fun SliderPreference(
valueRange: ClosedRange<Int>,
step: Int,
showAsPercentage: Boolean = false,
showUnit: String = "",
) {
val transformedAdapter = rememberTransformAdapter(
adapter = adapter,
Expand All @@ -65,6 +66,7 @@ fun SliderPreference(
valueRange = start..endInclusive,
step = step.toFloat(),
showAsPercentage = showAsPercentage,
showUnit = showUnit,
)
}

Expand All @@ -75,6 +77,7 @@ fun SliderPreference(
valueRange: ClosedFloatingPointRange<Float>,
step: Float,
showAsPercentage: Boolean = false,
showUnit: String = "",
) {
var adapterValue by adapter
var sliderValue by remember { mutableFloatStateOf(adapterValue) }
Expand Down Expand Up @@ -105,9 +108,9 @@ fun SliderPreference(
stringResource(
id = R.string.n_percent,
(value * 100).roundToInt(),
)
) + " $showUnit"
} else {
value.roundToInt().toString()
value.roundToInt().toString() + " $showUnit"
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,28 @@ fun AppDrawerPreferences() {
}

ExpandAndShrink(visible = showDrawerSearchBar.state.value) {
PreferenceGroup {
PreferenceGroup(heading = stringResource(id = R.string.pref_suggestion_label)) {
DividerColumn {
SwitchPreference(
adapter = prefs.searchResultStartPageSuggestion.getAdapter(),
label = stringResource(id = R.string.pref_suggestion_title),
)
ExpandAndShrink(visible = prefs.searchResultStartPageSuggestion.getAdapter().state.value) {
SliderPreference(
label = stringResource(id = R.string.max_suggestion_result_count_title),
adapter = prefs2.maxSuggestionResultCount.getAdapter(),
step = 1,
valueRange = 3..10,
)
DividerColumn {
SliderPreference(
label = stringResource(id = R.string.max_suggestion_result_count_title),
adapter = prefs2.maxSuggestionResultCount.getAdapter(),
step = 1,
valueRange = 3..10,
)
SliderPreference(
label = stringResource(id = R.string.max_web_suggestion_delay),
adapter = prefs2.maxWebSuggestionDelay.getAdapter(),
step = 100,
valueRange = 200..5000,
showUnit = "ms",
)
}
}
SwitchPreference(
adapter = prefs.searchResulRecentSuggestion.getAdapter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import app.lawnchair.ui.preferences.components.controls.ClickablePreference
import app.lawnchair.ui.preferences.components.controls.ListPreference
import app.lawnchair.ui.preferences.components.controls.SliderPreference
import app.lawnchair.ui.preferences.components.controls.SwitchPreference
import app.lawnchair.ui.preferences.components.layout.DividerColumn
import app.lawnchair.ui.preferences.components.layout.ExpandAndShrink
import app.lawnchair.ui.preferences.components.layout.PreferenceGroup
import app.lawnchair.ui.preferences.components.layout.PreferenceLayout
Expand Down Expand Up @@ -114,13 +115,25 @@ fun HomeScreenPreferences() {
destination = subRoute(name = HomeScreenRoutes.GRID),
subtitle = stringResource(id = R.string.x_by_y, columns, rows),
)
SwitchPreference(
adapter = lockHomeScreenAdapter,
label = stringResource(id = R.string.home_screen_lock),
description = stringResource(id = R.string.home_screen_lock_description),
)
DividerColumn {
SwitchPreference(
adapter = lockHomeScreenAdapter,
label = stringResource(id = R.string.home_screen_lock),
description = stringResource(id = R.string.home_screen_lock_description),
)
SwitchPreference(
adapter = prefs2.enableDotPagination.getAdapter(),
label = stringResource(id = R.string.show_dot_pagination_label),
description = stringResource(id = R.string.show_dot_pagination_description),
)
}
}
PreferenceGroup(heading = stringResource(id = R.string.popup_menu)) {
SwitchPreference(
adapter = prefs2.enableMaterialUPopUp.getAdapter(),
label = stringResource(id = R.string.show_material_u_popup_label),
description = stringResource(id = R.string.show_material_u_popup_description),
)
SwitchPreference(
adapter = prefs2.lockHomeScreenButtonOnPopUp.getAdapter(),
label = stringResource(id = R.string.home_screen_lock_toggle_from_home_popup),
Expand Down
Loading

0 comments on commit f34627d

Please sign in to comment.