|
|
@ -28,7 +28,7 @@ import io.legado.app.utils.* |
|
|
|
class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener { |
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener { |
|
|
|
|
|
|
|
|
|
|
|
val items = arrayListOf("极简", "曜夜", "经典", "黑白", "A屏黑") |
|
|
|
val items = App.INSTANCE.resources.getStringArray(R.array.default_themes).toList() |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
@ -41,7 +41,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
findPreference<ColorPreference>(PreferKey.cBackground)?.let { |
|
|
|
findPreference<ColorPreference>(PreferKey.cBackground)?.let { |
|
|
|
it.onSaveColor = { color -> |
|
|
|
it.onSaveColor = { color -> |
|
|
|
if (!ColorUtils.isColorLight(color)) { |
|
|
|
if (!ColorUtils.isColorLight(color)) { |
|
|
|
toast("白天背景不能太暗") |
|
|
|
toast(R.string.day_background_too_dark) |
|
|
|
true |
|
|
|
true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
false |
|
|
|
false |
|
|
@ -51,7 +51,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
findPreference<ColorPreference>(PreferKey.cBBackground)?.let { |
|
|
|
findPreference<ColorPreference>(PreferKey.cBBackground)?.let { |
|
|
|
it.onSaveColor = { color -> |
|
|
|
it.onSaveColor = { color -> |
|
|
|
if (!ColorUtils.isColorLight(color)) { |
|
|
|
if (!ColorUtils.isColorLight(color)) { |
|
|
|
toast("白天底栏不能太暗") |
|
|
|
toast(R.string.day_bottom_bar_too_dark) |
|
|
|
true |
|
|
|
true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
false |
|
|
|
false |
|
|
@ -61,7 +61,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
findPreference<ColorPreference>(PreferKey.cNBackground)?.let { |
|
|
|
findPreference<ColorPreference>(PreferKey.cNBackground)?.let { |
|
|
|
it.onSaveColor = { color -> |
|
|
|
it.onSaveColor = { color -> |
|
|
|
if (ColorUtils.isColorLight(color)) { |
|
|
|
if (ColorUtils.isColorLight(color)) { |
|
|
|
toast("夜间背景不能太亮") |
|
|
|
toast(R.string.night_background_too_light) |
|
|
|
true |
|
|
|
true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
false |
|
|
|
false |
|
|
@ -71,7 +71,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
findPreference<ColorPreference>(PreferKey.cNBBackground)?.let { |
|
|
|
findPreference<ColorPreference>(PreferKey.cNBBackground)?.let { |
|
|
|
it.onSaveColor = { color -> |
|
|
|
it.onSaveColor = { color -> |
|
|
|
if (ColorUtils.isColorLight(color)) { |
|
|
|
if (ColorUtils.isColorLight(color)) { |
|
|
|
toast("夜间底栏不能太亮") |
|
|
|
toast(R.string.night_bottom_bar_too_light) |
|
|
|
true |
|
|
|
true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
false |
|
|
|
false |
|
|
@ -85,11 +85,11 @@ class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
val textColor = getCompatColor(R.color.tv_text_default) |
|
|
|
val textColor = getCompatColor(R.color.tv_text_default) |
|
|
|
when { |
|
|
|
when { |
|
|
|
ColorUtils.getColorDifference(color, background) <= 60 -> { |
|
|
|
ColorUtils.getColorDifference(color, background) <= 60 -> { |
|
|
|
toast("强调色不能和背景颜色相似") |
|
|
|
toast(R.string.accent_background_diff) |
|
|
|
true |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
ColorUtils.getColorDifference(color, textColor) <= 60 -> { |
|
|
|
ColorUtils.getColorDifference(color, textColor) <= 60 -> { |
|
|
|
toast("强调色不能和文字颜色相似") |
|
|
|
toast(R.string.accent_text_diff) |
|
|
|
true |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
else -> false |
|
|
|
else -> false |
|
|
@ -103,11 +103,11 @@ class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
val textColor = getCompatColor(R.color.tv_text_default) |
|
|
|
val textColor = getCompatColor(R.color.tv_text_default) |
|
|
|
when { |
|
|
|
when { |
|
|
|
ColorUtils.getColorDifference(color, background) <= 60 -> { |
|
|
|
ColorUtils.getColorDifference(color, background) <= 60 -> { |
|
|
|
toast("强调色不能和背景颜色相似") |
|
|
|
toast(R.string.accent_background_diff) |
|
|
|
true |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
ColorUtils.getColorDifference(color, textColor) <= 60 -> { |
|
|
|
ColorUtils.getColorDifference(color, textColor) <= 60 -> { |
|
|
|
toast("强调色不能和文字颜色相似") |
|
|
|
toast(R.string.accent_text_diff) |
|
|
|
true |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
else -> false |
|
|
|
else -> false |
|
|
@ -191,7 +191,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun changeTheme() { |
|
|
|
private fun changeTheme() { |
|
|
|
alert(title = "切换默认主题") { |
|
|
|
alert(title = getString(R.string.select_theme)) { |
|
|
|
items(items) { _, which -> |
|
|
|
items(items) { _, which -> |
|
|
|
when (which) { |
|
|
|
when (which) { |
|
|
|
0 -> { |
|
|
|
0 -> { |
|
|
|