Feat: Adds customizable theme and fix inner gamer theme (#2850)

This commit is contained in:
LunaDL authored and GitHub committed 2026-11-19 11:07:55 -05:00
1 parent 8f34554516
commit 71989b4cdb
38 files changed
+663 -13

No files matched your search

@@ -1534,6 +1534,45 @@ object SessionPrefs {
prefs(context).edit().putInt("gradientPrimary", primary).putInt("gradientSecondary", secondary).apply()
}
fun customThemeColors(context: Context): com.droiddeck.launcher.ui.CustomThemeColors =
prefs(context).let { p ->
val defaults = com.droiddeck.launcher.ui.CustomThemeColors()
com.droiddeck.launcher.ui.CustomThemeColors(
background = p.getInt("customThemeBackground", defaults.background),
surface = p.getInt("customThemeSurface", defaults.surface),
surfaceVariant = p.getInt("customThemeSurfaceVariant", defaults.surfaceVariant),
line = p.getInt("customThemeLine", defaults.line),
line2 = p.getInt("customThemeLine2", defaults.line2),
onBackground = p.getInt("customThemeOnBackground", defaults.onBackground),
onSurfaceVariant = p.getInt("customThemeOnSurfaceVariant", defaults.onSurfaceVariant),
primary = p.getInt("customThemePrimary", defaults.primary),
onPrimary = p.getInt("customThemeOnPrimary", defaults.onPrimary),
signal = p.getInt("customThemeSignal", defaults.signal),
good = p.getInt("customThemeGood", defaults.good),
error = p.getInt("customThemeError", defaults.error),
)
}
fun setCustomThemeColors(
context: Context,
colors: com.droiddeck.launcher.ui.CustomThemeColors,
) {
prefs(context).edit()
.putInt("customThemeBackground", colors.background)
.putInt("customThemeSurface", colors.surface)
.putInt("customThemeSurfaceVariant", colors.surfaceVariant)
.putInt("customThemeLine", colors.line)
.putInt("customThemeLine2", colors.line2)
.putInt("customThemeOnBackground", colors.onBackground)
.putInt("customThemeOnSurfaceVariant", colors.onSurfaceVariant)
.putInt("customThemePrimary", colors.primary)
.putInt("customThemeOnPrimary", colors.onPrimary)
.putInt("customThemeSignal", colors.signal)
.putInt("customThemeGood", colors.good)
.putInt("customThemeError", colors.error)
.apply()
}
fun trueBlackHighlight(context: Context): Int =
prefs(context).getInt("trueBlackHighlight", com.droiddeck.launcher.ui.Themes.DEFAULT_HIGHLIGHT)
@@ -437,6 +437,7 @@ internal fun SetupPanel(
}
if (s.theme == Themes.INNER_GAMER) RgbSpeedRow()
if (s.theme == Themes.GRADIENT) GradientColorRows()
if (s.theme == Themes.CUSTOM) CustomColorRows()
if (s.theme == Themes.TRUE_BLACK) HighlightColorRow()
ChoiceRow(
host, "app-scale", stringResource(R.string.setup_app_scale), stringResource(R.string.setup_app_scale_hint),
@@ -1212,3 +1213,42 @@ private fun GradientColorRows() {
if (picking == 1) Themes.setGradient(ctx, argb, secondary) else Themes.setGradient(ctx, primary, argb)
}
}
@Composable
private fun CustomColorRows() {
val ctx = androidx.compose.ui.platform.LocalContext.current.applicationContext
val colors = Themes.customColors
var picking by remember { mutableStateOf<String?>(null) }
val rows = listOf(
Triple("background", stringResource(R.string.theme_custom_background), colors.background),
Triple("surface", stringResource(R.string.theme_custom_surface), colors.surface),
Triple("surfaceVariant", stringResource(R.string.theme_custom_surface_variant), colors.surfaceVariant),
Triple("line", stringResource(R.string.theme_custom_line), colors.line),
Triple("line2", stringResource(R.string.theme_custom_line2), colors.line2),
Triple("onBackground", stringResource(R.string.theme_custom_on_background), colors.onBackground),
Triple("onSurfaceVariant", stringResource(R.string.theme_custom_on_surface_variant), colors.onSurfaceVariant),
Triple("primary", stringResource(R.string.theme_custom_primary), colors.primary),
Triple("onPrimary", stringResource(R.string.theme_custom_on_primary), colors.onPrimary),
Triple("signal", stringResource(R.string.theme_custom_signal), colors.signal),
Triple("good", stringResource(R.string.theme_custom_good), colors.good),
Triple("error", stringResource(R.string.theme_custom_error), colors.error),
)
rows.forEach { (key, label, argb) ->
SettingsRow(label, null) {
ColorCube(Color(argb), label) { picking = key }
}
}
val selected = rows.firstOrNull { it.first == picking }
if (selected != null) {
ColorPickerDialog(
selected.second,
selected.third,
onDismiss = { picking = null },
) { argb ->
Themes.setCustomColor(ctx, selected.first, argb)
}
}
}
@@ -41,6 +41,21 @@ class Palette(
val good: Color, val error: Color = Color(0xFFFF8A80),
)
data class CustomThemeColors(
val background: Int = 0xFF0A0B0D.toInt(),
val surface: Int = 0xFF121417.toInt(),
val surfaceVariant: Int = 0xFF1A1D22.toInt(),
val line: Int = 0xFF262A31.toInt(),
val line2: Int = 0xFF343A43.toInt(),
val onBackground: Int = 0xFFF2F4F7.toInt(),
val onSurfaceVariant: Int = 0xFF9AA3AF.toInt(),
val primary: Int = 0xFF1A9FFF.toInt(),
val onPrimary: Int = 0xFF03111F.toInt(),
val signal: Int = 0xFF1A9FFF.toInt(),
val good: Int = 0xFF4CD37F.toInt(),
val error: Int = 0xFFFF8A80.toInt(),
)
object Themes {
const val GRAPHITE = "graphite"
const val PAPER = "paper"
@@ -48,6 +63,7 @@ object Themes {
const val ELECTRIC = "electric"
const val INNER_GAMER = "inner_gamer"
const val GRADIENT = "gradient"
const val CUSTOM = "custom"
const val DEFAULT_PRIMARY = 0xFF8B5CF6.toInt()
const val DEFAULT_SECONDARY = 0xFF22D3EE.toInt()
@@ -55,6 +71,9 @@ object Themes {
var gradientColors by mutableStateOf(DEFAULT_PRIMARY to DEFAULT_SECONDARY)
private set
var customColors by mutableStateOf(CustomThemeColors())
private set
const val RGB_SPEEDS = 10
const val DEFAULT_RGB_SPEED = 3
const val RGB_HUE_STEP = 3f
@@ -87,6 +106,7 @@ object Themes {
gradientColors = SessionPrefs.gradientColors(context)
rgbSpeed = SessionPrefs.rgbSpeed(context)
trueBlackHighlight = SessionPrefs.trueBlackHighlight(context)
customColors = SessionPrefs.customThemeColors(context)
}
fun setTrueBlackHighlight(context: Context, highlight: Int) {
@@ -104,9 +124,51 @@ object Themes {
gradientColors = primary to secondary
}
fun setCustomColors(context: Context, colors: CustomThemeColors) {
SessionPrefs.setCustomThemeColors(context, colors)
customColors = colors
}
fun setCustomColor(context: Context, key: String, color: Int) {
val current = customColors
val updated = when (key) {
"background" -> current.copy(background = color)
"surface" -> current.copy(surface = color)
"surfaceVariant" -> current.copy(surfaceVariant = color)
"line" -> current.copy(line = color)
"line2" -> current.copy(line2 = color)
"onBackground" -> current.copy(onBackground = color)
"onSurfaceVariant" -> current.copy(onSurfaceVariant = color)
"primary" -> current.copy(primary = color)
"onPrimary" -> current.copy(onPrimary = color)
"signal" -> current.copy(signal = color)
"good" -> current.copy(good = color)
"error" -> current.copy(error = color)
else -> return
}
setCustomColors(context, updated)
}
private fun customPalette(colors: CustomThemeColors): Palette = Palette(
CUSTOM, R.string.theme_custom, R.string.theme_custom_detail,
background = Color(colors.background),
surface = Color(colors.surface),
surfaceVariant = Color(colors.surfaceVariant),
line = Color(colors.line),
line2 = Color(colors.line2),
onBackground = Color(colors.onBackground),
onSurfaceVariant = Color(colors.onSurfaceVariant),
primary = Color(colors.primary),
primary2 = Color(colors.primary),
onPrimary = Color(colors.onPrimary),
signal = Color(colors.signal),
good = Color(colors.good),
error = Color(colors.error),
)
fun current(context: Context): Palette {
val id = SessionPrefs.theme(context)
if (id == GRADIENT || id == INNER_GAMER || id == TRUE_BLACK) loadGradient(context)
if (id == GRADIENT || id == INNER_GAMER || id == TRUE_BLACK || id == CUSTOM) loadGradient(context)
return byId(id)
}
@@ -149,11 +211,13 @@ object Themes {
),
innerGamer(0f),
ThemeColors.palette(DEFAULT_PRIMARY, DEFAULT_SECONDARY, R.string.theme_gradient, R.string.theme_gradient_detail),
customPalette(customColors),
)
fun byId(id: String): Palette {
if (id == INNER_GAMER) return innerGamer(rgbHue)
if (id == TRUE_BLACK) return ThemeColors.trueBlack(trueBlackHighlight)
if (id == CUSTOM) return customPalette(customColors)
if (id == GRADIENT) return ThemeColors.palette(gradientColors.first, gradientColors.second, R.string.theme_gradient, R.string.theme_gradient_detail)
return all.firstOrNull { it.id == id } ?: all[0]
}
@@ -203,7 +267,6 @@ private val ContentDirected = Typography().run {
@Composable
private fun InnerGamerHue(speed: Int) {
if (Motion.scale == 0f) return
key(speed) { InnerGamerCycle(speed) }
}