|
|
@ -20,8 +20,12 @@ import io.legado.app.utils.* |
|
|
|
|
|
|
|
|
|
|
|
class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener { |
|
|
|
class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val items = arrayOf("极简","曜夜","经典") |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
|
|
|
addPreferencesFromResource(R.xml.pref_config_theme) |
|
|
|
addPreferencesFromResource(R.xml.pref_config_theme) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
findPreference<Preference>("defaultTheme")?.summary = "${items[getPrefInt("default_theme", 0)]}" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
@ -96,23 +100,34 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar |
|
|
|
"defaultTheme" -> { |
|
|
|
"defaultTheme" -> { |
|
|
|
activity?.let { |
|
|
|
activity?.let { |
|
|
|
AlertDialog.Builder(it) |
|
|
|
AlertDialog.Builder(it) |
|
|
|
.setTitle("恢复默认主题") |
|
|
|
.setTitle("切换默认主题") |
|
|
|
.setMessage("是否确认恢复?") |
|
|
|
.setItems(items){ |
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> |
|
|
|
_,which -> |
|
|
|
preferenceManager.sharedPreferences.edit() |
|
|
|
preference.summary = "${items[which]}" |
|
|
|
// light mode |
|
|
|
putPrefInt("default_theme", which) |
|
|
|
.putInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) |
|
|
|
when (which) { |
|
|
|
.putInt("colorAccent", getCompatColor(R.color.md_pink_800)) |
|
|
|
0 -> { |
|
|
|
.putInt("colorBackground", getCompatColor(R.color.md_grey_100)) |
|
|
|
putPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100)) |
|
|
|
// dark mode |
|
|
|
putPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color)) |
|
|
|
.putInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900)) |
|
|
|
putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) |
|
|
|
.putInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) |
|
|
|
putPrefBoolean("isNightTheme", false) |
|
|
|
.putInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000)) |
|
|
|
} |
|
|
|
.apply() |
|
|
|
1 -> { |
|
|
|
App.INSTANCE.applyTheme() |
|
|
|
putPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color)) |
|
|
|
|
|
|
|
putPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color)) |
|
|
|
|
|
|
|
putPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color)) |
|
|
|
|
|
|
|
putPrefBoolean("isNightTheme", true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
2 -> { |
|
|
|
|
|
|
|
putPrefInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) |
|
|
|
|
|
|
|
putPrefInt("colorAccent", getCompatColor(R.color.md_pink_800)) |
|
|
|
|
|
|
|
putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) |
|
|
|
|
|
|
|
putPrefBoolean("isNightTheme", false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
App.INSTANCE.applyDayNight() |
|
|
|
recreateActivities() |
|
|
|
recreateActivities() |
|
|
|
} |
|
|
|
} |
|
|
|
.setNegativeButton(R.string.cancel, null) |
|
|
|
|
|
|
|
.show().applyTint() |
|
|
|
.show().applyTint() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|