From cfa68524f302a00a32e194be4f54f3bdb1bad760 Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Thu, 17 Feb 2022 23:39:17 +0100 Subject: [PATCH] Add: App's compose themes --- .../looker/droidify/ui/compose/theme/Color.kt | 6 +- .../looker/droidify/ui/compose/theme/Theme.kt | 64 +++++++++++++++++++ .../com/looker/droidify/utility/Utils.kt | 32 ++++------ 3 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 src/main/kotlin/com/looker/droidify/ui/compose/theme/Theme.kt diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/theme/Color.kt b/src/main/kotlin/com/looker/droidify/ui/compose/theme/Color.kt index 8de767cd..23f4aaa1 100644 --- a/src/main/kotlin/com/looker/droidify/ui/compose/theme/Color.kt +++ b/src/main/kotlin/com/looker/droidify/ui/compose/theme/Color.kt @@ -44,7 +44,7 @@ val DarkOnError = Color(0xFF680003) val DarkOnErrorContainer = Color(0xFFFFDAD4) val DarkBackground = Color(0xFF191C1A) val DarkOnBackground = Color(0xFFE1E3DE) -val DarkSurface = Color(0xFF191C1A) +val DarkSurface = Color(0xFF2C2C2C) val DarkOnSurface = Color(0xFFE1E3DE) val DarkSurfaceVariant = Color(0xFF414942) val DarkOnSurfaceVariant = Color(0xFFC0C9C0) @@ -53,5 +53,9 @@ val DarkInversePrimary = Color(0xFFE1E3DE) val DarkInverseSurface = Color(0xFF191C1A) val DarkInverseOnSurface = Color(0xFF006D3E) +// Black Theme +val BlackBackground = Color(0xFF000000) +val BlackSurface = Color(0xFF191C1A) + val Seed = Color(0xFF51DF93) diff --git a/src/main/kotlin/com/looker/droidify/ui/compose/theme/Theme.kt b/src/main/kotlin/com/looker/droidify/ui/compose/theme/Theme.kt new file mode 100644 index 00000000..ece6f3f2 --- /dev/null +++ b/src/main/kotlin/com/looker/droidify/ui/compose/theme/Theme.kt @@ -0,0 +1,64 @@ +package com.looker.droidify.ui.compose.theme + +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material.MaterialTheme +import androidx.compose.material.darkColors +import androidx.compose.material.lightColors +import androidx.compose.runtime.Composable +import com.looker.droidify.utility.isBlackTheme + +@Composable +fun AppTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + blackTheme: Boolean = isBlackTheme, + content: @Composable () -> Unit +) { + MaterialTheme( + shapes = AppShapes, + colors = when { + darkTheme && blackTheme -> BlackColors + darkTheme -> DarkColors + else -> LightColors + }, + content = content + ) +} + +private val LightColors = lightColors( + primary = LightPrimary, + primaryVariant = LightPrimaryContainer, + onPrimary = LightOnPrimary, + secondary = LightSecondary, + secondaryVariant = LightSecondaryContainer, + onSecondary = LightOnSecondary, + surface = LightSurface, + background = LightBackground, + onBackground = LightOnBackground, + error = LightError +) + +private val DarkColors = darkColors( + primary = DarkPrimary, + primaryVariant = DarkPrimaryContainer, + onPrimary = DarkOnPrimary, + secondary = DarkSecondary, + secondaryVariant = DarkSecondaryContainer, + onSecondary = DarkOnSecondary, + surface = DarkSurface, + background = DarkBackground, + onBackground = DarkOnBackground, + error = DarkError +) + +private val BlackColors = darkColors( + primary = DarkPrimary, + primaryVariant = DarkPrimaryContainer, + onPrimary = DarkOnPrimary, + secondary = DarkSecondary, + secondaryVariant = DarkSecondaryContainer, + onSecondary = DarkOnSecondary, + surface = BlackSurface, + background = BlackBackground, + onBackground = DarkOnBackground, + error = DarkError +) \ No newline at end of file diff --git a/src/main/kotlin/com/looker/droidify/utility/Utils.kt b/src/main/kotlin/com/looker/droidify/utility/Utils.kt index 99649112..1b3557bc 100644 --- a/src/main/kotlin/com/looker/droidify/utility/Utils.kt +++ b/src/main/kotlin/com/looker/droidify/utility/Utils.kt @@ -8,8 +8,6 @@ import android.content.pm.PackageInfo import android.content.pm.Signature import android.content.res.Configuration import android.graphics.drawable.Drawable -import androidx.recyclerview.widget.AsyncDifferConfig -import androidx.recyclerview.widget.DiffUtil import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.core.JsonParser import com.looker.droidify.BuildConfig @@ -194,21 +192,17 @@ fun jsonGenerate(callback: (JsonGenerator) -> Unit): ByteArray { return outputStream.toByteArray() } -val PRODUCT_ASYNC_DIFFER_CONFIG - get() = AsyncDifferConfig.Builder(object : - DiffUtil.ItemCallback() { - override fun areItemsTheSame( - oldItem: com.looker.droidify.database.entity.Product, - newItem: com.looker.droidify.database.entity.Product - ): Boolean { - return oldItem.repository_id == newItem.repository_id - && oldItem.package_name == newItem.package_name - } +val isDarkTheme: Boolean + get() = when (Preferences[Preferences.Key.Theme]) { + is Preferences.Theme.Light -> false + is Preferences.Theme.Dark -> true + is Preferences.Theme.Amoled -> true + else -> false + } - override fun areContentsTheSame( - oldItem: com.looker.droidify.database.entity.Product, - newItem: com.looker.droidify.database.entity.Product - ): Boolean { - return oldItem.item == newItem.item - } - }).build() \ No newline at end of file +val isBlackTheme: Boolean + get() = when (Preferences[Preferences.Key.Theme]) { + is Preferences.Theme.Amoled -> true + is Preferences.Theme.AmoledSystem -> true + else -> false + } \ No newline at end of file