Opt theme color management
adjust button color to fit dark mode
This commit is contained in:
@@ -111,8 +111,9 @@ import shirkneko.zako.sukisu.ui.viewmodel.ModuleViewModel
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.util.zip.ZipInputStream
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.material3.FloatingActionButtonDefaults
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import shirkneko.zako.sukisu.ui.theme.CardConfig
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@@ -342,6 +343,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
floatingActionButton = {
|
||||
if (!hideInstallButton) {
|
||||
val moduleInstall = stringResource(id = R.string.module_install)
|
||||
val cardColor = MaterialTheme.colorScheme.secondaryContainer
|
||||
ExtendedFloatingActionButton(
|
||||
onClick = {
|
||||
selectZipLauncher.launch(
|
||||
@@ -362,12 +364,8 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
text = moduleInstall
|
||||
)
|
||||
},
|
||||
elevation = FloatingActionButtonDefaults.elevation(
|
||||
defaultElevation = 0.dp,
|
||||
pressedElevation = 0.dp,
|
||||
focusedElevation = 0.dp,
|
||||
hoveredElevation = 0.dp
|
||||
)
|
||||
containerColor = cardColor.copy(alpha = 1f),
|
||||
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -62,6 +62,7 @@ import kotlinx.coroutines.launch
|
||||
import shirkneko.zako.sukisu.R
|
||||
import shirkneko.zako.sukisu.ui.viewmodel.TemplateViewModel
|
||||
import androidx.lifecycle.compose.dropUnlessResumed
|
||||
import shirkneko.zako.sukisu.ui.theme.CardConfig
|
||||
|
||||
/**
|
||||
* @author weishu
|
||||
@@ -78,6 +79,7 @@ fun AppProfileTemplateScreen(
|
||||
val viewModel = viewModel<TemplateViewModel>()
|
||||
val scope = rememberCoroutineScope()
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
|
||||
val cardColor = MaterialTheme.colorScheme.secondaryContainer
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
if (viewModel.templateList.isEmpty()) {
|
||||
@@ -149,12 +151,8 @@ fun AppProfileTemplateScreen(
|
||||
},
|
||||
icon = { Icon(Icons.Filled.Add, null) },
|
||||
text = { Text(stringResource(id = R.string.app_profile_template_create)) },
|
||||
elevation = FloatingActionButtonDefaults.elevation(
|
||||
defaultElevation = 0.dp,
|
||||
pressedElevation = 0.dp,
|
||||
focusedElevation = 0.dp,
|
||||
hoveredElevation = 0.dp
|
||||
)
|
||||
containerColor = cardColor.copy(alpha = 1f),
|
||||
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
|
||||
)
|
||||
},
|
||||
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal)
|
||||
|
||||
@@ -26,6 +26,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.zIndex
|
||||
import coil.compose.rememberAsyncImagePainter
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
@@ -125,21 +126,34 @@ fun KernelSUTheme(
|
||||
|
||||
val colorScheme = when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
if (darkTheme) dynamicDarkColorScheme(context).copy(
|
||||
background = Color.Transparent,
|
||||
surface = Color.Transparent,
|
||||
onBackground = Color.White,
|
||||
onSurface = Color.White,
|
||||
onPrimary = Color.White,
|
||||
onSecondary = Color.White,
|
||||
onTertiary = Color.White,
|
||||
onPrimaryContainer = Color.White,
|
||||
onSecondaryContainer = Color.White,
|
||||
onTertiaryContainer = Color.White
|
||||
) else dynamicLightColorScheme(context).copy(
|
||||
background = Color.Transparent,
|
||||
surface = Color.Transparent
|
||||
)
|
||||
if (darkTheme) {
|
||||
val originalScheme = dynamicDarkColorScheme(context)
|
||||
originalScheme.copy(
|
||||
// 调整按钮相关颜色
|
||||
primary = adjustColor(originalScheme.primary),
|
||||
onPrimary = adjustColor(originalScheme.onPrimary),
|
||||
primaryContainer = adjustColor(originalScheme.primaryContainer),
|
||||
onPrimaryContainer = adjustColor(originalScheme.onPrimaryContainer),
|
||||
background = Color.Transparent,
|
||||
surface = Color.Transparent,
|
||||
onBackground = Color.White,
|
||||
onSurface = Color.White,
|
||||
onSecondary = Color.White,
|
||||
onTertiary = Color.White,
|
||||
onSecondaryContainer = Color.White,
|
||||
onTertiaryContainer = Color.White
|
||||
)
|
||||
} else {
|
||||
val originalScheme = dynamicLightColorScheme(context)
|
||||
originalScheme.copy(
|
||||
primary = adjustColor(originalScheme.primary),
|
||||
onPrimary = adjustColor(originalScheme.onPrimary),
|
||||
primaryContainer = adjustColor(originalScheme.primaryContainer),
|
||||
onPrimaryContainer = adjustColor(originalScheme.onPrimaryContainer),
|
||||
background = Color.Transparent,
|
||||
surface = Color.Transparent
|
||||
)
|
||||
}
|
||||
}
|
||||
darkTheme -> getDarkColorScheme()
|
||||
else -> getLightColorScheme()
|
||||
@@ -307,4 +321,16 @@ fun Context.loadDynamicColorState() {
|
||||
val enabled = getSharedPreferences("theme_prefs", Context.MODE_PRIVATE)
|
||||
.getBoolean("use_dynamic_color", true)
|
||||
ThemeConfig.useDynamicColor = enabled
|
||||
}
|
||||
|
||||
private fun adjustColor(color: Color): Color {
|
||||
val minLuminance = 0.75f
|
||||
val maxLuminance = 1f
|
||||
var luminance = color.luminance()
|
||||
if (luminance < minLuminance) {
|
||||
luminance = minLuminance
|
||||
} else if (luminance > maxLuminance) {
|
||||
luminance = maxLuminance
|
||||
}
|
||||
return color.copy(luminance)
|
||||
}
|
||||
Reference in New Issue
Block a user