pull/32/head
gedoor 6 years ago
parent a7c6e1ba62
commit f99e40b719
  1. 34
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt

@ -37,13 +37,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
sharedPreferences ?: return
when (key) {
"colorPrimary", "colorAccent", "colorBackground" ->
if (!ColorUtils.isColorLight(
sharedPreferences.getInt(
"colorBackground",
App.INSTANCE.getCompatColor(R.color.md_grey_100)
)
)
) {
if (backgroundIsDark(sharedPreferences)) {
activity?.let {
AlertDialog.Builder(it)
.setTitle("白天背景太暗")
@ -62,13 +56,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
upTheme(false)
}
"colorPrimaryNight", "colorAccentNight", "colorBackgroundNight" ->
if (ColorUtils.isColorLight(
sharedPreferences.getInt(
"colorBackgroundNight",
App.INSTANCE.getCompatColor(R.color.md_grey_800)
)
)
) {
if (backgroundIsLight(sharedPreferences)) {
activity?.let {
AlertDialog.Builder(it)
.setTitle("夜间背景太亮")
@ -118,6 +106,24 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
return super.onPreferenceTreeClick(preference)
}
private fun backgroundIsDark(sharedPreferences: SharedPreferences): Boolean {
return !ColorUtils.isColorLight(
sharedPreferences.getInt(
"colorBackground",
App.INSTANCE.getCompatColor(R.color.md_grey_100)
)
)
}
private fun backgroundIsLight(sharedPreferences: SharedPreferences): Boolean {
return ColorUtils.isColorLight(
sharedPreferences.getInt(
"colorBackgroundNight",
App.INSTANCE.getCompatColor(R.color.md_grey_800)
)
)
}
private fun upTheme(isNightTheme: Boolean) {
if (App.INSTANCE.getPrefBoolean("isNightTheme", false) == isNightTheme) {
App.INSTANCE.upThemeStore()

Loading…
Cancel
Save