From 3ad39d88bbc75666cdc4c06a97bb83de32650fd6 Mon Sep 17 00:00:00 2001 From: Yasan Date: Tue, 29 Nov 2022 18:09:27 +0330 Subject: [PATCH] Use system icon shape as default icon shape instead of circle --- lawnchair/res/values/config.xml | 2 +- .../app/lawnchair/icons/shape/IconShape.kt | 40 +++++++++++-------- .../preferences2/PreferenceManager2.kt | 6 +-- .../preferences/CustomIconShapePreference.kt | 2 +- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/lawnchair/res/values/config.xml b/lawnchair/res/values/config.xml index 791cbf08e1..773b2355b1 100644 --- a/lawnchair/res/values/config.xml +++ b/lawnchair/res/values/config.xml @@ -57,7 +57,7 @@ google - circle + system gregorian diff --git a/lawnchair/src/app/lawnchair/icons/shape/IconShape.kt b/lawnchair/src/app/lawnchair/icons/shape/IconShape.kt index d7676f40ee..949e46f0a3 100644 --- a/lawnchair/src/app/lawnchair/icons/shape/IconShape.kt +++ b/lawnchair/src/app/lawnchair/icons/shape/IconShape.kt @@ -19,6 +19,7 @@ package app.lawnchair.icons.shape +import android.content.Context import android.graphics.Path import android.graphics.PointF import android.util.Log @@ -351,23 +352,30 @@ open class IconShape(val topLeft: Corner, companion object { - fun fromString(value: String): IconShape? { - return when (value) { - "circle" -> Circle - "square" -> Square - "sharpSquare" -> SharpSquare - "roundedSquare" -> RoundedSquare - "squircle" -> Squircle - "sammy" -> Sammy - "teardrop" -> Teardrop - "cylinder" -> Cylinder - "cupertino" -> Cupertino - "octagon" -> Octagon - "diamond" -> Diamond - "egg" -> Egg - "" -> null - else -> runCatching { parseCustomShape(value) }.getOrNull() + fun fromString(value: String, context: Context): IconShape? { + if (value == "system") { + runCatching { + return IconShapeManager.getSystemIconShape(context = context) + } } + return fromStringWithoutContext(value = value) + } + + private fun fromStringWithoutContext(value: String): IconShape? = when (value) { + "circle" -> Circle + "square" -> Square + "sharpSquare" -> SharpSquare + "roundedSquare" -> RoundedSquare + "squircle" -> Squircle + "sammy" -> Sammy + "teardrop" -> Teardrop + "cylinder" -> Cylinder + "cupertino" -> Cupertino + "octagon" -> Octagon + "diamond" -> Diamond + "egg" -> Egg + "" -> null + else -> runCatching { parseCustomShape(value) }.getOrNull() } private fun parseCustomShape(value: String): IconShape { diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt index a1e8a162a4..90e6d2afda 100644 --- a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt +++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt @@ -87,15 +87,15 @@ class PreferenceManager2(private val context: Context) : PreferenceManager { val iconShape = preference( key = stringPreferencesKey(name = "icon_shape"), - defaultValue = IconShape.fromString(context.getString(R.string.config_default_icon_shape)) ?: IconShape.Circle, - parse = { IconShape.fromString(it) ?: IconShapeManager.getSystemIconShape(context) }, + defaultValue = IconShape.fromString(value = context.getString(R.string.config_default_icon_shape), context = context) ?: IconShape.Circle, + parse = { IconShape.fromString(value = it, context = context) ?: IconShapeManager.getSystemIconShape(context) }, save = { it.toString() }, ) val customIconShape = preference( key = stringPreferencesKey(name = "custom_icon_shape"), defaultValue = null, - parse = { IconShape.fromString(it) ?: IconShapeManager.getSystemIconShape(context) }, + parse = { IconShape.fromString(value = it, context = context) ?: IconShapeManager.getSystemIconShape(context) }, save = { it.toString() }, onSet = { it?.let(iconShape::setBlocking) }, ) diff --git a/lawnchair/src/app/lawnchair/ui/preferences/CustomIconShapePreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/CustomIconShapePreference.kt index c95763ce32..d74a873905 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/CustomIconShapePreference.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/CustomIconShapePreference.kt @@ -205,7 +205,7 @@ private fun IconShapeClipboardPreferenceGroup( label = stringResource(id = R.string.import_from_clipboard), ) { getClipboardContent(context)?.let { - IconShape.fromString(value = it) + IconShape.fromString(value = it, context = context) }?.let { onSelectedIconShapeChange(it) } ?: run {