From 180f987097da88c0b7c2dce2d48442e8d7e6671f Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 18 Jun 2020 22:40:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8DEInk=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/App.kt | 17 +++--- .../java/io/legado/app/constant/PreferKey.kt | 21 ++++++- .../main/java/io/legado/app/help/AppConfig.kt | 2 +- .../io/legado/app/lib/theme/ThemeStore.kt | 9 +-- .../io/legado/app/ui/main/my/MyFragment.kt | 57 +++++++++---------- 5 files changed, 63 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 5c4c02964..dde82c946 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.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() } } diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index e8f29712c..e4d8eafae 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -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" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index fef825c70..2ebd8f47a 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt index 5b3997081..415938c22 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 122f787eb..1d20baeab 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -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, "") }