修复主题应用
This commit is contained in:
1 parent
32e7e78c69
commit
9c3f185fa7
10 files changed
+59
-78
No files matched your search
@@ -16,15 +16,15 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import io.legato.kazusa.R
|
||||
import androidx.core.graphics.toColorInt
|
||||
import io.legato.kazusa.constant.EventBus
|
||||
import io.legato.kazusa.utils.postEvent
|
||||
|
||||
@SuppressLint("ResourceType")
|
||||
class ThemeCardPreference(
|
||||
context: Context,
|
||||
attrs: AttributeSet
|
||||
) : Preference(context, attrs) {
|
||||
class ThemeCardPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) {
|
||||
|
||||
private var entries: Array<CharSequence> = context.resources.getTextArray(R.array.themes_item)
|
||||
private var entryValues: Array<CharSequence> = context.resources.getTextArray(R.array.themes_value)
|
||||
private var entryValues: Array<CharSequence> = context.resources.getTextArray(R.array.themes_value).takeIf { it.isNotEmpty() }
|
||||
?: arrayOf("0")
|
||||
private var currentValue: String? = null
|
||||
|
||||
init {
|
||||
@@ -39,10 +39,8 @@ class ThemeCardPreference(
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
//val titleView = holder.findViewById(R.id.title) as TextView
|
||||
val recyclerView = holder.findViewById(R.id.recyclerView) as RecyclerView
|
||||
|
||||
//titleView.text = title
|
||||
recyclerView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
recyclerView.adapter = ThemeAdapter()
|
||||
}
|
||||
@@ -80,6 +78,7 @@ class ThemeCardPreference(
|
||||
persistString(value)
|
||||
callChangeListener(value)
|
||||
notifyDataSetChanged()
|
||||
postEvent(EventBus.RECREATE, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.ViewGroup
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.help.config.ThemeConfig
|
||||
|
||||
|
||||
class ThemeModePreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) {
|
||||
@@ -41,7 +42,6 @@ class ThemeModePreference(context: Context, attrs: AttributeSet) : Preference(co
|
||||
"2" -> toggleGroup.check(R.id.btn_dark)
|
||||
}
|
||||
|
||||
// 监听选择变化
|
||||
toggleGroup.addOnButtonCheckedListener { group, checkedId, isChecked ->
|
||||
if (isChecked) {
|
||||
val newValue = when (checkedId) {
|
||||
@@ -54,6 +54,8 @@ class ThemeModePreference(context: Context, attrs: AttributeSet) : Preference(co
|
||||
if (newValue != null && callChangeListener(newValue)) {
|
||||
currentValue = newValue
|
||||
persistString(newValue)
|
||||
callChangeListener(newValue)
|
||||
ThemeConfig.applyDayNight(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,4 +68,5 @@ class ThemeModePreference(context: Context, attrs: AttributeSet) : Preference(co
|
||||
override fun shouldDisableDependents(): Boolean {
|
||||
return currentValue == null || super.shouldDisableDependents()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user