From a7f2cc6aba1f248e1398732a29cd0ffded76b0c7 Mon Sep 17 00:00:00 2001 From: Acclorite <140836141+Acclorite@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:48:39 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20ColorScheme=20logger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added theme logger (basically just prints scheme's colors in Log.i to then use them for new themes in convenient way) --- .../book_story/presentation/ui/ThemeLogger.kt | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 app/src/main/java/ua/acclorite/book_story/presentation/ui/ThemeLogger.kt diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/ui/ThemeLogger.kt b/app/src/main/java/ua/acclorite/book_story/presentation/ui/ThemeLogger.kt new file mode 100644 index 00000000..28a636e1 --- /dev/null +++ b/app/src/main/java/ua/acclorite/book_story/presentation/ui/ThemeLogger.kt @@ -0,0 +1,76 @@ +package ua.acclorite.book_story.presentation.ui + +import android.util.Log +import androidx.compose.material3.ColorScheme +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb + +private const val THEME = "THEME" + +/** + * This function logs all the colors of the colorScheme. + * You can use it to extract colors from Material You theme and add it to the app. + * Sadly, Material Theme Builder (both figma + site) does not provide many colors, + * that's why I have to use Material You theme on the device itself + * (which provides tons of different colors and presets of those colors) + * to generate and add new themes. + * + * @param darkTheme Whether the theme is in dark mode. + * Changes variable suffix to "Dark" if true, "Light" otherwise. + */ +fun ColorScheme.logTheme(darkTheme: Boolean): ColorScheme { + val suffix = if (darkTheme) "Dark" else "Light" + + fun Color.convertToVal(variableName: String): String { + return "private val $variableName$suffix = Color(0x${this.convertToHex()})\n" + } + + Log.i( + THEME, + "Theme:\n" + + "------------------------\n" + + primary.convertToVal("primary") + + onPrimary.convertToVal("onPrimary") + + primaryContainer.convertToVal("primaryContainer") + + onPrimaryContainer.convertToVal("onPrimaryContainer") + + secondary.convertToVal("secondary") + + onSecondary.convertToVal("onSecondary") + + secondaryContainer.convertToVal("secondaryContainer") + + onSecondaryContainer.convertToVal("onSecondaryContainer") + + tertiary.convertToVal("tertiary") + + onTertiary.convertToVal("onTertiary") + + tertiaryContainer.convertToVal("tertiaryContainer") + + onTertiaryContainer.convertToVal("onTertiaryContainer") + + error.convertToVal("error") + + onError.convertToVal("onError") + + errorContainer.convertToVal("errorContainer") + + onErrorContainer.convertToVal("onErrorContainer") + + background.convertToVal("background") + + onBackground.convertToVal("onBackground") + + surface.convertToVal("surface") + + onSurface.convertToVal("onSurface") + + surfaceVariant.convertToVal("surfaceVariant") + + onSurfaceVariant.convertToVal("onSurfaceVariant") + + outline.convertToVal("outline") + + outlineVariant.convertToVal("outlineVariant") + + scrim.convertToVal("scrim") + + inverseSurface.convertToVal("inverseSurface") + + inverseOnSurface.convertToVal("inverseOnSurface") + + inversePrimary.convertToVal("inversePrimary") + + surfaceDim.convertToVal("surfaceDim") + + surfaceBright.convertToVal("surfaceBright") + + surfaceContainerLowest.convertToVal("surfaceContainerLowest") + + surfaceContainerLow.convertToVal("surfaceContainerLow") + + surfaceContainer.convertToVal("surfaceContainer") + + surfaceContainerHigh.convertToVal("surfaceContainerHigh") + + surfaceContainerHighest.convertToVal("surfaceContainerHighest") + + "------------------------" + ) + + return this +} + +@OptIn(ExperimentalStdlibApi::class) +private fun Color.convertToHex(): String { + return toArgb().toHexString(format = HexFormat.UpperCase) +} \ No newline at end of file