还是感觉原来颜色好看点

pull/83/head
kunfei 5 years ago
parent 1423f8b90e
commit 0793f81385
  1. 9
      app/src/main/java/io/legado/app/App.kt
  2. 19
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  4. 13
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  5. 2
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  6. 8
      app/src/main/java/io/legado/app/utils/FragmentExtensions.kt
  7. 12
      app/src/main/res/values/arrays.xml
  8. 1
      app/src/main/res/values/strings.xml
  9. 17
      app/src/main/res/xml/pref_main.xml

@ -22,7 +22,6 @@ import io.legado.app.lib.theme.ThemeStore
import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.ChapterProvider
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.sysIsDarkMode
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
class App : Application() { class App : Application() {
@ -104,13 +103,7 @@ class App : Application() {
private fun initNightMode() { private fun initNightMode() {
val targetMode = val targetMode =
if (AppConfig.autoDarkMode) { if (AppConfig.isNightTheme) {
if (sysIsDarkMode()) {
AppCompatDelegate.MODE_NIGHT_YES
} else {
AppCompatDelegate.MODE_NIGHT_NO
}
} else if (AppConfig.isNightTheme) {
AppCompatDelegate.MODE_NIGHT_YES AppCompatDelegate.MODE_NIGHT_YES
} else { } else {
AppCompatDelegate.MODE_NIGHT_NO AppCompatDelegate.MODE_NIGHT_NO

@ -2,17 +2,24 @@ package io.legado.app.help
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.*
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.putPrefInt
object AppConfig { object AppConfig {
var isNightTheme: Boolean var isNightTheme: Boolean
get() = App.INSTANCE.getPrefBoolean("isNightTheme") get() {
return when (App.INSTANCE.getPrefString("themeMode", "0")) {
"1" -> false
"2" -> true
else -> App.INSTANCE.sysIsDarkMode()
}
}
set(value) { set(value) {
App.INSTANCE.putPrefBoolean("isNightTheme", value) if (value) {
App.INSTANCE.putPrefString("themeMode", "2")
} else {
App.INSTANCE.putPrefString("themeMode", "1")
}
} }
var isTransparentStatusBar: Boolean var isTransparentStatusBar: Boolean

@ -145,7 +145,7 @@ class ReadMenu : FrameLayout {
//夜间模式 //夜间模式
fabNightTheme.onClick { fabNightTheme.onClick {
context.putPrefBoolean("isNightTheme", !AppConfig.isNightTheme) AppConfig.isNightTheme = !AppConfig.isNightTheme
App.INSTANCE.applyDayNight() App.INSTANCE.applyDayNight()
} }

@ -10,6 +10,7 @@ import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.dialogs.yesButton
@ -110,25 +111,25 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
putPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100)) putPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100))
putPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color)) putPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color))
putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100))
putPrefBoolean("isNightTheme", false) AppConfig.isNightTheme = false
} }
1 -> { 1 -> {
putPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color)) putPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color))
putPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color)) putPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color))
putPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color)) putPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color))
putPrefBoolean("isNightTheme", true) AppConfig.isNightTheme = true
} }
2 -> { 2 -> {
putPrefInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) putPrefInt("colorPrimary", getCompatColor(R.color.md_light_blue_500))
putPrefInt("colorAccent", getCompatColor(R.color.md_pink_800)) putPrefInt("colorAccent", getCompatColor(R.color.md_pink_800))
putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100))
putPrefBoolean("isNightTheme", false) AppConfig.isNightTheme = false
} }
3 -> { 3 -> {
putPrefInt("colorPrimary", getCompatColor(R.color.white)) putPrefInt("colorPrimary", getCompatColor(R.color.white))
putPrefInt("colorAccent", getCompatColor(R.color.black)) putPrefInt("colorAccent", getCompatColor(R.color.black))
putPrefInt("colorBackground", getCompatColor(R.color.white)) putPrefInt("colorBackground", getCompatColor(R.color.white))
putPrefBoolean("isNightTheme", false) AppConfig.isNightTheme = false
} }
4 -> { 4 -> {
putPrefInt("colorPrimaryNight", getCompatColor(R.color.black)) putPrefInt("colorPrimaryNight", getCompatColor(R.color.black))
@ -140,7 +141,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
"colorBackgroundNight", "colorBackgroundNight",
getCompatColor(R.color.black) getCompatColor(R.color.black)
) )
putPrefBoolean("isNightTheme", true) AppConfig.isNightTheme = true
} }
} }
App.INSTANCE.applyDayNight() App.INSTANCE.applyDayNight()
@ -172,7 +173,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
} }
private fun upTheme(isNightTheme: Boolean) { private fun upTheme(isNightTheme: Boolean) {
if (this.isNightTheme == isNightTheme) { if (AppConfig.isNightTheme == isNightTheme) {
App.INSTANCE.applyTheme() App.INSTANCE.applyTheme()
recreateActivities() recreateActivities()
} }

@ -200,7 +200,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) { when (key) {
"isNightTheme" -> App.INSTANCE.applyDayNight() "themeMode" -> App.INSTANCE.applyDayNight()
"webService" -> { "webService" -> {
if (requireContext().getPrefBoolean("webService")) { if (requireContext().getPrefBoolean("webService")) {
WebService.start(requireContext()) WebService.start(requireContext())

@ -54,17 +54,9 @@ fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = requireContext
fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id) fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id)
val Fragment.isNightTheme: Boolean
get() = getPrefBoolean("isNightTheme")
val Fragment.isTransparentStatusBar: Boolean
get() = getPrefBoolean("transparentStatusBar")
inline fun <reified T : Activity> Fragment.startActivity(vararg params: Pair<String, Any?>) = inline fun <reified T : Activity> Fragment.startActivity(vararg params: Pair<String, Any?>) =
AnkoInternals.internalStartActivity(requireActivity(), T::class.java, params) AnkoInternals.internalStartActivity(requireActivity(), T::class.java, params)
inline fun <reified T : Activity> Fragment.startActivityForResult(requestCode: Int, vararg params: Pair<String, Any?>) = inline fun <reified T : Activity> Fragment.startActivityForResult(requestCode: Int, vararg params: Pair<String, Any?>) =
startActivityForResult(AnkoInternals.createIntent(requireActivity(), T::class.java, params), requestCode) startActivityForResult(AnkoInternals.createIntent(requireActivity(), T::class.java, params), requestCode)

@ -63,6 +63,18 @@
<item>@string/jf_convert_f</item> <item>@string/jf_convert_f</item>
</string-array> </string-array>
<string-array name="theme_mode">
<item>跟随系统</item>
<item>亮色主题</item>
<item>暗色主题</item>
</string-array>
<string-array name="theme_mode_v">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="NavBarColors"> <string-array name="NavBarColors">
<item>自动</item> <item>自动</item>
<item>黑色</item> <item>黑色</item>

@ -433,6 +433,7 @@
<string name="scan_qr_code">扫描二维码</string> <string name="scan_qr_code">扫描二维码</string>
<string name="click_on_selected_show_menu">选中时点击可弹出菜单</string> <string name="click_on_selected_show_menu">选中时点击可弹出菜单</string>
<string name="theme">主题</string> <string name="theme">主题</string>
<string name="theme_mode">主题模式</string>
<string name="default_theme">默认主题</string> <string name="default_theme">默认主题</string>
<string name="restore_default_theme">恢复主题为默认配色</string> <string name="restore_default_theme">恢复主题为默认配色</string>
<string name="join_qq_group">加入QQ群</string> <string name="join_qq_group">加入QQ群</string>

@ -12,17 +12,12 @@
android:title="@string/replace_purify" android:title="@string/replace_purify"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference <io.legado.app.lib.theme.prefs.ATEListPreference
android:defaultValue="true" android:defaultValue="0"
android:key="autoDarkMode" android:entries="@array/theme_mode"
android:summary="@string/auto_dark_mode_s" android:entryValues="@array/theme_mode_v"
android:title="@string/auto_dark_mode" android:key="themeMode"
app:iconSpaceReserved="false" /> android:title="@string/theme_mode"
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false"
android:key="isNightTheme"
android:title="@string/night_theme"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference <io.legado.app.lib.theme.prefs.ATESwitchPreference

Loading…
Cancel
Save