From f99e40b719ff98fe8c52a7bdc9ba5be034c6139f Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 9 Jun 2019 10:13:05 +0800 Subject: [PATCH] up --- .../app/ui/config/ThemeConfigFragment.kt | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 072442180..8ac64d67a 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/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()