feat: 修复EInk bug

pull/248/head
gedoor 4 years ago
parent c21c30ac3e
commit 180f987097
  1. 17
      app/src/main/java/io/legado/app/App.kt
  2. 21
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 2
      app/src/main/java/io/legado/app/help/AppConfig.kt
  4. 9
      app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt
  5. 57
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt

@ -12,6 +12,7 @@ import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.constant.AppConst.channelIdDownload import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.constant.PreferKey
import io.legado.app.data.AppDatabase import io.legado.app.data.AppDatabase
import io.legado.app.help.ActivityHelp import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -71,24 +72,24 @@ class App : Application() {
if (AppConfig.isNightTheme) { if (AppConfig.isNightTheme) {
ThemeStore.editTheme(this) ThemeStore.editTheme(this)
.primaryColor( .primaryColor(
getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_blue_grey_600)) getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
).accentColor( ).accentColor(
getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) getPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_800))
).backgroundColor( ).backgroundColor(
getPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color)) getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.shine_color))
).bottomBackground( ).bottomBackground(
getPrefInt("colorBottomBackgroundNight", getCompatColor(R.color.md_grey_850)) getPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_850))
).apply() ).apply()
} else { } else {
ThemeStore.editTheme(this) ThemeStore.editTheme(this)
.primaryColor( .primaryColor(
getPrefInt("colorPrimary", getCompatColor(R.color.md_indigo_800)) getPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_indigo_800))
).accentColor( ).accentColor(
getPrefInt("colorAccent", getCompatColor(R.color.md_red_600)) getPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_red_600))
).backgroundColor( ).backgroundColor(
getPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) getPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100))
).bottomBackground( ).bottomBackground(
getPrefInt("colorBottomBackground", getCompatColor(R.color.md_grey_200)) getPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200))
).apply() ).apply()
} }
} }

@ -43,7 +43,26 @@ object PreferKey {
const val readStyleSelect = "readStyleSelect" const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces" const val systemTypefaces = "system_typefaces"
const val readBodyToLh = "readBodyToLh" const val readBodyToLh = "readBodyToLh"
const val einkMode = "isEInkMode" const val eInkMode = "isEInkMode"
const val textFullJustify = "textFullJustify" const val textFullJustify = "textFullJustify"
const val autoReadSpeed = "autoReadSpeed" const val autoReadSpeed = "autoReadSpeed"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"
const val cBackground = "colorBackground"
const val cBBackground = "colorBottomBackground"
const val cNPrimary = "colorPrimaryNight"
const val cNAccent = "colorAccentNight"
const val cNBackground = "colorBackgroundNight"
const val cNBBackground = "colorBottomBackgroundNight"
const val cLPrimary = "lastColorPrimary"
const val cLAccent = "lastColorAccent"
const val cLBackground = "lastColorBackground"
const val cLBBackground = "lastColorBottomBackground"
const val lastPageAnim = "lastPageAnim"
const val lastIsNight = "lastIsNightTheme"
const val lastThemeMode = "lastThemeMode"
} }

@ -81,7 +81,7 @@ object AppConfig {
get() = App.INSTANCE.getPrefString(PreferKey.ttsSpeechPer) ?: "0" get() = App.INSTANCE.getPrefString(PreferKey.ttsSpeechPer) ?: "0"
val isEInkMode: Boolean val isEInkMode: Boolean
get() = App.INSTANCE.getPrefBoolean(PreferKey.einkMode) get() = App.INSTANCE.getPrefBoolean(PreferKey.eInkMode)
val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false) val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false)

