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