diff --git a/lawnchair/res/values/strings.xml b/lawnchair/res/values/strings.xml
index 5c2e433d11..b8778a49eb 100644
--- a/lawnchair/res/values/strings.xml
+++ b/lawnchair/res/values/strings.xml
@@ -231,8 +231,8 @@
Material 3 Expressive
Enable Material 3 Expressive changes in workspace
- Customizable folder shape
- Folder
+ Folder shape
+ Folder
App
Use GestureNavContract API
@@ -340,6 +340,9 @@
Custom icon shape
Create custom icon shape
Edit custom icon shape
+ Custom folder shape
+ Create custom folder shape
+ Edit custom folder shape
Corner shape
Round
Smooth
diff --git a/lawnchair/src/app/lawnchair/icons/LawnchairThemeManager.kt b/lawnchair/src/app/lawnchair/icons/LawnchairThemeManager.kt
index 8920198163..d3d613c727 100644
--- a/lawnchair/src/app/lawnchair/icons/LawnchairThemeManager.kt
+++ b/lawnchair/src/app/lawnchair/icons/LawnchairThemeManager.kt
@@ -61,6 +61,8 @@ constructor(
merge(
prefs2.iconShape.get(),
prefs2.customIconShape.get(),
+ prefs2.folderShape.get(),
+ prefs2.customFolderShape.get(),
).onEach { verifyIconState() }
.launchIn(scope)
@@ -93,30 +95,31 @@ constructor(
val currentFolderShape: IconShape = try {
prefs2.folderShape.firstBlocking()
} catch (e: Exception) {
- Log.d(TAG, "Error getting icon shape", e)
+ Log.d(TAG, "Error getting folder shape", e)
IconShape.Circle
}
val currentPrefs1State = prefs1State()
val appShapeKey = currentAppShape.getHashString() + currentPrefs1State
val folderShapeKey = currentFolderShape.getHashString() + currentPrefs1State
+ val combinedKey = "$appShapeKey:$folderShapeKey"
val appShape =
- if (oldState != null && oldState.iconMask == appShapeKey) {
+ if (oldState != null && (oldState.iconShape as? PathShapeDelegate)?.iconShape == currentAppShape) {
oldState.iconShape
} else {
PathShapeDelegate(currentAppShape)
}
val folderShape =
- if (oldState != null && oldState.iconMask == folderShapeKey) {
- oldState.iconShape
+ if (oldState != null && (oldState.folderShape as? PathShapeDelegate)?.iconShape == currentFolderShape) {
+ oldState.folderShape
} else {
PathShapeDelegate(currentFolderShape)
}
return IconState(
- iconMask = appShapeKey,
+ iconMask = combinedKey,
folderRadius = 1f,
shapeRadius = 1f,
themeController = iconControllerFactory.createThemeController(),
diff --git a/lawnchair/src/app/lawnchair/icons/shape/IconShape.kt b/lawnchair/src/app/lawnchair/icons/shape/IconShape.kt
index f16348243f..a336f5b50f 100644
--- a/lawnchair/src/app/lawnchair/icons/shape/IconShape.kt
+++ b/lawnchair/src/app/lawnchair/icons/shape/IconShape.kt
@@ -282,6 +282,8 @@ sealed class IconShape {
// Format: v1||||
override fun toString(): String = "v$version|$topLeft|$topRight|$bottomLeft|$bottomRight"
+ override fun getHashString(): String = toString()
+
companion object {
/** Parses [value], returning null for invalid or unsupported serialized input. */
fun fromStringOrNull(value: String): CustomCornerBased? {
diff --git a/lawnchair/src/app/lawnchair/icons/shape/PathShapeDelegate.kt b/lawnchair/src/app/lawnchair/icons/shape/PathShapeDelegate.kt
index 1c24811ef1..a02fff1500 100644
--- a/lawnchair/src/app/lawnchair/icons/shape/PathShapeDelegate.kt
+++ b/lawnchair/src/app/lawnchair/icons/shape/PathShapeDelegate.kt
@@ -31,7 +31,7 @@ import com.android.launcher3.views.ClipPathView
* when the IconShape provides an SVG path string. The shape is assumed
* to be defined within a [0, 0, 100, 100] viewport.
*/
-data class PathShapeDelegate(private val iconShape: IconShape) : ShapeDelegate {
+data class PathShapeDelegate(val iconShape: IconShape) : ShapeDelegate {
private val basePath: Path = iconShape.getMaskPath()
private val tmpPath = Path()
diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt
index 8ecf28456f..620e6f6a63 100644
--- a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt
+++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt
@@ -164,6 +164,19 @@ class PreferenceManager2 @Inject constructor(
onSet = { it?.let(iconShape::setBlocking) },
)
+ val customFolderShape = preference(
+ key = stringPreferencesKey(name = "custom_folder_shape"),
+ defaultValue = null,
+ parse = {
+ IconShape.CustomCornerBased.fromStringOrNull(value = it)
+ ?: IconShape.CustomCornerBased(
+ IconShapeManager.getSystemIconShape(context).findNearestShape(),
+ )
+ },
+ save = { it.toString() },
+ onSet = { it?.let(folderShape::setBlocking) },
+ )
+
val alwaysReloadIcons = preference(
key = booleanPreferencesKey(name = "always_reload_icons"),
defaultValue = context.resources.getBoolean(R.bool.config_default_always_reload_icons),
@@ -423,12 +436,6 @@ class PreferenceManager2 @Inject constructor(
},
)
- val enableFolderIconShapeCustomization = preference(
- key = booleanPreferencesKey(name = "enable_folder_icon_shape_customization"),
- defaultValue = context.resources.getBoolean(R.bool.config_default_enable_folder_icon_shape_customization),
- onSet = { reloadHelper.reloadIcons() },
- )
-
val autoShowKeyboardInDrawer = preference(
key = booleanPreferencesKey(name = "auto_show_keyboard_in_drawer"),
defaultValue = context.resources.getBoolean(R.bool.config_default_auto_show_keyboard_in_drawer),
diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/CustomIconShapePreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/CustomIconShapePreference.kt
index fb90994f89..240e354ac0 100644
--- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/CustomIconShapePreference.kt
+++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/CustomIconShapePreference.kt
@@ -63,13 +63,17 @@ import kotlin.toString
@Composable
fun CustomIconShapePreference(
modifier: Modifier = Modifier,
+ currentTab: ShapeRoute = ShapeRoute.APP_SHAPE,
) {
val preferenceManager2 = preferenceManager2()
- val customIconShapeAdapter = preferenceManager2.customIconShape.getAdapter()
+ val customIconShapeAdapter = when (currentTab) {
+ ShapeRoute.APP_SHAPE -> preferenceManager2.customIconShape.getAdapter()
+ ShapeRoute.FOLDER_SHAPE -> preferenceManager2.customFolderShape.getAdapter()
+ }
val appliedIconShape = customIconShapeAdapter.state.value
- val selectedIconShape = remember {
+ val selectedIconShape = remember(currentTab) {
mutableStateOf(IconShape.CustomCornerBased(appliedIconShape ?: IconShape.Circle))
}
@@ -80,8 +84,13 @@ fun CustomIconShapePreference(
}
}
+ val label = when (currentTab) {
+ ShapeRoute.APP_SHAPE -> stringResource(id = R.string.custom_icon_shape)
+ ShapeRoute.FOLDER_SHAPE -> stringResource(id = R.string.custom_folder_shape)
+ }
+
PreferenceLayout(
- label = stringResource(id = R.string.custom_icon_shape),
+ label = label,
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally,
bottomBar = {
diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/ExperimentalFeaturesPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/ExperimentalFeaturesPreferences.kt
index 3e0802ba19..ce314e4e1b 100644
--- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/ExperimentalFeaturesPreferences.kt
+++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/ExperimentalFeaturesPreferences.kt
@@ -72,49 +72,6 @@ fun ExperimentalFeaturesPreferences(
Modifier,
stringResource(R.string.workspace_label),
) {
- Item {
- // LC-Note: The feature is pretty much ready,
- // we just need some minor UI planning then we should be good to promote the feature
- // to stable.
- val getFolderIconShapeCustomizationAdapter = prefs2.enableFolderIconShapeCustomization.getAdapter()
- val enableFolderIconShapeCustomizationAdapter = remember(prefs2) {
- getFolderIconShapeCustomizationAdapter
- }
-
- val folderShapeAdapter = prefs2.folderShape.getAdapter()
- val folderShapeDefault = prefs2.folderShape.defaultValue
-
- val enabled = enableFolderIconShapeCustomizationAdapter.state.value
-
- NavigationActionPreference(
- label = stringResource(id = R.string.experimental_folder_shape_modify_label),
- destination = if (enabled) GeneralIconShape(ShapeRoute.FOLDER_SHAPE) else null,
- subtitle = folderIconShapeSubtitle,
- endWidget = {
- if (enabled) {
- VerticalDivider(modifier = Modifier.padding(horizontal = 16.dp))
- }
- Switch(
- checked = enabled,
- onCheckedChange = {
- mMSDLPlayerWrapper.playToken(if (it) MSDLToken.SWITCH_ON else MSDLToken.SWITCH_OFF)
- enableFolderIconShapeCustomizationAdapter.onChange(it)
- // Clean-up when user disables folder shape customisation.
- if (!it) {
- folderShapeAdapter.onChange(folderShapeDefault)
- }
- },
- thumbContent = {
- Icon(
- imageVector = if (enabled) Icons.Filled.Check else Icons.Filled.Close,
- contentDescription = null,
- modifier = Modifier.size(SwitchDefaults.IconSize),
- )
- },
- )
- },
- )
- }
Item {
SwitchPreference(
adapter = prefs2.enableFontSelection.getAdapter(),
diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/FolderPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/FolderPreferences.kt
index 693212d922..4e85ba1372 100644
--- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/FolderPreferences.kt
+++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/FolderPreferences.kt
@@ -18,16 +18,19 @@ package app.lawnchair.ui.preferences.destinations
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import app.lawnchair.preferences.getAdapter
import app.lawnchair.preferences.preferenceManager
import app.lawnchair.preferences2.preferenceManager2
import app.lawnchair.ui.preferences.LocalIsExpandedScreen
+import app.lawnchair.ui.preferences.components.NavigationActionPreference
import app.lawnchair.ui.preferences.components.colorpreference.ColorPreference
import app.lawnchair.ui.preferences.components.controls.SliderPreference
import app.lawnchair.ui.preferences.components.controls.SwitchPreference
import app.lawnchair.ui.preferences.components.layout.PreferenceGroup
import app.lawnchair.ui.preferences.components.layout.PreferenceLayout
+import app.lawnchair.ui.preferences.navigation.GeneralIconShape
import com.android.launcher3.R
@Composable
@@ -39,9 +42,25 @@ fun FolderPreferences(
backArrowVisible = !LocalIsExpandedScreen.current,
modifier = modifier,
) {
+ val context = LocalContext.current
val prefs = preferenceManager()
val prefs2 = preferenceManager2()
+ val folderIconShapeAdapter = prefs2.folderShape.getAdapter()
+ val folderIconShapeSubtitle = iconShapeEntries(context)
+ .firstOrNull { it.value == folderIconShapeAdapter.state.value }
+ ?.label?.invoke()
+ ?: stringResource(id = R.string.custom)
PreferenceGroup(heading = stringResource(id = R.string.general_label)) {
+ Item {
+ NavigationActionPreference(
+ label = stringResource(id = R.string.folder_shape_label),
+ destination = GeneralIconShape(ShapeRoute.FOLDER_SHAPE),
+ subtitle = folderIconShapeSubtitle,
+ endWidget = {
+ IconShapePreview(iconShape = folderIconShapeAdapter.state.value)
+ },
+ )
+ }
Item { ColorPreference(preference = prefs2.folderColor) }
Item {
SliderPreference(
diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/IconShapePreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/IconShapePreference.kt
index 877c45a857..a47c7c3f99 100644
--- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/IconShapePreference.kt
+++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/IconShapePreference.kt
@@ -38,6 +38,7 @@ import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -113,47 +114,51 @@ fun ShapePreference(
modifier: Modifier = Modifier,
currentTab: ShapeRoute = ShapeRoute.APP_SHAPE,
) {
- val prefs2 = preferenceManager2()
- if (prefs2.enableFolderIconShapeCustomization.getAdapter().state.value) {
- TwoTabPreferenceLayout(
- label = stringResource(id = R.string.icon_shape_label),
- backArrowVisible = !LocalIsExpandedScreen.current,
- defaultPage = currentTab.ordinal,
- firstPageLabel = stringResource(id = R.string.app_icon_shape_label),
- firstPageContent = {
- AppIconShapeContent()
- },
- secondPageLabel = stringResource(id = R.string.folder_shape_label),
- secondPageContent = {
- FolderShapeContent()
- },
- modifier = modifier,
- )
- } else {
- IconShapePreference()
- }
+ TwoTabPreferenceLayout(
+ label = stringResource(id = R.string.icon_shape_label),
+ backArrowVisible = !LocalIsExpandedScreen.current,
+ defaultPage = currentTab.ordinal,
+ firstPageLabel = stringResource(id = R.string.app_icon_shape_label),
+ firstPageContent = {
+ ShapeTabContent(currentTab = ShapeRoute.APP_SHAPE)
+ },
+ secondPageLabel = stringResource(id = R.string.folder_label),
+ secondPageContent = {
+ ShapeTabContent(currentTab = ShapeRoute.FOLDER_SHAPE)
+ },
+ modifier = modifier,
+ )
}
@Composable
-private fun AppIconShapeContent() {
+private fun ShapeTabContent(currentTab: ShapeRoute) {
val context = LocalContext.current
val preferenceManager2 = preferenceManager2()
val entries = remember { iconShapeEntries(context) }
- val iconShapeAdapter = preferenceManager2.iconShape.getAdapter()
- val customIconShape = preferenceManager2.customIconShape.asState()
+ val shapeAdapter = when (currentTab) {
+ ShapeRoute.APP_SHAPE -> preferenceManager2.iconShape.getAdapter()
+ ShapeRoute.FOLDER_SHAPE -> preferenceManager2.folderShape.getAdapter()
+ }
+ val customShape by when (currentTab) {
+ ShapeRoute.APP_SHAPE -> preferenceManager2.customIconShape.asState()
+ ShapeRoute.FOLDER_SHAPE -> preferenceManager2.customFolderShape.asState()
+ }
PreferenceGroup(
heading = stringResource(id = R.string.custom),
) {
- Item(visible = customIconShape.value != null) {
- CustomIconShapePreferenceOption(
- iconShapeAdapter = iconShapeAdapter,
- customIconShape = customIconShape.value!!,
- )
+ customShape?.let { shape ->
+ Item {
+ CustomIconShapePreferenceOption(
+ iconShapeAdapter = shapeAdapter,
+ customIconShape = shape,
+ )
+ }
}
Item {
ModifyCustomIconShapePreference(
- customIconShape = customIconShape.value,
+ customIconShape = customShape,
+ currentTab = currentTab,
)
}
}
@@ -166,11 +171,11 @@ private fun AppIconShapeContent() {
enabled = item.enabled,
title = { Text(item.label()) },
modifier = Modifier.clickable(item.enabled) {
- iconShapeAdapter.onChange(newValue = item.value)
+ shapeAdapter.onChange(newValue = item.value)
},
startWidget = {
RadioButton(
- selected = item.value == iconShapeAdapter.state.value,
+ selected = item.value == shapeAdapter.state.value,
onClick = null,
enabled = item.enabled,
)
@@ -184,97 +189,6 @@ private fun AppIconShapeContent() {
}
}
-@Composable
-private fun FolderShapeContent() {
- val context = LocalContext.current
- val preferenceManager2 = preferenceManager2()
- val entries = remember { iconShapeEntries(context) }
- val folderShapeAdapter = preferenceManager2.folderShape.getAdapter()
-
- PreferenceGroup(
- heading = stringResource(id = R.string.presets),
- ) {
- entries.forEach { item ->
- Item {
- PreferenceTemplate(
- enabled = item.enabled,
- title = { Text(item.label()) },
- modifier = Modifier.clickable(item.enabled) {
- folderShapeAdapter.onChange(newValue = item.value)
- },
- startWidget = {
- RadioButton(
- selected = item.value == folderShapeAdapter.state.value,
- onClick = null,
- enabled = item.enabled,
- )
- },
- endWidget = {
- IconShapePreview(iconShape = item.value)
- },
- )
- }
- }
- }
-}
-
-@Composable
-fun IconShapePreference(
- modifier: Modifier = Modifier,
-) {
- val context = LocalContext.current
- val preferenceManager2 = preferenceManager2()
- val entries = remember { iconShapeEntries(context) }
- val iconShapeAdapter = preferenceManager2.iconShape.getAdapter()
- val customIconShape = preferenceManager2.customIconShape.asState()
-
- PreferenceLayout(
- label = stringResource(id = R.string.icon_shape_label),
- modifier = modifier,
- ) {
- PreferenceGroup(
- heading = stringResource(id = R.string.custom),
- ) {
- Item(visible = customIconShape.value != null) {
- CustomIconShapePreferenceOption(
- iconShapeAdapter = iconShapeAdapter,
- customIconShape = customIconShape.value!!,
- )
- }
- Item {
- ModifyCustomIconShapePreference(
- customIconShape = customIconShape.value,
- )
- }
- }
- PreferenceGroup(
- heading = stringResource(id = R.string.presets),
- ) {
- entries.forEach { item ->
- Item {
- PreferenceTemplate(
- enabled = item.enabled,
- title = { Text(item.label()) },
- modifier = Modifier.clickable(item.enabled) {
- iconShapeAdapter.onChange(newValue = item.value)
- },
- startWidget = {
- RadioButton(
- selected = item.value == iconShapeAdapter.state.value,
- onClick = null,
- enabled = item.enabled,
- )
- },
- endWidget = {
- IconShapePreview(iconShape = item.value)
- },
- )
- }
- }
- }
- }
-}
-
@Composable
private fun CustomIconShapePreferenceOption(
iconShapeAdapter: PreferenceAdapter,
@@ -301,18 +215,20 @@ private fun CustomIconShapePreferenceOption(
@Composable
private fun ModifyCustomIconShapePreference(
customIconShape: IconShape?,
+ currentTab: ShapeRoute,
modifier: Modifier = Modifier,
) {
val navController = LocalNavController.current
- val route = GeneralCustomIconShapeCreator
+ val route = GeneralCustomIconShapeCreator(selectedId = currentTab)
val created = customIconShape != null
- val text = if (created) {
- stringResource(id = R.string.custom_icon_shape_edit)
- } else {
- stringResource(id = R.string.custom_icon_shape_create)
- }
+ val text = stringResource(
+ when (currentTab) {
+ ShapeRoute.APP_SHAPE -> if (created) R.string.custom_icon_shape_edit else R.string.custom_icon_shape_create
+ ShapeRoute.FOLDER_SHAPE -> if (created) R.string.custom_folder_shape_edit else R.string.custom_folder_shape_create
+ },
+ )
val icon = if (created) Icons.Rounded.Edit else Icons.Rounded.Add
diff --git a/lawnchair/src/app/lawnchair/ui/preferences/navigation/PreferenceNavigation.kt b/lawnchair/src/app/lawnchair/ui/preferences/navigation/PreferenceNavigation.kt
index 57c47658ba..b3a719f1ed 100644
--- a/lawnchair/src/app/lawnchair/ui/preferences/navigation/PreferenceNavigation.kt
+++ b/lawnchair/src/app/lawnchair/ui/preferences/navigation/PreferenceNavigation.kt
@@ -42,7 +42,6 @@ import app.lawnchair.ui.preferences.destinations.HomeScreenGridPreferences
import app.lawnchair.ui.preferences.destinations.HomeScreenPreferences
import app.lawnchair.ui.preferences.destinations.IconPackPreferences
import app.lawnchair.ui.preferences.destinations.IconPickerPreference
-import app.lawnchair.ui.preferences.destinations.IconShapePreference
import app.lawnchair.ui.preferences.destinations.LauncherPopupPreference
import app.lawnchair.ui.preferences.destinations.PickAppForGesture
import app.lawnchair.ui.preferences.destinations.PreferencesDashboard
@@ -122,8 +121,11 @@ fun PreferenceNavigation(
ShapePreference(currentTab = route.selectedId)
}
composable(
- deepLinks = getDeepLink(GeneralCustomIconShapeCreator),
- ) { CustomIconShapePreference() }
+ deepLinks = getDeepLink(GeneralCustomIconShapeCreator()),
+ ) { backStackEntry ->
+ val route: GeneralCustomIconShapeCreator = backStackEntry.toRoute()
+ CustomIconShapePreference(currentTab = route.selectedId)
+ }
composable(
deepLinks = getDeepLink(HomeScreen),
diff --git a/lawnchair/src/app/lawnchair/ui/preferences/navigation/PreferenceRoutes.kt b/lawnchair/src/app/lawnchair/ui/preferences/navigation/PreferenceRoutes.kt
index 903d8c57f8..f8a654d917 100644
--- a/lawnchair/src/app/lawnchair/ui/preferences/navigation/PreferenceRoutes.kt
+++ b/lawnchair/src/app/lawnchair/ui/preferences/navigation/PreferenceRoutes.kt
@@ -121,7 +121,9 @@ data object GeneralIconPack : PreferenceRoute, PreferenceDeepLink {
data class GeneralIconShape(val selectedId: ShapeRoute = ShapeRoute.APP_SHAPE) : PreferenceRoute
@Serializable
-data object GeneralCustomIconShapeCreator : PreferenceRoute, PreferenceDeepLink {
+data class GeneralCustomIconShapeCreator(val selectedId: ShapeRoute = ShapeRoute.APP_SHAPE) :
+ PreferenceRoute,
+ PreferenceDeepLink {
override val deepLink = "$URI/general-icon-shape-creator"
}