@ -9,6 +9,7 @@ import androidx.annotation.CheckResult
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
/** /**
@ -194,7 +195,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
@CheckResult @CheckResult
@ColorInt @ColorInt
fun primaryColor(context: Context): Int { fun primaryColor(context: Context = App.INSTANCE): Int {
return prefs(context).getInt( return prefs(context).getInt(
ThemeStorePrefKeys.KEY_PRIMARY_COLOR, ThemeStorePrefKeys.KEY_PRIMARY_COLOR,
ATHUtils.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64")) ATHUtils.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64"))
@ -212,7 +213,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
@CheckResult @CheckResult
@ColorInt @ColorInt
fun accentColor(context: Context): Int { fun accentColor(context: Context = App.INSTANCE): Int {
return prefs(context).getInt( return prefs(context).getInt(
ThemeStorePrefKeys.KEY_ACCENT_COLOR, ThemeStorePrefKeys.KEY_ACCENT_COLOR,
ATHUtils.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")) ATHUtils.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238"))
@ -277,7 +278,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
@CheckResult @CheckResult
@ColorInt @ColorInt
fun backgroundColor(context: Context): Int { fun backgroundColor(context: Context = App.INSTANCE): Int {
return prefs(context).getInt( return prefs(context).getInt(
ThemeStorePrefKeys.KEY_BACKGROUND_COLOR, ThemeStorePrefKeys.KEY_BACKGROUND_COLOR,
ATHUtils.resolveColor(context, android.R.attr.colorBackground) ATHUtils.resolveColor(context, android.R.attr.colorBackground)
@ -294,7 +295,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
@CheckResult @CheckResult
@ColorInt @ColorInt
fun bottomBackground(context: Context): Int { fun bottomBackground(context: Context = App.INSTANCE): Int {
return prefs(context).getInt( return prefs(context).getInt(
ThemeStorePrefKeys.KEY_BOTTOM_BACKGROUND, ThemeStorePrefKeys.KEY_BOTTOM_BACKGROUND,
ATHUtils.resolveColor(context, android.R.attr.colorBackground) ATHUtils.resolveColor(context, android.R.attr.colorBackground)

@ -123,46 +123,45 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog.
} }
} }
"recordLog" -> LogUtils.upLevel() "recordLog" -> LogUtils.upLevel()
PreferKey.einkMode -> { PreferKey.eInkMode -> {
//既然是 E-Ink 模式,为什么不一步到位呢 //既然是 E-Ink 模式,为什么不一步到位呢
if (AppConfig.isEInkMode) { if (AppConfig.isEInkMode) {
//保存开启前的设置 //保存开启前的设置
putPrefInt("lastReadBookPageAnim", ReadBookConfig.pageAnim) putPrefInt(PreferKey.lastPageAnim, ReadBookConfig.pageAnim)
putPrefInt("lastColorPrimary", ThemeStore.primaryColor(requireContext())) putPrefInt(PreferKey.cLPrimary, ThemeStore.primaryColor())
putPrefInt("lastColorAccent", ThemeStore.accentColor(requireContext())) putPrefInt(PreferKey.cLAccent, ThemeStore.accentColor())
putPrefInt("lastColorBackground", ThemeStore.backgroundColor(requireContext())) putPrefInt(PreferKey.cLBackground, ThemeStore.backgroundColor())
putPrefInt("lastColorBottomBackground", ThemeStore.bottomBackground(requireContext())) putPrefInt(PreferKey.cLBBackground, ThemeStore.bottomBackground())
putPrefBoolean("lastIsNightTheme", AppConfig.isNightTheme) putPrefBoolean(PreferKey.lastIsNight, AppConfig.isNightTheme)
putPrefString(
PreferKey.lastThemeMode,
getPrefString(PreferKey.themeMode) ?: "0"
)
//设置 E-Ink 模式配置 //设置 E-Ink 模式配置
ReadBookConfig.pageAnim = 4 ReadBookConfig.pageAnim = 4
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
App.INSTANCE.applyDayNight() App.INSTANCE.applyDayNight()
postEvent(EventBus.RECREATE, "") postEvent(EventBus.RECREATE, "")
} else { } else if (getPrefString(PreferKey.themeMode) != null) {
ReadBookConfig.pageAnim = getPrefInt("lastReadBookPageAnim") ReadBookConfig.pageAnim = getPrefInt(PreferKey.lastPageAnim)
if (getPrefBoolean("lastIsNightTheme")) { val isNightTheme = getPrefBoolean(PreferKey.lastIsNight)
putPrefInt("colorPrimaryNight", getPrefInt("lastColorPrimary")) if (isNightTheme) {
putPrefInt("colorAccentNight", getPrefInt("lastColorAccent")) putPrefInt(PreferKey.cNPrimary, getPrefInt(PreferKey.cLPrimary))
putPrefInt("colorBackgroundNight", getPrefInt("lastColorBackground")) putPrefInt(PreferKey.cNAccent, getPrefInt(PreferKey.cLAccent))
putPrefInt( putPrefInt(PreferKey.cNBackground, getPrefInt(PreferKey.cLBackground))
"colorBottomBackgroundNight", putPrefInt(PreferKey.cNBBackground, getPrefInt(PreferKey.cLBBackground))
getPrefInt("lastColorBottomBackground")
)
} else { } else {
putPrefInt("colorPrimary", getPrefInt("lastColorPrimary")) putPrefInt(PreferKey.cPrimary, getPrefInt(PreferKey.cLPrimary))
putPrefInt("colorAccent", getPrefInt("lastColorAccent")) putPrefInt(PreferKey.cAccent, getPrefInt(PreferKey.cLAccent))
putPrefInt("colorBackground", getPrefInt("lastColorBackground")) putPrefInt(PreferKey.cBackground, getPrefInt(PreferKey.cLBackground))
putPrefInt( putPrefInt(PreferKey.cBBackground, getPrefInt(PreferKey.cLBBackground))
"colorBottomBackground",
getPrefInt("lastColorBottomBackground")
)
} }
AppConfig.isNightTheme = getPrefBoolean("lastIsNightTheme") AppConfig.isNightTheme = isNightTheme
App.INSTANCE.applyDayNight() App.INSTANCE.applyDayNight()
postEvent(EventBus.RECREATE, "") postEvent(EventBus.RECREATE, "")
} }

Loading…
Cancel
Save