Przeglądaj źródła

feat: 主题重置

HapeLee 3 miesięcy temu
rodzic
commit
bf528a1bed

+ 8 - 0
app/src/main/java/io/legado/app/ui/config/themeConfig/ThemeConfigContract.kt

@@ -11,6 +11,7 @@ data class ThemeConfigUiState(
     val theme: ThemeSettings = ThemeSettings(),
     val fontFolder: String = "",
     val activeSheet: ThemeConfigSheet? = null,
+    val activeDialog: ThemeConfigDialog? = null,
     val showEInkTheme: Boolean = false,
 )
 
@@ -24,6 +25,10 @@ sealed interface ThemeConfigSheet {
     data object Font : ThemeConfigSheet
 }
 
+sealed interface ThemeConfigDialog {
+    data object ResetDefaults : ThemeConfigDialog
+}
+
 enum class ThemeTimeField {
     EyeProtectionStart,
     EyeProtectionEnd,
@@ -35,6 +40,9 @@ sealed interface ThemeConfigIntent {
     ) : ThemeConfigIntent
     data class ShowSheet(val sheet: ThemeConfigSheet) : ThemeConfigIntent
     data object DismissSheet : ThemeConfigIntent
+    data class ShowDialog(val dialog: ThemeConfigDialog) : ThemeConfigIntent
+    data object DismissDialog : ThemeConfigIntent
+    data object ResetDefaults : ThemeConfigIntent
     data class SelectTheme(val value: String) : ThemeConfigIntent
     data class SetThemeMode(val value: String) : ThemeConfigIntent
     data class SetComposeEngine(val value: String) : ThemeConfigIntent

+ 26 - 0
app/src/main/java/io/legado/app/ui/config/themeConfig/ThemeConfigScreen.kt

@@ -69,6 +69,7 @@ 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
@@ -835,9 +836,34 @@ fun ThemeConfigScreen(
                 }
             }
 
+            item {
+                SplicedColumnGroup {
+                    ClickableSettingItem(
+                        title = stringResource(R.string.theme_config_reset_defaults),
+                        description = stringResource(R.string.theme_config_reset_defaults_summary),
+                        onClick = {
+                            onIntent(
+                                ThemeConfigIntent.ShowDialog(ThemeConfigDialog.ResetDefaults)
+                            )
+                        }
+                    )
+                }
+            }
+
         }
     }
 
