Opt theme mode management
Update card color and dark color setting logic
This commit is contained in:
@@ -148,7 +148,6 @@ private fun BottomBar(navController: NavHostController) {
|
|||||||
label = { Text(stringResource(destination.label)) },
|
label = { Text(stringResource(destination.label)) },
|
||||||
alwaysShowLabel = false,
|
alwaysShowLabel = false,
|
||||||
colors = androidx.compose.material3.NavigationBarItemDefaults.colors(
|
colors = androidx.compose.material3.NavigationBarItemDefaults.colors(
|
||||||
selectedTextColor = Color.Black,
|
|
||||||
unselectedTextColor = MaterialTheme.colorScheme.onSurfaceVariant
|
unselectedTextColor = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
|||||||
val snackBarHost = LocalSnackbarHost.current
|
val snackBarHost = LocalSnackbarHost.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val confirmDialog = rememberConfirmDialog()
|
val confirmDialog = rememberConfirmDialog()
|
||||||
val buttonTextColor = androidx.compose.ui.graphics.Color.Black
|
|
||||||
|
|
||||||
val selectZipLauncher = rememberLauncherForActivityResult(
|
val selectZipLauncher = rememberLauncherForActivityResult(
|
||||||
contract = ActivityResultContracts.StartActivityForResult()
|
contract = ActivityResultContracts.StartActivityForResult()
|
||||||
|
|||||||
@@ -356,6 +356,9 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
|
|||||||
cardAlpha = 0.65f
|
cardAlpha = 0.65f
|
||||||
themeMode = 0
|
themeMode = 0
|
||||||
context.saveThemeMode(null)
|
context.saveThemeMode(null)
|
||||||
|
CardConfig.isUserDarkModeEnabled = false
|
||||||
|
CardConfig.isUserLightModeEnabled = false
|
||||||
|
CardConfig.save(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -424,6 +427,26 @@ fun MoreSettingsScreen(navigator: DestinationsNavigator) {
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
context.saveThemeMode(newThemeMode)
|
context.saveThemeMode(newThemeMode)
|
||||||
|
when (index) {
|
||||||
|
2 -> {
|
||||||
|
ThemeConfig.forceDarkMode = true
|
||||||
|
CardConfig.isUserLightModeEnabled = false
|
||||||
|
CardConfig.isUserDarkModeEnabled = true
|
||||||
|
CardConfig.save(context)
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
|
ThemeConfig.forceDarkMode = false
|
||||||
|
CardConfig.isUserLightModeEnabled = true
|
||||||
|
CardConfig.isUserDarkModeEnabled = false
|
||||||
|
CardConfig.save(context)
|
||||||
|
}
|
||||||
|
0 -> {
|
||||||
|
ThemeConfig.forceDarkMode = null
|
||||||
|
CardConfig.isUserLightModeEnabled = false
|
||||||
|
CardConfig.isUserDarkModeEnabled = false
|
||||||
|
CardConfig.save(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
showThemeModeDialog = false
|
showThemeModeDialog = false
|
||||||
}
|
}
|
||||||
.padding(vertical = 12.dp),
|
.padding(vertical = 12.dp),
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package shirkneko.zako.sukisu.ui.theme
|
package shirkneko.zako.sukisu.ui.theme
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -9,7 +11,6 @@ import androidx.compose.ui.graphics.Color
|
|||||||
import androidx.compose.ui.graphics.luminance
|
import androidx.compose.ui.graphics.luminance
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.material3.CardDefaults
|
|
||||||
|
|
||||||
object CardConfig {
|
object CardConfig {
|
||||||
val defaultElevation: Dp = 0.dp
|
val defaultElevation: Dp = 0.dp
|
||||||
@@ -18,6 +19,9 @@ object CardConfig {
|
|||||||
var cardElevation by mutableStateOf(defaultElevation)
|
var cardElevation by mutableStateOf(defaultElevation)
|
||||||
var isShadowEnabled by mutableStateOf(true)
|
var isShadowEnabled by mutableStateOf(true)
|
||||||
var isCustomAlphaSet by mutableStateOf(false)
|
var isCustomAlphaSet by mutableStateOf(false)
|
||||||
|
var isUserDarkModeEnabled by mutableStateOf(false)
|
||||||
|
var isUserLightModeEnabled by mutableStateOf(false)
|
||||||
|
var isCustomBackgroundEnabled by mutableStateOf(false)
|
||||||
|
|
||||||
fun save(context: Context) {
|
fun save(context: Context) {
|
||||||
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
val prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||||
@@ -25,6 +29,9 @@ object CardConfig {
|
|||||||
putFloat("card_alpha", cardAlpha)
|
putFloat("card_alpha", cardAlpha)
|
||||||
putBoolean("custom_background_enabled", cardElevation == 0.dp)
|
putBoolean("custom_background_enabled", cardElevation == 0.dp)
|
||||||
putBoolean("is_custom_alpha_set", isCustomAlphaSet)
|
putBoolean("is_custom_alpha_set", isCustomAlphaSet)
|
||||||
|
putBoolean("is_user_dark_mode_enabled", isUserDarkModeEnabled)
|
||||||
|
putBoolean("is_user_light_mode_enabled", isUserLightModeEnabled)
|
||||||
|
putBoolean("is_custom_background_enabled", isCustomBackgroundEnabled)
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,6 +41,9 @@ object CardConfig {
|
|||||||
cardAlpha = prefs.getFloat("card_alpha", 1f)
|
cardAlpha = prefs.getFloat("card_alpha", 1f)
|
||||||
cardElevation = if (prefs.getBoolean("custom_background_enabled", false)) 0.dp else defaultElevation
|
cardElevation = if (prefs.getBoolean("custom_background_enabled", false)) 0.dp else defaultElevation
|
||||||
isCustomAlphaSet = prefs.getBoolean("is_custom_alpha_set", false)
|
isCustomAlphaSet = prefs.getBoolean("is_custom_alpha_set", false)
|
||||||
|
isUserDarkModeEnabled = prefs.getBoolean("is_user_dark_mode_enabled", false)
|
||||||
|
isUserLightModeEnabled = prefs.getBoolean("is_user_light_mode_enabled", false)
|
||||||
|
isCustomBackgroundEnabled = prefs.getBoolean("is_custom_background_enabled", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateShadowEnabled(enabled: Boolean) {
|
fun updateShadowEnabled(enabled: Boolean) {
|
||||||
@@ -53,7 +63,26 @@ object CardConfig {
|
|||||||
@Composable
|
@Composable
|
||||||
fun getCardColors(originalColor: Color) = CardDefaults.elevatedCardColors(
|
fun getCardColors(originalColor: Color) = CardDefaults.elevatedCardColors(
|
||||||
containerColor = originalColor.copy(alpha = CardConfig.cardAlpha),
|
containerColor = originalColor.copy(alpha = CardConfig.cardAlpha),
|
||||||
contentColor = if (originalColor.luminance() > 0.5) Color.Black else Color.White
|
contentColor = when {
|
||||||
|
CardConfig.isUserLightModeEnabled -> {
|
||||||
|
Color.Black
|
||||||
|
}
|
||||||
|
CardConfig.isUserDarkModeEnabled -> {
|
||||||
|
Color.White
|
||||||
|
}
|
||||||
|
!isSystemInDarkTheme() && !CardConfig.isUserDarkModeEnabled -> {
|
||||||
|
Color.Black
|
||||||
|
}
|
||||||
|
!isSystemInDarkTheme() && !CardConfig.isCustomBackgroundEnabled && !CardConfig.isUserDarkModeEnabled && originalColor.luminance() > 0.3 -> {
|
||||||
|
Color.Black
|
||||||
|
}
|
||||||
|
isSystemInDarkTheme() && !CardConfig.isUserDarkModeEnabled && !CardConfig.isUserLightModeEnabled-> {
|
||||||
|
Color.White
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Color.White
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getCardElevation() = CardConfig.cardElevation
|
fun getCardElevation() = CardConfig.cardElevation
|
||||||
Reference in New Issue
Block a user