Ver Fonte

为需要重启应用的选项提供引导

HapeLee há 1 ano atrás
pai
commit
e9c5800437

+ 12 - 2
app/src/main/java/io/legato/kazusa/lib/prefs/ThemeCardPreference.kt

@@ -19,6 +19,7 @@ import com.google.android.material.card.MaterialCardView
 import io.legato.kazusa.R
 import io.legato.kazusa.R
 import io.legato.kazusa.constant.EventBus
 import io.legato.kazusa.constant.EventBus
 import io.legato.kazusa.constant.PreferKey
 import io.legato.kazusa.constant.PreferKey
+import io.legato.kazusa.lib.dialogs.alert
 import io.legato.kazusa.utils.getPrefString
 import io.legato.kazusa.utils.getPrefString
 import io.legato.kazusa.utils.postEvent
 import io.legato.kazusa.utils.postEvent
 import io.legato.kazusa.utils.restart
 import io.legato.kazusa.utils.restart
@@ -96,11 +97,20 @@ class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(co
                     val isDynamicSwitch = (oldValue == "11" || value == "11")
                     val isDynamicSwitch = (oldValue == "11" || value == "11")
                     Handler(Looper.getMainLooper()).postDelayed({
                     Handler(Looper.getMainLooper()).postDelayed({
                         if (isDynamicSwitch) {
                         if (isDynamicSwitch) {
-                            context.restart()
+                            context.alert(context.getString(R.string.restart_required_message)) {
+                                okButton {
+                                    Handler(Looper.getMainLooper()).postDelayed({
+                                        context.restart()
+                                    }, 100)
+                                }
+                                cancelButton {
+                                    context.toastOnUi(R.string.restart_later_message)
+                                }
+                            }
                         } else {
                         } else {
                             postEvent(EventBus.RECREATE, "")
                             postEvent(EventBus.RECREATE, "")
                         }
                         }
-                    }, 300)
+                    }, 100)
                 }
                 }
             }
             }
         }
         }

+ 16 - 11
app/src/main/java/io/legato/kazusa/ui/config/ThemeConfigFragment.kt

@@ -179,16 +179,12 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
                 //recreateActivities()
                 //recreateActivities()
             }
             }
 
 
-            PreferKey.customMode -> {
-                Handler(Looper.getMainLooper()).postDelayed({
-                    requireContext().restart()
-                }, 300)
-            }
+            PreferKey.customMode -> handleRestartRequired()
 
 
             PreferKey.pureBlack -> {
             PreferKey.pureBlack -> {
                 Handler(Looper.getMainLooper()).postDelayed({
                 Handler(Looper.getMainLooper()).postDelayed({
                     recreateActivities()
                     recreateActivities()
-                }, 300)
+                }, 100)
             }
             }
 
 
             PreferKey.cPrimary -> {
             PreferKey.cPrimary -> {
@@ -201,7 +197,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
                     .build())
                     .build())
                 Handler(Looper.getMainLooper()).postDelayed({
                 Handler(Looper.getMainLooper()).postDelayed({
                     recreateActivities()
                     recreateActivities()
-                }, 300)
+                }, 100)
             }
             }
 
 
             PreferKey.cBackground,
             PreferKey.cBackground,
@@ -220,10 +216,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
                 //recreateActivities()
                 //recreateActivities()
             }
             }
 
 
-            PreferKey.colorImage ->
-                Handler(Looper.getMainLooper()).postDelayed({
-                    requireContext().restart()
-                }, 100)
+            PreferKey.colorImage -> handleRestartRequired()
 
 
             PreferKey.bgImage,
             PreferKey.bgImage,
             PreferKey.bgImageN -> {
             PreferKey.bgImageN -> {
@@ -346,6 +339,18 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
             }
             }
         }
         }
 
 
+        private fun handleRestartRequired() {
+            alert(getString(R.string.restart_required_message)) {
+                okButton {
+                    Handler(Looper.getMainLooper()).postDelayed({
+                        requireContext().restart()
+                    }, 100)
+                }
+                cancelButton {
+                    toastOnUi(R.string.restart_later_message)
+                }
+            }
+        }
 
 
         private fun alertImageBlurring(preferKey: String, success: () -> Unit) {
         private fun alertImageBlurring(preferKey: String, success: () -> Unit) {
         alert(R.string.background_image_blurring) {
         alert(R.string.background_image_blurring) {

+ 3 - 0
app/src/main/res/values-zh/strings.xml

@@ -1296,4 +1296,7 @@
     <string name="seed_photo_summary">使用图片生成主题颜色</string>
     <string name="seed_photo_summary">使用图片生成主题颜色</string>
     <string name="seed_photo_alart">若需使用种子颜色,请取消种子图片选择</string>
     <string name="seed_photo_alart">若需使用种子颜色,请取消种子图片选择</string>
     <string name="click_to_delete">点击以删除或更改</string>
     <string name="click_to_delete">点击以删除或更改</string>
+    <string name="tip_custom_mode">切换至自定义主题或调整自定义设置时,部分选项需要重启。</string>
+    <string name="restart_required_message">此更改需要重启应用才能生效,是否立即重启?</string>
+    <string name="restart_later_message">更改将在下次启动应用时生效</string>
 </resources>
 </resources>

+ 3 - 0
app/src/main/res/values/strings.xml

@@ -1297,4 +1297,7 @@
     <string name="seed_photo_summary">使用图片生成主题颜色</string>
     <string name="seed_photo_summary">使用图片生成主题颜色</string>
     <string name="seed_photo_alart">若需使用种子颜色,请取消种子图片选择</string>
     <string name="seed_photo_alart">若需使用种子颜色,请取消种子图片选择</string>
     <string name="click_to_delete">Click to delete or change</string>
     <string name="click_to_delete">Click to delete or change</string>
+    <string name="tip_custom_mode">切换至自定义主题或调整自定义设置时,部分选项需要重启。</string>
+    <string name="restart_required_message">修改该选项需要重启</string>
+    <string name="restart_later_message">稍后重启</string>
 </resources>
 </resources>

+ 6 - 0
app/src/main/res/xml/pref_config_theme.xml

@@ -24,6 +24,12 @@
             android:entryValues="@array/themes_value"
             android:entryValues="@array/themes_value"
             android:defaultValue="0" />
             android:defaultValue="0" />
 
 
+        <io.legato.kazusa.lib.prefs.TipPreference
+            android:key="tip"
+            android:selectable="false"
+            app:iconSpaceReserved="false"
+            app:tipText="@string/tip_custom_mode"/>
+
         <io.legato.kazusa.lib.prefs.SwitchPreference
         <io.legato.kazusa.lib.prefs.SwitchPreference
             android:defaultValue="false"
             android:defaultValue="false"
             android:key="pure_black"
             android:key="pure_black"