diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index b93a0d8ab..43381a2c8 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -89,10 +89,18 @@ class App : Application() { getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600)) val accent = getPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_800)) - val background = - getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.shine_color)) - val bBackground = + var background = + getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.md_grey_900)) + if (ColorUtils.isColorLight(background)) { + background = getCompatColor(R.color.md_grey_900) + putPrefInt(PreferKey.cNBackground, background) + } + var bBackground = getPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_850)) + if (!ColorUtils.isColorLight(bBackground)) { + bBackground = getCompatColor(R.color.md_grey_850) + putPrefInt(PreferKey.cNBBackground, bBackground) + } ThemeStore.editTheme(this) .coloredNavigationBar(true) .primaryColor(ColorUtils.withAlpha(primary, 1f)) 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 13d12c4b0..d15fac81b 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 @@ -132,59 +132,15 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), @SuppressLint("PrivateResource") override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - "defaultTheme" -> alert(title = "切换默认主题") { - items(items) { _, which -> - when (which) { - 0 -> { - putPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100)) - putPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color)) - putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) - AppConfig.isNightTheme = false - } - 1 -> { - putPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color)) - putPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color)) - putPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color)) - AppConfig.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)) - AppConfig.isNightTheme = false - } - 3 -> { - putPrefInt("colorPrimary", getCompatColor(R.color.white)) - putPrefInt("colorAccent", getCompatColor(R.color.black)) - putPrefInt("colorBackground", getCompatColor(R.color.white)) - putPrefInt("colorBottomBackground", getCompatColor(R.color.white)) - AppConfig.isNightTheme = false - } - 4 -> { - putPrefInt("colorPrimaryNight", getCompatColor(R.color.black)) - putPrefInt( - "colorAccentNight", - getCompatColor(R.color.md_grey_500) - ) - putPrefInt( - "colorBackgroundNight", - getCompatColor(R.color.black) - ) - putPrefInt("colorBottomBackgroundNight", getCompatColor(R.color.black)) - AppConfig.isNightTheme = true - } - } - App.INSTANCE.applyDayNight() - recreateActivities() - } - }.show().applyTint() + "defaultTheme" -> changeTheme() "barElevation" -> NumberPickerDialog(requireContext()) .setTitle(getString(R.string.bar_elevation)) .setMaxValue(32) .setMinValue(0) .setValue(AppConfig.elevation) .setCustomButton((R.string.btn_default_s)) { - AppConfig.elevation = App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt() + AppConfig.elevation = + App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt() recreateActivities() } .show { @@ -195,6 +151,52 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), return super.onPreferenceTreeClick(preference) } + private fun changeTheme() { + alert(title = "切换默认主题") { + items(items) { _, which -> + when (which) { + 0 -> { + putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_grey_100)) + putPrefInt(PreferKey.cAccent, getCompatColor(R.color.lightBlue_color)) + putPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100)) + putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200)) + AppConfig.isNightTheme = false + } + 1 -> { + putPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_grey_900)) + putPrefInt(PreferKey.cNAccent, getCompatColor(R.color.lightBlue_color)) + putPrefInt(PreferKey.cNBackground, getCompatColor(R.color.md_grey_900)) + putPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_900)) + AppConfig.isNightTheme = true + } + 2 -> { + putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_light_blue_500)) + putPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_pink_800)) + putPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100)) + putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200)) + AppConfig.isNightTheme = false + } + 3 -> { + putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.white)) + putPrefInt(PreferKey.cAccent, getCompatColor(R.color.black)) + putPrefInt(PreferKey.cBackground, getCompatColor(R.color.white)) + putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.white)) + AppConfig.isNightTheme = false + } + 4 -> { + putPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.black)) + putPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_grey_500)) + putPrefInt(PreferKey.cNBackground, getCompatColor(R.color.black)) + putPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.black)) + AppConfig.isNightTheme = true + } + } + App.INSTANCE.applyDayNight() + recreateActivities() + } + }.show().applyTint() + } + private fun backgroundIsDark(sharedPreferences: SharedPreferences): Boolean { return !ColorUtils.isColorLight( sharedPreferences.getInt( diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index d74c3a850..b730f36c9 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -6,7 +6,6 @@ #66666666 #FF578FCC - #FF212227 #eb4333 #439b53