增加默认主题选择

pull/60/head
Administrator 5 years ago
parent 67e270f2db
commit d62c4517e9
  1. 10
      app/src/main/java/io/legado/app/App.kt
  2. 4
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 45
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  4. 3
      app/src/main/res/drawable/item_bg_dark.xml
  5. 3
      app/src/main/res/drawable/item_bg_light.xml
  6. 2
      app/src/main/res/layout/activity_main.xml
  7. 4
      app/src/main/res/values/colors.xml
  8. 6
      app/src/main/res/xml/pref_main.xml

@ -70,22 +70,22 @@ class App : Application() {
if (isNightTheme) {
ThemeStore.editTheme(this)
.primaryColor(
getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900))
getPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color))
)
.accentColor(
getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800))
getPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color))
)
.backgroundColor(
getPrefInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000))
getPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color))
)
.apply()
} else {
ThemeStore.editTheme(this)
.primaryColor(
getPrefInt("colorPrimary", getCompatColor(R.color.md_light_blue_500))
getPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100))
)
.accentColor(
getPrefInt("colorAccent", getCompatColor(R.color.md_pink_800))
getPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color))
)
.backgroundColor(
getPrefInt("colorBackground", getCompatColor(R.color.md_grey_100))

@ -206,6 +206,10 @@ object ATH {
.setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create()
itemIconTintList = colorStateList
itemTextColor = colorStateList
itemBackgroundResource = when(context.isNightTheme) {
true -> R.drawable.item_bg_dark
false -> R.drawable.item_bg_light
}
}
}

@ -20,8 +20,12 @@ import io.legado.app.utils.*
class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener {
val items = arrayOf("极简","曜夜","经典")
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_theme)
findPreference<Preference>("defaultTheme")?.summary = "${items[getPrefInt("default_theme", 0)]}"
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -96,23 +100,34 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
"defaultTheme" -> {
activity?.let {
AlertDialog.Builder(it)
.setTitle("恢复默认主题")
.setMessage("是否确认恢复?")
.setPositiveButton(R.string.ok) { _, _ ->
preferenceManager.sharedPreferences.edit()
// light mode
.putInt("colorPrimary", getCompatColor(R.color.md_light_blue_500))
.putInt("colorAccent", getCompatColor(R.color.md_pink_800))
.putInt("colorBackground", getCompatColor(R.color.md_grey_100))
// dark mode
.putInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900))
.putInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800))
.putInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000))
.apply()
App.INSTANCE.applyTheme()
.setTitle("切换默认主题")
.setItems(items){
_,which ->
preference.summary = "${items[which]}"
putPrefInt("default_theme", 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))
putPrefBoolean("isNightTheme", false)
}
1 -> {
putPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color))
putPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color))
putPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color))
putPrefBoolean("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))
putPrefBoolean("isNightTheme", false)
}
}
App.INSTANCE.applyDayNight()
recreateActivities()
}
.setNegativeButton(R.string.cancel, null)
.show().applyTint()
}
}

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<color xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/item_bg_color" />

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<color xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/md_grey_100" />

@ -6,8 +6,6 @@
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation_view"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="6dp"

@ -5,6 +5,10 @@
<color name="colorAccent">@color/md_pink_800</color>
<color name="divider">#66666666</color>
<color name="lightBlue_color">#FF578FCC</color>
<color name="shine_color">#FF212227</color>
<color name="item_bg_color">#FF272731</color>
<color name="error">#eb4333</color>
<color name="success">#439b53</color>

@ -12,12 +12,6 @@
android:title="@string/replace_purify"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false"
android:key="isNightTheme"
android:title="@string/dark_theme"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false"
android:key="webService"

Loading…
Cancel
Save