|
|
@@ -3,8 +3,6 @@ package io.legado.app.ui.config.themeConfig
|
|
|
import android.annotation.SuppressLint
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
-import android.os.Handler
|
|
|
-import android.os.Looper
|
|
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
|
import androidx.compose.animation.AnimatedVisibility
|
|
|
@@ -85,7 +83,6 @@ import io.legado.app.ui.widget.components.AppScaffold
|
|
|
import io.legado.app.ui.widget.components.FontFolderState
|
|
|
import io.legado.app.ui.widget.components.FontSelectSheet
|
|
|
import io.legado.app.ui.widget.components.SplicedColumnGroup
|
|
|
-import io.legado.app.ui.widget.components.alert.AppAlertDialog
|
|
|
import io.legado.app.ui.widget.components.button.series.SmallPlainButton
|
|
|
import io.legado.app.ui.widget.components.card.GlassCard
|
|
|
import io.legado.app.ui.widget.components.dialog.ColorPickerSheet
|
|
|
@@ -99,7 +96,6 @@ import io.legado.app.ui.widget.components.topbar.GlassMediumFlexibleTopAppBar
|
|
|
import io.legado.app.ui.widget.components.topbar.GlassTopAppBarDefaults
|
|
|
import io.legado.app.ui.widget.components.topbar.TopBarNavigationButton
|
|
|
import io.legado.app.utils.postEvent
|
|
|
-import io.legado.app.utils.restart
|
|
|
import io.legado.app.utils.takePersistablePermissionSafely
|
|
|
import io.legado.app.utils.toastOnUi
|
|
|
import org.koin.androidx.compose.koinViewModel
|
|
|
@@ -119,7 +115,6 @@ fun ThemeConfigScreen(
|
|
|
var selectedThemeMode by remember { mutableStateOf(ThemeConfig.themeMode) }
|
|
|
var selectedTheme by remember { mutableStateOf(ThemeConfig.appTheme) }
|
|
|
var useMiuixMonet by remember { mutableStateOf(ThemeConfig.useMiuixMonet) }
|
|
|
- var showRestartDialog by remember { mutableStateOf(false) }
|
|
|
var showLauncherIconPicker by remember { mutableStateOf(false) }
|
|
|
var showBorderColorPicker by remember { mutableStateOf(false) }
|
|
|
var showNavIconSheet by remember { mutableStateOf(false) }
|
|
|
@@ -239,7 +234,7 @@ fun ThemeConfigScreen(
|
|
|
onValueChange = { mode ->
|
|
|
selectedThemeMode = mode
|
|
|
ThemeConfig.themeMode = mode
|
|
|
- ThemeConfigStore.applyDayNight(context)
|
|
|
+ ThemeConfigStore.applyDayNightLive()
|
|
|
}
|
|
|
)
|
|
|
|
|
|
@@ -268,7 +263,7 @@ fun ThemeConfigScreen(
|
|
|
selectedTheme = newTheme
|
|
|
ThemeConfig.appTheme = newTheme
|
|
|
if (oldTheme != newTheme) {
|
|
|
- showRestartDialog = true
|
|
|
+ postEvent(EventBus.RECREATE, "")
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
@@ -279,7 +274,7 @@ fun ThemeConfigScreen(
|
|
|
onModeSelected = { mode ->
|
|
|
selectedThemeMode = mode
|
|
|
ThemeConfig.themeMode = mode
|
|
|
- ThemeConfigStore.applyDayNight(context)
|
|
|
+ ThemeConfigStore.applyDayNightLive()
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
@@ -310,15 +305,9 @@ fun ThemeConfigScreen(
|
|
|
ThemeConfig.containerOpacity = 0
|
|
|
}
|
|
|
}
|
|
|
- val oldTheme = selectedTheme
|
|
|
selectedTheme = theme
|
|
|
ThemeConfig.appTheme = theme
|
|
|
- val isDynamicSwitch = (oldTheme == "12" || theme == "12")
|
|
|
- if (isDynamicSwitch) {
|
|
|
- showRestartDialog = true
|
|
|
- } else {
|
|
|
- postEvent(EventBus.RECREATE, "")
|
|
|
- }
|
|
|
+ postEvent(EventBus.RECREATE, "")
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
@@ -819,25 +808,6 @@ fun ThemeConfigScreen(
|
|
|
}
|
|
|
|
|
|
|
|
|
- AppAlertDialog(
|
|
|
- show = showRestartDialog,
|
|
|
- onDismissRequest = { showRestartDialog = false },
|
|
|
- title = stringResource(R.string.restart_required_message),
|
|
|
- onConfirm = {
|
|
|
- showRestartDialog = false
|
|
|
- Handler(Looper.getMainLooper()).postDelayed({
|
|
|
- context.restart()
|
|
|
- }, 100)
|
|
|
- },
|
|
|
- confirmText = stringResource(R.string.ok),
|
|
|
- onDismiss = {
|
|
|
- showRestartDialog = false
|
|
|
- context.toastOnUi(R.string.restart_later_message)
|
|
|
- },
|
|
|
- dismissText = stringResource(R.string.cancel)
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
BackgroundImageManageSheet(
|
|
|
isDarkTheme = manageKey,
|
|
|
onDismissRequest = { manageKey = null }
|
|
|
@@ -1005,15 +975,20 @@ fun ThemeColorButton(
|
|
|
customNightSeedColor: Int,
|
|
|
onClick: () -> Unit
|
|
|
) {
|
|
|
- val colors = getThemeColorPalette(
|
|
|
- context = context,
|
|
|
- value = value,
|
|
|
- isDark = isDark,
|
|
|
- isAmoled = isAmoled,
|
|
|
- paletteStyle = paletteStyle,
|
|
|
- customLightSeedColor = customLightSeedColor,
|
|
|
- customNightSeedColor = customNightSeedColor
|
|
|
- )
|
|
|
+ // 配色方案由种子色实时生成,开销不小,缓存避免无关重组时重复计算
|
|
|
+ val colors = remember(
|
|
|
+ value, isDark, isAmoled, paletteStyle, customLightSeedColor, customNightSeedColor
|
|
|
+ ) {
|
|
|
+ getThemeColorPalette(
|
|
|
+ context = context,
|
|
|
+ value = value,
|
|
|
+ isDark = isDark,
|
|
|
+ isAmoled = isAmoled,
|
|
|
+ paletteStyle = paletteStyle,
|
|
|
+ customLightSeedColor = customLightSeedColor,
|
|
|
+ customNightSeedColor = customNightSeedColor
|
|
|
+ )
|
|
|
+ }
|
|
|
val borderWidth by animateDpAsState(
|
|
|
targetValue = if (isSelected) 2.dp else 0.dp,
|
|
|
label = "borderWidth"
|
|
|
@@ -1106,15 +1081,19 @@ fun ThemeCard(
|
|
|
customLightSeedColor: Int,
|
|
|
customNightSeedColor: Int
|
|
|
) {
|
|
|
- val colors = getThemeColors(
|
|
|
- context = context,
|
|
|
- value = value,
|
|
|
- isDark = isDark,
|
|
|
- isAmoled = isAmoled,
|
|
|
- paletteStyle = paletteStyle,
|
|
|
- customLightSeedColor = customLightSeedColor,
|
|
|
- customNightSeedColor = customNightSeedColor
|
|
|
- )
|
|
|
+ val colors = remember(
|
|
|
+ value, isDark, isAmoled, paletteStyle, customLightSeedColor, customNightSeedColor
|
|
|
+ ) {
|
|
|
+ getThemeColors(
|
|
|
+ context = context,
|
|
|
+ value = value,
|
|
|
+ isDark = isDark,
|
|
|
+ isAmoled = isAmoled,
|
|
|
+ paletteStyle = paletteStyle,
|
|
|
+ customLightSeedColor = customLightSeedColor,
|
|
|
+ customNightSeedColor = customNightSeedColor
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
Column(
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|