+    AppAlertDialog(
+        show = state.activeDialog == ThemeConfigDialog.ResetDefaults,
+        onDismissRequest = { onIntent(ThemeConfigIntent.DismissDialog) },
+        title = stringResource(R.string.theme_config_reset_defaults),
+        text = stringResource(R.string.theme_config_reset_defaults_confirm),
+        confirmText = stringResource(R.string.reset),
+        dismissText = stringResource(R.string.cancel),
+        onConfirm = { onIntent(ThemeConfigIntent.ResetDefaults) },
+        onDismiss = { onIntent(ThemeConfigIntent.DismissDialog) },
+    )
+
 
     BackgroundImageManageSheet(
         isDarkTheme = (state.activeSheet as? ThemeConfigSheet.Background)?.dark,

+ 336 - 3
app/src/main/java/io/legado/app/ui/config/themeConfig/ThemeConfigViewModel.kt

@@ -5,10 +5,20 @@ import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import io.legado.app.R
 import io.legado.app.constant.PreferKey
+import io.legado.app.domain.gateway.AppShellBooleanSetting
 import io.legado.app.domain.gateway.AppShellSettingsGateway
+import io.legado.app.domain.gateway.AppShellSettingsUpdate
+import io.legado.app.domain.gateway.AppShellStringSetting
+import io.legado.app.domain.gateway.LabSettingsGateway
 import io.legado.app.domain.gateway.ReadSettingsGateway
+import io.legado.app.domain.gateway.ReadSettingsUpdate
+import io.legado.app.domain.gateway.ThemeBooleanSetting
+import io.legado.app.domain.gateway.ThemeColorSlot
+import io.legado.app.domain.gateway.ThemeFloatSetting
+import io.legado.app.domain.gateway.ThemeIntSetting
 import io.legado.app.domain.gateway.ThemeSettingsGateway
-import io.legado.app.domain.gateway.LabSettingsGateway
+import io.legado.app.domain.gateway.ThemeSettingsUpdate
+import io.legado.app.domain.gateway.ThemeStringSetting
 import io.legado.app.domain.model.settings.AppShellSettings
 import io.legado.app.domain.model.settings.ThemeSettings
 import io.legado.app.ui.main.MainDestination
@@ -18,8 +28,6 @@ import io.legado.app.utils.MD5Utils
 import io.legado.app.utils.externalFiles
 import io.legado.app.utils.inputStream
 import io.legado.app.utils.openInputStream
-import java.io.File
-import java.io.FileOutputStream
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.MutableSharedFlow
 import kotlinx.coroutines.flow.MutableStateFlow
@@ -28,6 +36,8 @@ import kotlinx.coroutines.flow.asStateFlow
 import kotlinx.coroutines.flow.update
 import kotlinx.coroutines.launch
 import splitties.init.appCtx
+import java.io.File
+import java.io.FileOutputStream
 
 class ThemeConfigViewModel(
     private val appShellSettingsGateway: AppShellSettingsGateway,
@@ -79,6 +89,13 @@ class ThemeConfigViewModel(
                 _uiState.update { it.copy(activeSheet = intent.sheet) }
             ThemeConfigIntent.DismissSheet ->
                 _uiState.update { it.copy(activeSheet = null) }
+            is ThemeConfigIntent.ShowDialog ->
+                _uiState.update { it.copy(activeDialog = intent.dialog) }
+
+            ThemeConfigIntent.DismissDialog ->
+                _uiState.update { it.copy(activeDialog = null) }
+
+            ThemeConfigIntent.ResetDefaults -> resetDefaults()
             is ThemeConfigIntent.SelectTheme -> selectTheme(intent.value)
             is ThemeConfigIntent.SetThemeMode -> updateAppShell(
                 transform = { it.copy(themeMode = intent.value) },
@@ -165,6 +182,322 @@ class ThemeConfigViewModel(
         viewModelScope.launch { themeSettingsGateway.update(transform) }
     }
 
+    private fun resetDefaults() {
+        viewModelScope.launch(Dispatchers.IO) {
+            val defaultShell = AppShellSettings()
+            val defaultTheme = ThemeSettings()
+            val currentTheme = _uiState.value.theme
+
+            listOf(currentTheme.backgroundImageLight, currentTheme.backgroundImageDark)
+                .filterNotNull()
+                .map(::File)
+                .filter { it.absolutePath.startsWith(appCtx.externalFiles.absolutePath) }
+                .forEach { it.delete() }
+            listOf("home", "bookshelf", "explore", "rss", "my")
+                .map { File(appCtx.filesDir, "nav_icons/$it.png") }
+                .forEach { it.delete() }
+            currentTheme.appFontPath?.let { path ->
+                File(path)
+                    .takeIf { it.absolutePath.startsWith(appCtx.filesDir.absolutePath) }
+                    ?.delete()
+            }
+
+            appShellSettingsGateway.updateAll(
+                listOf(
+                    AppShellSettingsUpdate.ThemeMode(defaultShell.themeMode),
+                    AppShellSettingsUpdate.FontScale(defaultShell.fontScale),
+                    AppShellSettingsUpdate.ComposeEngine(defaultShell.composeEngine),
+                    AppShellSettingsUpdate.MainNavigationOrder(defaultShell.mainNavigationOrder),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.ShowHome,
+                        defaultShell.showHome
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.ShowDiscovery,
+                        defaultShell.showDiscovery
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.ShowRss,
+                        defaultShell.showRss
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.ShowStatusBar,
+                        defaultShell.showStatusBar
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.SwipeAnimation,
+                        defaultShell.swipeAnimation
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.PredictiveBack,
+                        defaultShell.predictiveBackEnabled
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.ShowBottomView,
+                        defaultShell.showBottomView
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.UseFloatingBottomBar,
+                        defaultShell.useFloatingBottomBar
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.UseFloatingBottomBarLiquidGlass,
+                        defaultShell.useFloatingBottomBarLiquidGlass
+                    ),
+                    AppShellSettingsUpdate.BooleanValue(
+                        AppShellBooleanSetting.NavExtended,
+                        defaultShell.navExtended
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.TabletInterface,
+                        defaultShell.tabletInterface
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.LabelVisibilityMode,
+                        defaultShell.labelVisibilityMode
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.DefaultHomePage,
+                        defaultShell.defaultHomePage
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.NavIconHome,
+                        defaultShell.navIconHome
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.NavIconBookshelf,
+                        defaultShell.navIconBookshelf
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.NavIconExplore,
+                        defaultShell.navIconExplore
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.NavIconRss,
+                        defaultShell.navIconRss
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.NavIconMy,
+                        defaultShell.navIconMy
+                    ),
+                    AppShellSettingsUpdate.StringValue(
+                        AppShellStringSetting.LauncherIcon,
+                        defaultShell.launcherIcon
+                    ),
+                )
+            )
+            themeSettingsGateway.updateAll(
+                listOf(
+                    ThemeSettingsUpdate.AppTheme(defaultTheme.appTheme),
+                    ThemeSettingsUpdate.PureBlack(defaultTheme.isPureBlack),
+                    ThemeSettingsUpdate.PaletteStyle(defaultTheme.paletteStyle),
+                    ThemeSettingsUpdate.MaterialVersion(defaultTheme.materialVersion),
+                    ThemeSettingsUpdate.CustomContrast(defaultTheme.customContrast),
+                    ThemeSettingsUpdate.DeepPersonalization(defaultTheme.enableDeepPersonalization),
+                    ThemeSettingsUpdate.CustomPrimary(defaultTheme.customPrimary),
+                    ThemeSettingsUpdate.CustomNightPrimary(defaultTheme.customNightPrimary),
+                    ThemeSettingsUpdate.AppFontPath(null),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.Primary,
+                        defaultTheme.themeColor
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.Secondary,
+                        defaultTheme.secondaryThemeColor
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.PrimaryText,
+                        defaultTheme.primaryTextColor
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.SecondaryText,
+                        defaultTheme.secondaryTextColor
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.Background,
+                        defaultTheme.themeBackgroundColor
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.LabelContainer,
+                        defaultTheme.labelContainerColor
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.PrimaryNight,
+                        defaultTheme.themeColorNight
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.SecondaryNight,
+                        defaultTheme.secondaryThemeColorNight
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.PrimaryTextNight,
+                        defaultTheme.primaryTextColorNight
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.SecondaryTextNight,
+                        defaultTheme.secondaryTextColorNight
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.BackgroundNight,
+                        defaultTheme.themeBackgroundColorNight
+                    ),
+                    ThemeSettingsUpdate.CustomColor(
+                        ThemeColorSlot.LabelContainerNight,
+                        defaultTheme.labelContainerColorNight
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.UseMiuixMonet,
+                        defaultTheme.useMiuixMonet
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.EnableBlur,
+                        defaultTheme.enableBlur
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.EnableProgressiveBlur,
+                        defaultTheme.enableProgressiveBlur
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.UseFlexibleTopAppBar,
+                        defaultTheme.useFlexibleTopAppBar
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.BookInfoFollowCoverColor,
+                        defaultTheme.bookInfoFollowCoverColor
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.EnableItemDivider,
+                        defaultTheme.enableItemDivider
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.OverrideBaseCardCornerRadius,
+                        defaultTheme.overrideBaseCardCornerRadius
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.OverrideBaseCardBorder,
+                        defaultTheme.overrideBaseCardBorder
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.DisableSplicedColumnGroupCornerRadius,
+                        defaultTheme.disableSplicedColumnGroupCornerRadius
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.EyeProtectionEnabled,
+                        defaultTheme.eyeProtectionEnabled
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.EyeProtectionSchedule,
+                        defaultTheme.eyeProtectionSchedule
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.ShowRefactorTip,
+                        defaultTheme.showRefactorTip
+                    ),
+                    ThemeSettingsUpdate.BooleanValue(
+                        ThemeBooleanSetting.EnableCustomTagColors,
+                        defaultTheme.enableCustomTagColors
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.ContainerOpacity,
+                        defaultTheme.containerOpacity
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.TopBarOpacity,
+                        defaultTheme.topBarOpacity
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.BottomBarOpacity,
+                        defaultTheme.bottomBarOpacity
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.TopBarBlurRadius,
+                        defaultTheme.topBarBlurRadius
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.BottomBarBlurRadius,
+                        defaultTheme.bottomBarBlurRadius
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.TopBarBlurAlpha,
+                        defaultTheme.topBarBlurAlpha
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.BottomBarBlurAlpha,
+                        defaultTheme.bottomBarBlurAlpha
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.BackgroundImageBlurring,
+                        defaultTheme.backgroundImageBlurring
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.BackgroundImageDarkBlurring,
+                        defaultTheme.backgroundImageDarkBlurring
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.ItemDividerColor,
+                        defaultTheme.itemDividerColor
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.BaseCardBorderColor,
+                        defaultTheme.baseCardBorderColor
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.BaseCardBorderColorNight,
+                        defaultTheme.baseCardBorderColorNight
+                    ),
+                    ThemeSettingsUpdate.IntValue(
+                        ThemeIntSetting.ColorTemperature,
+                        defaultTheme.colorTemperature
+                    ),
+                    ThemeSettingsUpdate.FloatValue(
+                        ThemeFloatSetting.BottomBarLensRadius,
+                        defaultTheme.bottomBarLensRadius
+                    ),
+                    ThemeSettingsUpdate.FloatValue(
+                        ThemeFloatSetting.ItemDividerWidth,
+                        defaultTheme.itemDividerWidth
+                    ),
+                    ThemeSettingsUpdate.FloatValue(
+                        ThemeFloatSetting.ItemDividerLength,
+                        defaultTheme.itemDividerLength
+                    ),
+                    ThemeSettingsUpdate.FloatValue(
+                        ThemeFloatSetting.BaseCardCornerRadius,
+                        defaultTheme.baseCardCornerRadius
+                    ),
+                    ThemeSettingsUpdate.FloatValue(
+                        ThemeFloatSetting.BaseCardBorderWidth,
+                        defaultTheme.baseCardBorderWidth
+                    ),
+                    ThemeSettingsUpdate.StringValue(
+                        ThemeStringSetting.BookInfoNetworkCoverBackground,
+                        defaultTheme.bookInfoNetworkCoverBackground
+                    ),
+                    ThemeSettingsUpdate.StringValue(
+                        ThemeStringSetting.BookInfoDefaultCoverBackground,
+                        defaultTheme.bookInfoDefaultCoverBackground
+                    ),
+                    ThemeSettingsUpdate.StringValue(ThemeStringSetting.BackgroundImageLight, null),
+                    ThemeSettingsUpdate.StringValue(ThemeStringSetting.BackgroundImageDark, null),
+                    ThemeSettingsUpdate.StringValue(
+                        ThemeStringSetting.EyeProtectionStartTime,
+                        defaultTheme.eyeProtectionStartTime
+                    ),
+                    ThemeSettingsUpdate.StringValue(
+                        ThemeStringSetting.EyeProtectionEndTime,
+                        defaultTheme.eyeProtectionEndTime
+                    ),
+                    ThemeSettingsUpdate.StringValue(ThemeStringSetting.CustomTagColorsJson, null),
+                )
+            )
+            _effects.tryEmit(ThemeConfigEffect.ApplyDayNight)
+            _effects.tryEmit(ThemeConfigEffect.NotifyMain)
+            _effects.tryEmit(ThemeConfigEffect.ChangeLauncherIcon(defaultShell.launcherIcon))
+            _effects.tryEmit(ThemeConfigEffect.ShowToast(R.string.theme_config_reset_success))
+            _uiState.update { it.copy(activeDialog = null) }
+        }
+    }
+
     private fun selectTheme(value: String) {
         val theme = _uiState.value.theme
         if (value == "13" &&