更新界面
增加首次进入引导界面
This commit is contained in:
1 parent
ab98072ec3
commit
50abb9b552
33 files changed
+684
-307
No files matched your search
@@ -24,7 +24,7 @@ class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(co
|
||||
private var entries: Array<CharSequence> = context.resources.getTextArray(R.array.themes_item)
|
||||
private var entryValues: Array<CharSequence> = context.resources.getTextArray(R.array.themes_value).takeIf { it.isNotEmpty() }
|
||||
?: arrayOf("0")
|
||||
private var currentValue: String? = null
|
||||
private var currentValue = "0"
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.preference_theme_card
|
||||
|
||||
@@ -2,9 +2,6 @@ package io.legato.kazusa.lib.prefs
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup
|
||||
import io.legato.kazusa.R
|
||||
@@ -13,7 +10,7 @@ import io.legato.kazusa.help.config.ThemeConfig
|
||||
|
||||
class ThemeModePreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) {
|
||||
|
||||
private var currentValue: String? = null
|
||||
private var currentValue: String = "0"
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.view_pref
|
||||
@@ -23,17 +20,21 @@ class ThemeModePreference(context: Context, attrs: AttributeSet) : Preference(co
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
val toggleGroup = holder.itemView.findViewById<View>(R.id.theme_toggle_group)
|
||||
if (toggleGroup == null) {
|
||||
val rootView = holder.itemView as ViewGroup
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val themeToggleView = inflater.inflate(R.layout.view_theme_mode, rootView, false)
|
||||
rootView.addView(themeToggleView)
|
||||
val toggleGroup =
|
||||
holder.itemView.findViewById<MaterialButtonToggleGroup>(R.id.theme_toggle_group)
|
||||
?: return
|
||||
|
||||
setupToggleGroup(themeToggleView.findViewById(R.id.theme_toggle_group))
|
||||
// 根据 currentValue 设置选中
|
||||
when (currentValue) {
|
||||
"0" -> toggleGroup.check(R.id.btn_system)
|
||||
"1" -> toggleGroup.check(R.id.btn_light)
|
||||
"2" -> toggleGroup.check(R.id.btn_dark)
|
||||
}
|
||||
|
||||
setupToggleGroup(toggleGroup)
|
||||
}
|
||||
|
||||
|
||||
private fun setupToggleGroup(toggleGroup: MaterialButtonToggleGroup) {
|
||||
|
||||
when (currentValue) {
|
||||
@@ -65,8 +66,4 @@ class ThemeModePreference(context: Context, attrs: AttributeSet) : Preference(co
|
||||
currentValue = getPersistedString(defaultValue as? String ?: "0")
|
||||
}
|
||||
|
||||
override fun shouldDisableDependents(): Boolean {
|
||||
return currentValue == null || super.shouldDisableDependents()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user