feat: 优化

pull/254/head
gedoor 4 years ago
parent 76c9510321
commit 9dde645644
  1. 14
      app/src/main/java/io/legado/app/App.kt
  2. 80
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  3. 1
      app/src/main/res/values/colors.xml

@ -89,10 +89,18 @@ class App : Application() {
getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600)) getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
val accent = val accent =
getPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_800)) getPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_800))
val background = var background =
getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.shine_color)) getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.md_grey_900))
val bBackground = 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)) 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) ThemeStore.editTheme(this)
.coloredNavigationBar(true) .coloredNavigationBar(true)
.primaryColor(ColorUtils.withAlpha(primary, 1f)) .primaryColor(ColorUtils.withAlpha(primary, 1f))

@ -132,45 +132,62 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
@SuppressLint("PrivateResource") @SuppressLint("PrivateResource")
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
"defaultTheme" -> alert(title = "切换默认主题") { "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()
recreateActivities()
}
.show {
AppConfig.elevation = it
recreateActivities()
}
}
return super.onPreferenceTreeClick(preference)
}
private fun changeTheme() {
alert(title = "切换默认主题") {
items(items) { _, which -> items(items) { _, which ->
when (which) { when (which) {
0 -> { 0 -> {
putPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100)) putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_grey_100))
putPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color)) putPrefInt(PreferKey.cAccent, getCompatColor(R.color.lightBlue_color))
putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) putPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100))
putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200))
AppConfig.isNightTheme = false AppConfig.isNightTheme = false
} }
1 -> { 1 -> {
putPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color)) putPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_grey_900))
putPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color)) putPrefInt(PreferKey.cNAccent, getCompatColor(R.color.lightBlue_color))
putPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color)) putPrefInt(PreferKey.cNBackground, getCompatColor(R.color.md_grey_900))
putPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_900))
AppConfig.isNightTheme = true AppConfig.isNightTheme = true
} }
2 -> { 2 -> {
putPrefInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_light_blue_500))
putPrefInt("colorAccent", getCompatColor(R.color.md_pink_800)) putPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_pink_800))
putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) putPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100))
putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200))
AppConfig.isNightTheme = false AppConfig.isNightTheme = false
} }
3 -> { 3 -> {
putPrefInt("colorPrimary", getCompatColor(R.color.white)) putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.white))
putPrefInt("colorAccent", getCompatColor(R.color.black)) putPrefInt(PreferKey.cAccent, getCompatColor(R.color.black))
putPrefInt("colorBackground", getCompatColor(R.color.white)) putPrefInt(PreferKey.cBackground, getCompatColor(R.color.white))
putPrefInt("colorBottomBackground", getCompatColor(R.color.white)) putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.white))
AppConfig.isNightTheme = false AppConfig.isNightTheme = false
} }
4 -> { 4 -> {
putPrefInt("colorPrimaryNight", getCompatColor(R.color.black)) putPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.black))
putPrefInt( putPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_grey_500))
"colorAccentNight", putPrefInt(PreferKey.cNBackground, getCompatColor(R.color.black))
getCompatColor(R.color.md_grey_500) putPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.black))
)
putPrefInt(
"colorBackgroundNight",
getCompatColor(R.color.black)
)
putPrefInt("colorBottomBackgroundNight", getCompatColor(R.color.black))
AppConfig.isNightTheme = true AppConfig.isNightTheme = true
} }
} }
@ -178,21 +195,6 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
recreateActivities() recreateActivities()
} }
}.show().applyTint() }.show().applyTint()
"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()
recreateActivities()
}
.show {
AppConfig.elevation = it
recreateActivities()
}
}
return super.onPreferenceTreeClick(preference)
} }
private fun backgroundIsDark(sharedPreferences: SharedPreferences): Boolean { private fun backgroundIsDark(sharedPreferences: SharedPreferences): Boolean {

@ -6,7 +6,6 @@
<color name="divider">#66666666</color> <color name="divider">#66666666</color>
<color name="lightBlue_color">#FF578FCC</color> <color name="lightBlue_color">#FF578FCC</color>
<color name="shine_color">#FF212227</color>
<color name="error">#eb4333</color> <color name="error">#eb4333</color>
<color name="success">#439b53</color> <color name="success">#439b53</color>

Loading…
Cancel
Save