[新增] 合并代码

This commit is contained in:
HapeLee
2026-01-17 06:43:05 +08:00
parent 66c5de6f18
commit bfcb9f88a9
10 changed files with 97 additions and 17 deletions
@@ -94,6 +94,8 @@ object PreferKey {
const val defaultCoverDark = "defaultCoverDark"
const val replaceEnableDefault = "replaceEnableDefault"
const val showBrightnessView = "showBrightnessView"
const val useUnderline = "useUnderline"
const val adaptSpecialStyle = "adaptSpecialStyle"
const val autoClearExpired = "autoClearExpired"
const val autoChangeSource = "autoChangeSource"
const val importKeepName = "importKeepName"
@@ -174,6 +176,8 @@ object PreferKey {
const val cAccent = "colorAccent"
const val customMode = "customMode"
const val paletteStyle = "paletteStyle"
const val composeEngine = "composeEngine"
const val containerOpacity = "containerOpacity"
const val enableBlur = "enableBlur"
const val cBackground = "colorBackground"
const val cBBackground = "colorBottomBackground"
@@ -53,14 +53,26 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
var themeMode = appCtx.getPrefString(PreferKey.themeMode, "0")
var AppTheme = appCtx.getPrefString(PreferKey.appTheme, "0")
var containerOpacity = appCtx.getPrefInt(PreferKey.containerOpacity, 100)
var useDefaultCover = appCtx.getPrefBoolean(PreferKey.useDefaultCover, false)
var optimizeRender = CanvasRecorderFactory.isSupport
&& appCtx.getPrefBoolean(PreferKey.optimizeRender, false)
var recordLog = appCtx.getPrefBoolean(PreferKey.recordLog)
// -- lyc 版本特性 --
var adaptSpecialStyle = appCtx.getPrefBoolean(PreferKey.adaptSpecialStyle, true)
var useUnderline = appCtx.getPrefBoolean(PreferKey.useUnderline, false)
var webServiceAutoStart = appCtx.getPrefBoolean(PreferKey.webServiceAutoStart)
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) {
PreferKey.adaptSpecialStyle -> adaptSpecialStyle =
appCtx.getPrefBoolean(PreferKey.adaptSpecialStyle, true)
PreferKey.useUnderline -> useUnderline =
appCtx.getPrefBoolean(PreferKey.useUnderline, false)
PreferKey.appTheme -> {
AppTheme = appCtx.getPrefString(PreferKey.appTheme, "0")
}
@@ -973,16 +985,6 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefBoolean(PreferKey.sliderVibrator, value)
}
val audioPreDownloadNum: Int
get() = appCtx.getPrefInt(PreferKey.audioPreDownloadNum, 10)
val audioCacheCleanTimeOrgin: Int
get() = appCtx.getPrefInt(PreferKey.audioCacheCleanTime, 10)
val audioCacheCleanTime: Long
get() {
val str = appCtx.getPrefInt(PreferKey.audioCacheCleanTime, 10)
return str * 60 * 1000L
}
}
@@ -87,6 +87,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
addPreferencesFromResource(R.xml.pref_config_theme)
upPreferenceSummary(PreferKey.fontScale)
upPreferenceSummary(PreferKey.containerOpacity)
findPreference<ColorPreference>(PreferKey.cBackground)?.let {
it.onSaveColor = { color ->
@@ -254,6 +255,20 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
recreateActivities()
}
PreferKey.containerOpacity -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.container_opacity))
.setMaxValue(100)
.setMinValue(0)
.setValue(100)
.setCustomButton((R.string.btn_default_s)) {
putPrefInt(PreferKey.containerOpacity, 100)
ThemeSyncer.syncContainerOpacity()
}
.show {
putPrefInt(PreferKey.containerOpacity, it)
ThemeSyncer.syncContainerOpacity()
}
PreferKey.bgImage -> selectBgAction(false)
PreferKey.bgImageN -> selectBgAction(true)
"colorImage" -> selectBgAction(null)
@@ -402,6 +417,10 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
when (preferenceKey) {
//PreferKey.barElevation -> preference.summary =
// getString(R.string.bar_elevation_s, value)
PreferKey.containerOpacity -> {
preference.summary =
getString(R.string.container_opacity_summary, AppConfig.containerOpacity)
}
PreferKey.fontScale -> {
val fontScale = AppContextWrapper.getFontScale(requireContext())
@@ -20,13 +20,15 @@ fun AppTheme(
val isPureBlack by ThemeState.isPureBlack.collectAsState()
val hasImageBg by ThemeState.hasImageBg.collectAsState()
val paletteStyle by ThemeState.paletteStyle.collectAsState()
val opacity by ThemeState.containerOpacity.collectAsState()
val colorScheme = ThemeManager.getColorScheme(
mode = appThemeMode,
darkTheme = darkTheme,
isAmoled = isPureBlack,
isImageBg = hasImageBg,
paletteStyle = paletteStyle
paletteStyle = paletteStyle,
opacity = opacity
)
MaterialExpressiveTheme(
@@ -47,7 +47,8 @@ object ThemeManager {
isAmoled: Boolean,
isImageBg: Boolean,
paletteStyle: String?,
forceOpaque: Boolean = false
forceOpaque: Boolean = false,
opacity: Int = 100
): ColorScheme {
val context = LocalContext.current
val style = resolvePaletteStyle(paletteStyle)
@@ -83,16 +84,27 @@ object ThemeManager {
)
}
return if (!forceOpaque && (isImageBg || actualMode == AppThemeMode.Transparent)) {
scheme.copy(
if (!forceOpaque && (isImageBg || actualMode == AppThemeMode.Transparent)) {
return scheme.copy(
surface = Color.Transparent,
background = Color.Transparent,
surfaceContainerLow = Color.Transparent,
surfaceContainer = Color.Transparent
surfaceContainer = Color.Transparent,
)
}
val alpha = opacity / 100f
return if (opacity < 100 && !forceOpaque) {
scheme.copy(
surfaceContainerLowest = scheme.surfaceContainerLowest.copy(alpha = alpha),
surfaceContainerLow = scheme.surfaceContainerLow.copy(alpha = alpha),
surfaceContainer = scheme.surfaceContainer.copy(alpha = alpha),
surfaceContainerHigh = scheme.surfaceContainerHigh.copy(alpha = alpha),
surfaceContainerHighest = scheme.surfaceContainerHighest.copy(alpha = alpha),
)
} else {
scheme
}
}
}
@@ -30,6 +30,10 @@ object ThemeState {
MutableStateFlow(AppConfig.enableBlur)
val enableBlur: StateFlow<Boolean> = _enableBlur.asStateFlow()
private val _containerOpacity =
MutableStateFlow(AppConfig.containerOpacity)
val containerOpacity: StateFlow<Int> = _containerOpacity
fun updateThemeMode(newMode: AppThemeMode) {
if (_themeMode.value != newMode) {
_themeMode.value = newMode
@@ -60,4 +64,10 @@ object ThemeState {
}
}
fun updateContainerOpacity(opacity: Int) {
if (_containerOpacity.value != opacity) {
_containerOpacity.value = opacity
}
}
}
@@ -13,6 +13,7 @@ object ThemeSyncer {
syncImageBg()
syncPaletteStyle()
syncEnableBlur()
syncContainerOpacity()
}
fun syncThemeMode() {
@@ -36,4 +37,9 @@ object ThemeSyncer {
fun syncEnableBlur() {
ThemeState.updateEnableBlur(AppConfig.enableBlur)
}
fun syncContainerOpacity() {
ThemeState.updateContainerOpacity(AppConfig.containerOpacity)
}
}