Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Feb 22, 2024
1 parent dc24a98 commit 39b4356
Showing 1 changed file with 42 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,45 +151,48 @@ internal fun MaterialYouPalette(
private fun ColorScheme.asCodeString(
isDarkTheme: Boolean
): String = """
val ${if (isDarkTheme) "dark" else "light"}ColorScheme = ColorScheme(
background = Color(0xff${background.hex}),
error = Color(0xff${error.hex}),
errorContainer = Color(0xff${errorContainer.hex}),
inverseOnSurface = Color(0xff${inverseOnSurface.hex}),
inversePrimary = Color(0xff${inversePrimary.hex}),
inverseSurface = Color(0xff${inverseSurface.hex}),
onBackground = Color(0xff${onBackground.hex}),
onError = Color(0xff${onError.hex}),
onErrorContainer = Color(0xff${onErrorContainer.hex}),
onPrimary = Color(0xff${onPrimary.hex}),
onPrimaryContainer = Color(0xff${onPrimaryContainer.hex}),
onSecondary = Color(0xff${onSecondary.hex}),
onSecondaryContainer = Color(0xff${onSecondaryContainer.hex}),
onSurface = Color(0xff${onSurface.hex}),
onSurfaceVariant = Color(0xff${onSurfaceVariant.hex}),
onTertiary = Color(0xff${onTertiary.hex}),
onTertiaryContainer = Color(0xff${onTertiaryContainer.hex}),
outline = Color(0xff${outline.hex}),
outlineVariant = Color(0xff${outlineVariant.hex}),
primary = Color(0xff${primary.hex}),
primaryContainer = Color(0xff${primaryContainer.hex}),
scrim = Color(0xff${scrim.hex}),
secondary = Color(0xff${secondary.hex}),
secondaryContainer = Color(0xff${secondaryContainer.hex}),
surface = Color(0xff${surface.hex}),
surfaceTint = Color(0xff${surfaceTint.hex}),
surfaceVariant = Color(0xff${surfaceVariant.hex}),
tertiary = Color(0xff${tertiary.hex}),
tertiaryContainer = Color(0xff${tertiaryContainer.hex}),
surfaceBright = Color(0xff${surfaceBright.hex}),
surfaceDim = Color(0xff${surfaceDim.hex}),
surfaceContainer = Color(0xff${surfaceContainer.hex}),
surfaceContainerHigh = Color(0xff${surfaceContainerHigh.hex}),
surfaceContainerHighest = Color(0xff${surfaceContainerHighest.hex}),
surfaceContainerLow = Color(0xff${surfaceContainerLow.hex}),
surfaceContainerLowest = Color(0xff${surfaceContainerLowest.hex}),
val ${isDarkTheme.schemeName} = ColorScheme(
background = ${background.colorCode},
error = ${error.colorCode},
errorContainer = ${errorContainer.colorCode},
inverseOnSurface = ${inverseOnSurface.colorCode},
inversePrimary = ${inversePrimary.colorCode},
inverseSurface = ${inverseSurface.colorCode},
onBackground = ${onBackground.colorCode},
onError = ${onError.colorCode},
onErrorContainer = ${onErrorContainer.colorCode},
onPrimary = ${onPrimary.colorCode},
onPrimaryContainer = ${onPrimaryContainer.colorCode},
onSecondary = ${onSecondary.colorCode},
onSecondaryContainer = ${onSecondaryContainer.colorCode},
onSurface = ${onSurface.colorCode},
onSurfaceVariant = ${onSurfaceVariant.colorCode},
onTertiary = ${onTertiary.colorCode},
onTertiaryContainer = ${onTertiaryContainer.colorCode},
outline = ${outline.colorCode},
outlineVariant = ${outlineVariant.colorCode},
primary = ${primary.colorCode},
primaryContainer = ${primaryContainer.colorCode},
scrim = ${scrim.colorCode},
secondary = ${secondary.colorCode},
secondaryContainer = ${secondaryContainer.colorCode},
surface = ${surface.colorCode},
surfaceTint = ${surfaceTint.colorCode},
surfaceVariant = ${surfaceVariant.colorCode},
tertiary = ${tertiary.colorCode},
tertiaryContainer = ${tertiaryContainer.colorCode},
surfaceBright = ${surfaceBright.colorCode},
surfaceDim = ${surfaceDim.colorCode},
surfaceContainer = ${surfaceContainer.colorCode},
surfaceContainerHigh = ${surfaceContainerHigh.colorCode},
surfaceContainerHighest = ${surfaceContainerHighest.colorCode},
surfaceContainerLow = ${surfaceContainerLow.colorCode},
surfaceContainerLowest = ${surfaceContainerLowest.colorCode},
)
""".trim()

private val Color.hex
get() = this.toHex().drop(1).lowercase()
private val Boolean.schemeName: String
get() = "${if (this) "dark" else "light"}ColorScheme"

private val Color.colorCode
get() = "Color(0xff${this.toHex().drop(1).lowercase()})"

0 comments on commit 39b4356

Please sign in to comment.