Skip to content

Commit

Permalink
[feature|build] Support Amoled dark; update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Oct 23, 2024
1 parent e7e005d commit 41cb7ee
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 30 deletions.
22 changes: 11 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
minSdk = 24
targetSdk = 35
versionCode = 67
versionName = "2.3-alpha07"
versionName = "2.3-beta01"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -147,21 +147,21 @@ tasks.withType(KotlinCompile::class.java).configureEach {

dependencies {
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.compose.ui:ui:1.7.3")
implementation("androidx.compose.ui:ui:1.7.4")
implementation("androidx.compose.material3:material3:1.3.0")
implementation("androidx.compose.material3:material3-window-size-class:1.3.0")
implementation("androidx.compose.material:material:1.7.3")
implementation("androidx.compose.material:material-icons-extended:1.7.3")
implementation("androidx.compose.ui:ui-tooling-preview:1.7.3")
implementation("androidx.compose.material:material:1.7.4")
implementation("androidx.compose.material:material-icons-extended:1.7.4")
implementation("androidx.compose.ui:ui-tooling-preview:1.7.4")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.6")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.6")
implementation("androidx.activity:activity-compose:1.9.2")
implementation("androidx.activity:activity-compose:1.9.3")
implementation("androidx.palette:palette-ktx:1.0.0")
implementation("com.google.dagger:hilt-android:2.52")
ksp("com.google.dagger:hilt-android-compiler:2.52")
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
implementation("androidx.navigation:navigation-compose:2.8.2")
implementation("androidx.navigation:navigation-compose:2.8.3")
implementation("androidx.security:security-crypto:1.1.0-alpha06")
implementation("com.google.accompanist:accompanist-drawablepainter:0.36.0")
implementation("io.coil-kt:coil-compose:2.7.0")
Expand All @@ -173,8 +173,8 @@ dependencies {
implementation("androidx.room:room-ktx:2.6.1")
ksp("androidx.room:room-compiler:2.6.1")
implementation("com.github.thegrizzlylabs:sardine-android:0.8")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2")
implementation("com.materialkolor:material-kolor:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
implementation("com.materialkolor:material-kolor:2.0.0")
implementation("androidx.datastore:datastore-preferences:1.1.1")
implementation("com.airbnb.android:lottie-compose:6.5.2")

Expand All @@ -195,6 +195,6 @@ dependencies {

implementation("com.github.penfeizhou.android.animation:apng:3.0.1")

debugImplementation("androidx.compose.ui:ui-tooling:1.7.3")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.3")
debugImplementation("androidx.compose.ui:ui-tooling:1.7.4")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.4")
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/skyd/rays/ext/PreferenceExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.skyd.rays.model.preference.search.UseRegexSearchPreference
import com.skyd.rays.model.preference.share.CopyStickerToClipboardWhenSharingPreference
import com.skyd.rays.model.preference.share.StickerExtNamePreference
import com.skyd.rays.model.preference.share.UriStringSharePreference
import com.skyd.rays.model.preference.theme.AmoledDarkModePreference
import com.skyd.rays.model.preference.theme.CustomPrimaryColorPreference
import com.skyd.rays.model.preference.theme.DarkModePreference
import com.skyd.rays.model.preference.theme.StickerColorThemePreference
Expand All @@ -39,6 +40,7 @@ fun Preferences.toSettings(): Settings {
themeName = ThemeNamePreference.fromPreferences(this),
customPrimaryColor = CustomPrimaryColorPreference.fromPreferences(this),
darkMode = DarkModePreference.fromPreferences(this),
amoledDarkMode = AmoledDarkModePreference.fromPreferences(this),
stickerColorTheme = StickerColorThemePreference.fromPreferences(this),

// Theme
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/skyd/rays/model/preference/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import com.skyd.rays.model.preference.search.UseRegexSearchPreference
import com.skyd.rays.model.preference.share.CopyStickerToClipboardWhenSharingPreference
import com.skyd.rays.model.preference.share.StickerExtNamePreference
import com.skyd.rays.model.preference.share.UriStringSharePreference
import com.skyd.rays.model.preference.theme.AmoledDarkModePreference
import com.skyd.rays.model.preference.theme.CustomPrimaryColorPreference
import com.skyd.rays.model.preference.theme.DarkModePreference
import com.skyd.rays.model.preference.theme.StickerColorThemePreference
import com.skyd.rays.model.preference.theme.ThemeNamePreference
import com.skyd.rays.ui.local.LocalAmoledDarkMode
import com.skyd.rays.ui.local.LocalApiGrant
import com.skyd.rays.ui.local.LocalAutoShareIgnoreStrategy
import com.skyd.rays.ui.local.LocalBlurSticker
Expand Down Expand Up @@ -65,6 +67,7 @@ data class Settings(
val themeName: String = ThemeNamePreference.default,
val customPrimaryColor: String = CustomPrimaryColorPreference.default,
val darkMode: Int = DarkModePreference.default,
val amoledDarkMode: Boolean = AmoledDarkModePreference.default,
val stickerColorTheme: Boolean = StickerColorThemePreference.default,
// Update
val ignoreUpdateVersion: Long = IgnoreUpdateVersionPreference.default,
Expand Down Expand Up @@ -118,6 +121,7 @@ fun SettingsProvider(
LocalThemeName provides settings.themeName,
LocalCustomPrimaryColor provides settings.customPrimaryColor,
LocalDarkMode provides settings.darkMode,
LocalAmoledDarkMode provides settings.amoledDarkMode,
LocalStickerColorTheme provides settings.stickerColorTheme,
// Update
LocalIgnoreUpdateVersion provides settings.ignoreUpdateVersion,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.skyd.rays.model.preference.theme

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import com.skyd.rays.ext.dataStore
import com.skyd.rays.ext.put
import com.skyd.rays.model.preference.BasePreference
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

object AmoledDarkModePreference : BasePreference<Boolean> {
private const val AMOLED_DARK_MODE = "amoledDarkMode"
override val default = false

val key = booleanPreferencesKey(AMOLED_DARK_MODE)

fun put(context: Context, scope: CoroutineScope, value: Boolean) {
scope.launch(Dispatchers.IO) {
context.dataStore.put(key, value)
}
}

override fun fromPreferences(preferences: Preferences): Boolean = preferences[key] ?: default
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/skyd/rays/ui/local/LocalValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.skyd.rays.model.preference.search.UseRegexSearchPreference
import com.skyd.rays.model.preference.share.CopyStickerToClipboardWhenSharingPreference
import com.skyd.rays.model.preference.share.StickerExtNamePreference
import com.skyd.rays.model.preference.share.UriStringSharePreference
import com.skyd.rays.model.preference.theme.AmoledDarkModePreference
import com.skyd.rays.model.preference.theme.CustomPrimaryColorPreference
import com.skyd.rays.model.preference.theme.DarkModePreference
import com.skyd.rays.model.preference.theme.StickerColorThemePreference
Expand All @@ -44,6 +45,7 @@ val LocalWindowSizeClass = compositionLocalOf<WindowSizeClass> {

// Theme
val LocalDarkMode = compositionLocalOf { DarkModePreference.default }
val LocalAmoledDarkMode = compositionLocalOf { AmoledDarkModePreference.default }
val LocalThemeName = compositionLocalOf { ThemeNamePreference.default }
val LocalCustomPrimaryColor = compositionLocalOf { CustomPrimaryColorPreference.default }
val LocalStickerColorTheme = compositionLocalOf { StickerColorThemePreference.default }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
Expand Down Expand Up @@ -376,9 +375,7 @@ fun MainCard(
FlowRow(
modifier = Modifier
.padding(vertical = 6.dp, horizontal = 16.dp)
.fillMaxWidth()
.heightIn(max = 150.dp)
.verticalScroll(rememberScrollState()),
.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(5.dp)
) {
repeat(tags.size) { index ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Check
import androidx.compose.material.icons.outlined.Contrast
import androidx.compose.material.icons.outlined.DarkMode
import androidx.compose.material.icons.outlined.Palette
import androidx.compose.material.icons.outlined.Search
Expand Down Expand Up @@ -67,6 +68,7 @@ import com.skyd.rays.ext.checkColorHex
import com.skyd.rays.ext.dataStore
import com.skyd.rays.ext.onDark
import com.skyd.rays.ext.toColorOrNull
import com.skyd.rays.model.preference.theme.AmoledDarkModePreference
import com.skyd.rays.model.preference.theme.CustomPrimaryColorPreference
import com.skyd.rays.model.preference.theme.DarkModePreference
import com.skyd.rays.model.preference.theme.StickerColorThemePreference
Expand All @@ -80,6 +82,7 @@ import com.skyd.rays.ui.component.RaysTopBar
import com.skyd.rays.ui.component.RaysTopBarStyle
import com.skyd.rays.ui.component.SwitchSettingsItem
import com.skyd.rays.ui.component.dialog.TextFieldDialog
import com.skyd.rays.ui.local.LocalAmoledDarkMode
import com.skyd.rays.ui.local.LocalCustomPrimaryColor
import com.skyd.rays.ui.local.LocalDarkMode
import com.skyd.rays.ui.local.LocalNavController
Expand Down Expand Up @@ -152,6 +155,20 @@ fun AppearanceScreen() {
onClick = { openDarkBottomSheet = true }
)
}
item {
SwitchSettingsItem(
imageVector = Icons.Outlined.Contrast,
text = stringResource(id = R.string.appearance_screen_amoled_dark),
checked = LocalAmoledDarkMode.current,
onCheckedChange = {
AmoledDarkModePreference.put(
context = context,
scope = scope,
value = it,
)
}
)
}
item {
SwitchSettingsItem(
imageVector = Icons.Outlined.Palette,
Expand Down
31 changes: 23 additions & 8 deletions app/src/main/java/com/skyd/rays/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.skyd.rays.ext.activity
import com.skyd.rays.ext.toColorOrNull
import com.skyd.rays.model.preference.theme.DarkModePreference
import com.skyd.rays.model.preference.theme.ThemeNamePreference
import com.skyd.rays.ui.local.LocalAmoledDarkMode
import com.skyd.rays.ui.local.LocalCustomPrimaryColor
import com.skyd.rays.ui.local.LocalThemeName

Expand Down Expand Up @@ -47,14 +48,15 @@ fun RaysTheme(
}

val themeName = LocalThemeName.current
val amoledDarkMode = LocalAmoledDarkMode.current

MaterialTheme(
colorScheme = remember(themeName, LocalCustomPrimaryColor.current) {
colorScheme = remember(themeName, LocalCustomPrimaryColor.current, amoledDarkMode) {
wallpaperColors.getOrElse(themeName) {
dynamicColorScheme(
seedColor = ThemeNamePreference.values[0].keyColor,
isDark = darkTheme,
isAmoled = false,
isAmoled = amoledDarkMode,
)
}
},
Expand Down Expand Up @@ -88,12 +90,19 @@ fun extractAllColors(darkTheme: Boolean): Map<String, ColorScheme> {
@Composable
fun extractColors(darkTheme: Boolean): Map<String, ColorScheme> {
return ThemeNamePreference.values.associate {
it.name to rememberDynamicColorScheme(it.keyColor, isDark = darkTheme)
it.name to rememberDynamicColorScheme(
primary = it.keyColor,
isDark = darkTheme,
isAmoled = LocalAmoledDarkMode.current,
)
}.toMutableMap().also { map ->
val customPrimaryColor =
LocalCustomPrimaryColor.current.toColorOrNull() ?: Color.Transparent
map[ThemeNamePreference.CUSTOM_THEME_NAME] =
rememberDynamicColorScheme(customPrimaryColor, isDark = darkTheme)
map[ThemeNamePreference.CUSTOM_THEME_NAME] = rememberDynamicColorScheme(
primary = customPrimaryColor,
isDark = darkTheme,
isAmoled = LocalAmoledDarkMode.current,
)
}
}

Expand All @@ -113,18 +122,24 @@ fun extractColorsFromWallpaper(darkTheme: Boolean): Map<String, ColorScheme> {
preset["WallpaperPrimary"] = rememberSystemDynamicColorScheme(isDark = darkTheme)
} else {
preset["WallpaperPrimary"] = rememberDynamicColorScheme(
seedColor = Color(primary), isDark = darkTheme,
primary = Color(primary),
isDark = darkTheme,
isAmoled = LocalAmoledDarkMode.current,
)
}
}
if (secondary != null) {
preset["WallpaperSecondary"] = rememberDynamicColorScheme(
seedColor = Color(secondary), isDark = darkTheme,
primary = Color(secondary),
isDark = darkTheme,
isAmoled = LocalAmoledDarkMode.current,
)
}
if (tertiary != null) {
preset["WallpaperTertiary"] = rememberDynamicColorScheme(
seedColor = Color(tertiary), isDark = darkTheme,
primary = Color(tertiary),
isDark = darkTheme,
isAmoled = LocalAmoledDarkMode.current,
)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,5 @@
<string name="copied">已复制</string>
<string name="crash_screen_crash_log">日志</string>
<string name="crash_screen_copy_crash_log">复制日志</string>
<string name="appearance_screen_amoled_dark">Amoled 深色</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,5 @@
<string name="copied">Copied</string>
<string name="crash_screen_crash_log">Log</string>
<string name="crash_screen_copy_crash_log">Copy log</string>
<string name="appearance_screen_amoled_dark">Amoled dark</string>
</resources>
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.5.2" apply false
id("com.android.library") version "8.5.2" apply false
id("org.jetbrains.kotlin.android") version "2.0.20" apply false
id("org.jetbrains.kotlin.plugin.compose") version "2.0.20"
id("org.jetbrains.kotlin.plugin.serialization") version "2.0.20"
id("com.android.application") version "8.7.1" apply false
id("com.android.library") version "8.7.1" apply false
id("org.jetbrains.kotlin.android") version "2.0.21" apply false
id("org.jetbrains.kotlin.plugin.compose") version "2.0.21"
id("org.jetbrains.kotlin.plugin.serialization") version "2.0.21"
id("com.google.dagger.hilt.android") version "2.51.1" apply false
id("com.google.devtools.ksp") version "2.0.20-1.0.24" apply false
id("com.google.devtools.ksp") version "2.0.21-1.0.25" apply false
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Mon Jul 29 23:47:06 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 41cb7ee

Please sign in to comment.