增加默认主题选择

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) { if (isNightTheme) {
ThemeStore.editTheme(this) ThemeStore.editTheme(this)
.primaryColor( .primaryColor(
getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900)) getPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color))
) )
.accentColor( .accentColor(
getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) getPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color))
) )
.backgroundColor( .backgroundColor(
getPrefInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000)) getPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color))
) )
.apply() .apply()
} else { } else {
ThemeStore.editTheme(this) ThemeStore.editTheme(this)
.primaryColor( .primaryColor(
getPrefInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) getPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100))
) )
.accentColor( .accentColor(
getPrefInt("colorAccent", getCompatColor(R.color.md_pink_800)) getPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color))
) )
.backgroundColor( .backgroundColor(
getPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) getPrefInt("colorBackground", getCompatColor(R.color.md_grey_100))

@ -206,6 +206,10 @@ object ATH {
.setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create() .setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create()
itemIconTintList = colorStateList itemIconTintList = colorStateList
itemTextColor = 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 { class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener {
val items = arrayOf("极简","曜夜","经典")
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_theme) addPreferencesFromResource(R.xml.pref_config_theme)
findPreference<Preference>("defaultTheme")?.summary = "${items[getPrefInt("default_theme", 0)]}"
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -96,23 +100,34 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
"defaultTheme" -> { "defaultTheme" -> {
activity?.let { activity?.let {
AlertDialog.Builder(it) AlertDialog.Builder(it)
.setTitle("恢复默认主题") .setTitle("切换默认主题")
.setMessage("是否确认恢复?") .setItems(items){
.setPositiveButton(R.string.ok) { _, _ -> _,which ->
preferenceManager.sharedPreferences.edit() preference.summary = "${items[which]}"
// light mode putPrefInt("default_theme", which)
.putInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) when (which) {
.putInt("colorAccent", getCompatColor(R.color.md_pink_800)) 0 -> {
.putInt("colorBackground", getCompatColor(R.color.md_grey_100)) putPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100))
// dark mode putPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color))
.putInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900)) putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100))
.putInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) putPrefBoolean("isNightTheme", false)
.putInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000)) }
.apply() 1 -> {
App.INSTANCE.applyTheme() 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() recreateActivities()
} }
.setNegativeButton(R.string.cancel, null)
.show().applyTint() .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 <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation_view" android:id="@+id/bottom_navigation_view"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:elevation="6dp" android:elevation="6dp"

@ -5,6 +5,10 @@
<color name="colorAccent">@color/md_pink_800</color> <color name="colorAccent">@color/md_pink_800</color>
<color name="divider">#66666666</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="error">#eb4333</color>
<color name="success">#439b53</color> <color name="success">#439b53</color>

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

Loading…
Cancel
Save