diff --git a/build.gradle.kts b/build.gradle.kts index ace85f8..ecab46c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,8 @@ -buildscript { - repositories { - google() - mavenCentral() - } - dependencies { - classpath("com.android.tools.build:gradle:8.1.1") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10") - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.build.gradle.kts files - } +@Suppress("DSL_SCOPE_VIOLATION") +plugins { + alias(libs.plugins.android.gradlePlugin) apply false + alias(libs.plugins.kotlin.jvm) apply false } -// Top-level build file where you can add configuration options common to all sub-projects/modules. tasks.register("clean", Delete::class) { delete(rootProject.buildDir) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..fc500eb --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,26 @@ +[versions] +androidGradlePlugin = "8.2.1" +kotlin = "1.9.22" +androidxCoreCoreKts = "1.12.0" +junitJunit = "4.13.2" +androidxCompose = "1.6.0-rc01" +androidxComposeMaterial3 = "1.2.0-beta02" +androidxComposeCompiler = "1.5.8" +comGithubKyant0m3color = "2024.1" +androidxTestExtJunitKtx = "1.1.5" +androidxActivityActivityCompose = "1.8.2" + +[libraries] +androidx-core-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCoreCoreKts" } +junit-junit = { group = "junit", name = "junit", version.ref = "junitJunit" } +androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "androidxCompose" } +androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "androidxComposeMaterial3" } +androidx-compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "androidxCompose" } +com-github-kyant0-m3color = { group = "com.github.Kyant0", name = "m3color", version.ref = "comGithubKyant0m3color" } +androidx-test-ext-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidxTestExtJunitKtx" } +androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "androidxCompose" } +androidx-activity-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivityActivityCompose" } + +[plugins] +android-gradlePlugin = { id = "com.android.application", version.ref = "androidGradlePlugin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6eee2d8..15de902 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Sep 13 10:24:10 MSK 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle.kts similarity index 72% rename from settings.gradle rename to settings.gradle.kts index 434522c..68584eb 100644 --- a/settings.gradle +++ b/settings.gradle.kts @@ -5,14 +5,15 @@ pluginManagement { mavenCentral() } } +@Suppress("UnstableApiUsage") dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() - maven { url 'https://jitpack.io' } + maven(url = "https://jitpack.io") } } rootProject.name = "Themmo" -include ':themmo' -include ':themmosample' +include(":themmo") +include(":themmosample") diff --git a/themmo/build.gradle.kts b/themmo/build.gradle.kts index c860e64..95a043b 100644 --- a/themmo/build.gradle.kts +++ b/themmo/build.gradle.kts @@ -8,8 +8,8 @@ publishing { publications { register("release") { groupId = "io.github.sadellie" - artifactId = "themmo13" - version = "1.1.0" + artifactId = "themmo" + version = "1.2.0" afterEvaluate { from(components["release"]) @@ -18,7 +18,6 @@ publishing { } } -@Suppress("UnstableApiUsage") android { namespace = "io.github.sadellie.themmo" compileSdk = 34 @@ -67,9 +66,9 @@ android { buildConfig = false } composeOptions { - kotlinCompilerExtensionVersion = "1.4.4" + kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get().toString() } - packagingOptions { + packaging { jniLibs.excludes.add("META-INF/licenses/**") resources.excludes.add("META-INF/licenses/**") resources.excludes.add("META-INF/AL2.0") @@ -78,10 +77,10 @@ android { } dependencies { - implementation("androidx.core:core-ktx:1.12.0") - testImplementation("junit:junit:4.13.2") - androidTestImplementation("androidx.test.ext:junit:1.1.5") - implementation("androidx.compose.ui:ui:1.6.0-alpha06") - implementation("androidx.compose.material3:material3:1.2.0-alpha08") - implementation("com.github.Kyant0:m3color:2023.8.1") + implementation(libs.androidx.core.core.ktx) + testImplementation(libs.junit.junit) + androidTestImplementation(libs.androidx.test.ext.junit.ktx) + implementation(libs.androidx.compose.ui) + implementation(libs.com.github.kyant0.m3color) + implementation(libs.androidx.compose.material3) } \ No newline at end of file diff --git a/themmo/src/main/java/io/github/sadellie/themmo/DynamicColors.kt b/themmo/src/main/java/io/github/sadellie/themmo/DynamicColors.kt index ec3e66c..d647af5 100644 --- a/themmo/src/main/java/io/github/sadellie/themmo/DynamicColors.kt +++ b/themmo/src/main/java/io/github/sadellie/themmo/DynamicColors.kt @@ -27,8 +27,16 @@ import com.kyant.m3color.scheme.SchemeVibrant * @return Primary color of current wallpaper image. */ @RequiresApi(Build.VERSION_CODES.O_MR1) -internal fun extractWallpaperPrimary(context: Context): WallpaperColors? { - return WallpaperManager.getInstance(context).getWallpaperColors(WallpaperManager.FLAG_SYSTEM) +internal fun extractWallpaperPrimary(context: Context): Color? { + val wallpaperColors: WallpaperColors = WallpaperManager + .getInstance(context) + .getWallpaperColors(WallpaperManager.FLAG_SYSTEM) ?: return null + + return Color( + red = wallpaperColors.primaryColor.red(), + green = wallpaperColors.primaryColor.green(), + blue = wallpaperColors.primaryColor.blue() + ) } internal fun dynamicColorScheme( diff --git a/themmo/src/main/java/io/github/sadellie/themmo/ThemmoController.kt b/themmo/src/main/java/io/github/sadellie/themmo/ThemmoController.kt index eed0db1..c67ea44 100644 --- a/themmo/src/main/java/io/github/sadellie/themmo/ThemmoController.kt +++ b/themmo/src/main/java/io/github/sadellie/themmo/ThemmoController.kt @@ -5,6 +5,8 @@ import android.os.Build import androidx.annotation.RequiresApi import androidx.compose.material3.ColorScheme import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -102,27 +104,34 @@ class ThemmoController( private fun provideLightColorScheme(context: Context): ColorScheme { return when { isDynamicThemeEnabled -> { - val keyColor = when { + when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> { + dynamicLightColorScheme(context) + } Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { - colorResource(id = android.R.color.system_accent1_500) + val keyColor = colorResource(android.R.color.system_accent1_500) + + dynamicColorScheme( + keyColor = keyColor, + isDark = false, + style = currentMonetMode, + ) } Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 -> { - val wallpaperColors = extractWallpaperPrimary(context) - ?: return lightColorScheme - Color( - red = wallpaperColors.primaryColor.red(), - green = wallpaperColors.primaryColor.green(), - blue = wallpaperColors.primaryColor.blue() - ) + val keyColor = extractWallpaperPrimary(context) + + if (keyColor == null) { + lightColorScheme + } else { + dynamicColorScheme( + keyColor = keyColor, + isDark = false, + style = currentMonetMode, + ) + } } - else -> return lightColorScheme + else -> lightColorScheme } - - dynamicColorScheme( - keyColor = keyColor, - isDark = false, - style = currentMonetMode, - ) } !isDynamicThemeEnabled and currentCustomColor.isSpecified -> { dynamicColorScheme( @@ -137,29 +146,36 @@ class ThemmoController( @Composable private fun provideDarkColorScheme(context: Context): ColorScheme { - val dark = when { + val darkColorScheme: ColorScheme = when { isDynamicThemeEnabled -> { - val keyColor = when { + when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> { + dynamicDarkColorScheme(context) + } Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { - colorResource(id = android.R.color.system_accent1_500) + val keyColor = colorResource(android.R.color.system_accent1_500) + + dynamicColorScheme( + keyColor = keyColor, + isDark = true, + style = currentMonetMode, + ) } Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 -> { - val wallpaperColors = extractWallpaperPrimary(context) - ?: return darkColorScheme - Color( - red = wallpaperColors.primaryColor.red(), - green = wallpaperColors.primaryColor.green(), - blue = wallpaperColors.primaryColor.blue() - ) + val keyColor = extractWallpaperPrimary(context) + + if (keyColor == null) { + darkColorScheme + } else { + dynamicColorScheme( + keyColor = keyColor, + isDark = true, + style = currentMonetMode, + ) + } } - else -> return darkColorScheme + else -> darkColorScheme } - - dynamicColorScheme( - keyColor = keyColor, - isDark = true, - style = currentMonetMode, - ) } !isDynamicThemeEnabled and currentCustomColor.isSpecified -> { dynamicColorScheme( @@ -173,9 +189,9 @@ class ThemmoController( // Turning into amoled if needed return if (isAmoledThemeEnabled) { - dark.copy(background = Color.Black, surface = Color.Black) + darkColorScheme.copy(background = Color.Black, surface = Color.Black) } else { - dark + darkColorScheme } } diff --git a/themmosample/build.gradle.kts b/themmosample/build.gradle.kts index 6692838..8f291cb 100644 --- a/themmosample/build.gradle.kts +++ b/themmosample/build.gradle.kts @@ -3,7 +3,6 @@ plugins { id("kotlin-android") } -@Suppress("UnstableApiUsage") android { compileSdk = 34 @@ -40,9 +39,9 @@ android { compose = true } composeOptions { - kotlinCompilerExtensionVersion = "1.4.4" + kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get().toString() } - packagingOptions { + packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } @@ -51,13 +50,13 @@ android { } dependencies { - implementation("androidx.core:core-ktx:1.12.0") - implementation("androidx.compose.ui:ui:1.6.0-alpha06") - implementation("androidx.compose.ui:ui-tooling-preview:1.6.0-alpha06") - debugImplementation("androidx.compose.ui:ui-tooling:1.6.0-alpha06") - implementation("androidx.compose.material3:material3:1.2.0-alpha08") - implementation("androidx.activity:activity-compose:1.7.2") - testImplementation("junit:junit:4.13.2") - androidTestImplementation("androidx.test.ext:junit:1.1.5") + implementation(libs.androidx.core.core.ktx) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.tooling.preview) + debugImplementation(libs.androidx.compose.ui.tooling) + implementation(libs.androidx.compose.material3) + implementation(libs.androidx.activity.activity.compose) + testImplementation(libs.junit.junit) + androidTestImplementation(libs.androidx.test.ext.junit.ktx) implementation(project(mapOf("path" to ":themmo"))) } \ No newline at end of file