Use system icon shape as default icon shape instead of circle

This commit is contained in:
Yasan
2022-11-29 18:09:27 +03:30
parent 4d6e74742d
commit 3ad39d88bb
4 changed files with 29 additions and 21 deletions

View File

@@ -57,7 +57,7 @@
<string name="config_default_qsb_search_provider_id" translatable="false">google</string>
<!-- Which icon shape to use by default -->
<string name="config_default_icon_shape" translatable="false">circle</string>
<string name="config_default_icon_shape" translatable="false">system</string>
<!-- Which calendar to use on smartspace by default -->
<string name="config_default_smart_space_calendar" translatable="false">gregorian</string>

View File

@@ -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 {

View File

@@ -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) },
)

View File

@@ -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 {