mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Improve pop-up item behavior when home screen is locked
Disabled pop-up items (due to home screen being locked) should show again once home screen is unlocked. Doesn't override user-disabled items though. Fixes #5445 Fixes #5265
This commit is contained in:
@@ -47,6 +47,7 @@ import app.lawnchair.theme.color.ColorMode
|
||||
import app.lawnchair.theme.color.ColorOption
|
||||
import app.lawnchair.theme.color.ColorStyle
|
||||
import app.lawnchair.ui.popup.LauncherOptionsPopup
|
||||
import app.lawnchair.ui.popup.toOptionOrderString
|
||||
import app.lawnchair.ui.preferences.components.HiddenAppsInSearch
|
||||
import app.lawnchair.ui.preferences.data.liveinfo.LiveInformationManager
|
||||
import app.lawnchair.util.kotlinxJson
|
||||
@@ -294,11 +295,6 @@ class PreferenceManager2 private constructor(private val context: Context) :
|
||||
val lockHomeScreen = preference(
|
||||
key = booleanPreferencesKey(name = "lock_home_screen"),
|
||||
defaultValue = context.resources.getBoolean(R.bool.config_default_lock_home_screen),
|
||||
onSet = {
|
||||
if (it) {
|
||||
LauncherOptionsPopup.disableUnavailableItems(context)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
val legacyPopupOptionsMigrated = preference(
|
||||
@@ -308,7 +304,7 @@ class PreferenceManager2 private constructor(private val context: Context) :
|
||||
|
||||
val launcherPopupOrder = preference(
|
||||
key = stringPreferencesKey(name = "launcher_popup_order"),
|
||||
defaultValue = LauncherOptionsPopup.DEFAULT_ORDER,
|
||||
defaultValue = LauncherOptionsPopup.DEFAULT_ORDER.toOptionOrderString(),
|
||||
onSet = { reloadHelper.reloadGrid() },
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package app.lawnchair.ui.popup
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
@@ -14,25 +13,15 @@ import com.patrykmichalik.opto.core.firstBlocking
|
||||
import com.patrykmichalik.opto.core.setBlocking
|
||||
|
||||
object LauncherOptionsPopup {
|
||||
const val DEFAULT_ORDER = "+carousel|-lock|-edit_mode|+wallpaper|+widgets|+home_settings|-sys_settings"
|
||||
|
||||
fun disableUnavailableItems(
|
||||
context: Context,
|
||||
) {
|
||||
val prefs2 = getInstance(context)
|
||||
val optionOrder = prefs2.launcherPopupOrder.firstBlocking()
|
||||
|
||||
prefs2.launcherPopupOrder.setBlocking(
|
||||
optionOrder.split("|")
|
||||
.joinToString("|") { item ->
|
||||
when (item) {
|
||||
"+edit_mode" -> "-edit_mode"
|
||||
"+widgets" -> "-widgets"
|
||||
else -> item
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
val DEFAULT_ORDER = listOf(
|
||||
LauncherOptionPopupItem("carousel", true),
|
||||
LauncherOptionPopupItem("lock", false),
|
||||
LauncherOptionPopupItem("edit_mode", false),
|
||||
LauncherOptionPopupItem("wallpaper", true),
|
||||
LauncherOptionPopupItem("widgets", true),
|
||||
LauncherOptionPopupItem("home_settings", true),
|
||||
LauncherOptionPopupItem("sys_settings", false),
|
||||
)
|
||||
|
||||
fun restoreMissingPopupOptions(
|
||||
launcher: Launcher,
|
||||
@@ -40,12 +29,10 @@ object LauncherOptionsPopup {
|
||||
val prefs2 = getInstance(launcher)
|
||||
|
||||
val currentOrder = prefs2.launcherPopupOrder.firstBlocking()
|
||||
|
||||
val defaultOptions = DEFAULT_ORDER.toLauncherOptions()
|
||||
val currentOptions = currentOrder.toLauncherOptions()
|
||||
|
||||
// check for missing items in current options; if so, add them
|
||||
val missingItems = defaultOptions.filter { defaultItem ->
|
||||
val missingItems = DEFAULT_ORDER.filter { defaultItem ->
|
||||
defaultItem.identifier !in currentOptions.map { it.identifier }
|
||||
}
|
||||
|
||||
@@ -68,7 +55,8 @@ object LauncherOptionsPopup {
|
||||
): ArrayList<OptionItem> {
|
||||
val prefs2 = getInstance(launcher!!)
|
||||
val lockHomeScreen = prefs2.lockHomeScreen.firstBlocking()
|
||||
val optionOrder = prefs2.launcherPopupOrder.firstBlocking()
|
||||
val optionOrder = prefs2
|
||||
.launcherPopupOrder.firstBlocking().toLauncherOptions()
|
||||
|
||||
val wallpaperResString =
|
||||
if (Utilities.existsStyleWallpapers(launcher)) R.string.styles_wallpaper_button_text else R.string.wallpapers
|
||||
@@ -121,18 +109,19 @@ object LauncherOptionsPopup {
|
||||
)
|
||||
|
||||
val options = ArrayList<OptionItem>()
|
||||
optionOrder.split("|").forEach { item ->
|
||||
val (identifier, isEnabled) = when {
|
||||
item.startsWith("+") -> item.drop(1) to true
|
||||
item.startsWith("-") -> item.drop(1) to false
|
||||
else -> item to true // Default to enabled if no prefix
|
||||
optionOrder
|
||||
.filter {
|
||||
(it.isEnabled && it.identifier != "carousel")
|
||||
}
|
||||
if (isEnabled && identifier != "carousel") {
|
||||
optionsList[identifier]?.let { option ->
|
||||
options.add(option)
|
||||
.filter {
|
||||
if (lockHomeScreen) {
|
||||
it.identifier != "edit_mode" && it.identifier != "widgets"
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
.mapNotNull { optionsList[it.identifier] }
|
||||
.forEach { options.add(it) }
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ fun LauncherPopupPreference(
|
||||
DraggablePreferenceGroup(
|
||||
label = stringResource(R.string.popup_menu_items),
|
||||
items = optionsList,
|
||||
defaultList = LauncherOptionsPopup.DEFAULT_ORDER.toLauncherOptions(),
|
||||
defaultList = LauncherOptionsPopup.DEFAULT_ORDER,
|
||||
onOrderChange = {
|
||||
optionsList = it
|
||||
optionsPref.onChange(it.toOptionOrderString())
|
||||
@@ -106,7 +106,7 @@ fun LauncherPopupPreference(
|
||||
DraggableSwitchPreference(
|
||||
label = stringResource(metadata.label),
|
||||
description = if (!enabled && item.identifier != "home_settings") stringResource(R.string.home_screen_locked) else null,
|
||||
checked = item.isEnabled,
|
||||
checked = if (!enabled && item.identifier != "home_settings") false else item.isEnabled,
|
||||
onCheckedChange = {
|
||||
optionsList[index].isEnabled = it
|
||||
optionsPref.onChange(optionsList.toOptionOrderString())
|
||||
|
||||
Reference in New Issue
Block a user