Просмотр исходного кода

feat: 在主题配置中添加预测返回启用时的事件发布,优化重启提示

5151561 4 месяцев назад
Родитель
Сommit
98aff6c972

+ 3 - 1
app/src/main/java/io/legado/app/ui/config/themeConfig/ThemeConfig.kt

@@ -117,7 +117,9 @@ object ThemeConfig {
 
     var bgImageNBlurring by prefDelegate(PreferKey.bgImageNBlurring, 0)
 
-    var isPredictiveBackEnabled by prefDelegate(PreferKey.isPredictiveBackEnabled, true)
+    var isPredictiveBackEnabled by prefDelegate(PreferKey.isPredictiveBackEnabled, true) {
+        postEvent(EventBus.RECREATE, "")
+    }
 
     var customMode by prefDelegate<String?>(PreferKey.customMode, "tonalSpot")
 

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

@@ -344,7 +344,6 @@ fun ThemeConfigScreen(
                         checked = ThemeConfig.isPredictiveBackEnabled,
                         onCheckedChange = {
                             ThemeConfig.isPredictiveBackEnabled = it
-                            context.toastOnUi(R.string.restart_to_apply)
                         }
                     )
                     SliderSettingItem(

+ 4 - 2
app/src/main/java/io/legado/app/ui/config/themeManage/ThemeManageScreen.kt

@@ -41,6 +41,7 @@ import androidx.compose.ui.res.stringResource
 import androidx.compose.ui.unit.dp
 import androidx.lifecycle.compose.collectAsStateWithLifecycle
 import io.legado.app.R
+import io.legado.app.constant.EventBus
 import io.legado.app.help.config.SavedTheme
 import io.legado.app.help.config.ThemePackageManager
 import io.legado.app.ui.theme.adaptiveContentPadding
@@ -55,7 +56,7 @@ import io.legado.app.ui.widget.components.text.AppText
 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.restart
+import io.legado.app.utils.postEvent
 import io.legado.app.utils.toastOnUi
 import kotlinx.coroutines.flow.collectLatest
 import org.koin.androidx.compose.koinViewModel
@@ -254,6 +255,7 @@ fun ThemeManageScreen(
     }
 
     // Restart dialog
+    // TODO: 后续降级为纯重组,参考 ThemeConfigStore.applyDayNightLive
     AppAlertDialog(
         show = showRestartDialog,
         onDismissRequest = { showRestartDialog = false },
@@ -261,7 +263,7 @@ fun ThemeManageScreen(
         onConfirm = {
             showRestartDialog = false
             Handler(Looper.getMainLooper()).postDelayed({
-                context.restart()
+                postEvent(EventBus.RECREATE, "")
             }, 100)
         },
         confirmText = stringResource(R.string.ok),