feat: 修复EInk bug

pull/248/head
gedoor 5 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.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.constant.PreferKey
import io.legado.app.data.AppDatabase
import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig
@ -71,24 +72,24 @@ class App : Application() {
if (AppConfig.isNightTheme) {
ThemeStore.editTheme(this)
.primaryColor(
getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_blue_grey_600))
getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
).accentColor(
getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800))
getPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_800))
).backgroundColor(
getPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color))
getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.shine_color))
).bottomBackground(
getPrefInt("colorBottomBackgroundNight", getCompatColor(R.color.md_grey_850))
getPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_850))
).apply()
} else {
ThemeStore.editTheme(this)
.primaryColor(
getPrefInt("colorPrimary", getCompatColor(R.color.md_indigo_800))
getPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_indigo_800))
).accentColor(
getPrefInt("colorAccent", getCompatColor(R.color.md_red_600))
getPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_red_600))
).backgroundColor(
getPrefInt("colorBackground", getCompatColor(R.color.md_grey_100))
getPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100))
).bottomBackground(
getPrefInt("colorBottomBackground", getCompatColor(R.color.md_grey_200))
getPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200))
).apply()
}
}

@ -43,7 +43,26 @@ object PreferKey {
const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces"
const val readBodyToLh = "readBodyToLh"
const val einkMode = "isEInkMode"
const val eInkMode = "isEInkMode"
const val textFullJustify = "textFullJustify"
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"
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)

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

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

Loading…
Cancel
Save