Browse Source

优化透明主题选择逻辑

HapeLee 1 year ago
parent
commit
ec215ccf5e

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

@@ -18,8 +18,12 @@ import androidx.recyclerview.widget.RecyclerView
 import com.google.android.material.card.MaterialCardView
 import io.legato.kazusa.R
 import io.legato.kazusa.constant.EventBus
+import io.legato.kazusa.constant.PreferKey
+import io.legato.kazusa.utils.getPrefString
 import io.legato.kazusa.utils.postEvent
 import io.legato.kazusa.utils.restart
+import io.legato.kazusa.utils.toastOnUi
+import splitties.init.appCtx
 
 @SuppressLint("ResourceType")
 class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) {
@@ -76,6 +80,14 @@ class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(co
 
             holder.card.setOnClickListener {
                 if (value != currentValue) {
+                    if (value == "12") {
+                        val hasLightBg = !appCtx.getPrefString(PreferKey.bgImage).isNullOrEmpty()
+                        val hasDarkBg = !appCtx.getPrefString(PreferKey.bgImageN).isNullOrEmpty()
+                        if (!hasLightBg || !hasDarkBg) {
+                            context.toastOnUi(R.string.transparent_theme_alarm)
+                            return@setOnClickListener
+                        }
+                    }
                     val oldValue = currentValue
                     currentValue = value
                     persistString(value)

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

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