From 711bc3919a102f5838c0881f072baee603bf3dc6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 25 Oct 2020 20:29:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/App.kt | 1 + .../main/java/io/legado/app/help/AppConfig.kt | 42 +++++++++++++------ .../io/legado/app/help/storage/Restore.kt | 3 +- .../ui/book/read/config/MoreConfigDialog.kt | 4 ++ .../app/ui/config/OtherConfigFragment.kt | 3 +- .../app/ui/config/ThemeConfigFragment.kt | 3 +- 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 02dd32dae..a578bab15 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -67,6 +67,7 @@ class App : MultiDexApplication() { } fun applyDayNight() { + AppConfig.upEInkMode() ReadBookConfig.upBg() ThemeConfig.applyTheme(this) initNightMode() 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 cb14298b0..ed438c1dd 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -7,7 +7,26 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.utils.* +@Suppress("MemberVisibilityCanBePrivate") object AppConfig { + var isEInkMode: Boolean = false + var clickAllNext: Boolean = false + var isGooglePlay: Boolean + var isCoolApk: Boolean + var replaceEnableDefault: Boolean = true + val sysElevation = App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt() + + init { + upConfig() + isGooglePlay = App.INSTANCE.channel == "google" + isCoolApk = App.INSTANCE.channel == "coolApk" + } + + fun upConfig() { + upEInkMode() + upClickAllNext() + upReplaceEnableDefault() + } fun isNightTheme(context: Context): Boolean { return when (context.getPrefString(PreferKey.themeMode, "0")) { @@ -30,8 +49,9 @@ object AppConfig { } } - val isEInkMode: Boolean - get() = App.INSTANCE.getPrefString(PreferKey.themeMode) == "3" + fun upEInkMode() { + isEInkMode = App.INSTANCE.getPrefString(PreferKey.themeMode) == "3" + } var isTransparentStatusBar: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.transparentStatusBar) @@ -83,7 +103,9 @@ object AppConfig { App.INSTANCE.putPrefInt(PreferKey.ttsSpeechRate, value) } - val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false) + fun upClickAllNext() { + clickAllNext = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false) + } var chineseConverterType: Int get() = App.INSTANCE.getPrefInt(PreferKey.chineseConverterType) @@ -99,23 +121,19 @@ object AppConfig { var elevation: Int @SuppressLint("PrivateResource") - get() = App.INSTANCE.getPrefInt( - PreferKey.barElevation, - App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt() - ) + get() = App.INSTANCE.getPrefInt(PreferKey.barElevation, sysElevation) set(value) { App.INSTANCE.putPrefInt(PreferKey.barElevation, value) } - var replaceEnableDefault: Boolean = - App.INSTANCE.getPrefBoolean(PreferKey.replaceEnableDefault, true) - val autoChangeSource: Boolean get() = App.INSTANCE.getPrefBoolean("autoChangeSource", true) val readBodyToLh: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.readBodyToLh, true) - val isGooglePlay: Boolean get() = App.INSTANCE.channel == "google" + fun upReplaceEnableDefault() { + replaceEnableDefault = + App.INSTANCE.getPrefBoolean(PreferKey.replaceEnableDefault, true) + } - val isCoolApk: Boolean get() = App.INSTANCE.channel == "coolApk" } diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 3d376ade4..4820be0e3 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -204,8 +204,7 @@ object Restore { } } edit.apply() - AppConfig.replaceEnableDefault = - App.INSTANCE.getPrefBoolean(PreferKey.replaceEnableDefault, true) + AppConfig.upConfig() } ReadBookConfig.apply { styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 4a3b4bd23..4e2c82230 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -12,6 +12,7 @@ import io.legado.app.R import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.bottomBackground @@ -117,6 +118,9 @@ class MoreConfigDialog : DialogFragment() { PreferKey.showBrightnessView -> { postEvent(PreferKey.showBrightnessView, "") } + PreferKey.clickAllNext -> { + AppConfig.upClickAllNext() + } } } diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 542ae8780..c6b7e9fde 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -122,8 +122,7 @@ class OtherConfigFragment : BasePreferenceFragment(), key, getPrefString(PreferKey.defaultCover) ) - PreferKey.replaceEnableDefault -> AppConfig.replaceEnableDefault = - App.INSTANCE.getPrefBoolean(PreferKey.replaceEnableDefault, true) + PreferKey.replaceEnableDefault -> AppConfig.upReplaceEnableDefault() PreferKey.language -> listView.postDelayed({ LanguageUtils.setConfiguration(App.INSTANCE) val intent = Intent(App.INSTANCE, MainActivity::class.java) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 9b5d38e30..31ddeae8b 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -161,8 +161,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), .setMinValue(0) .setValue(AppConfig.elevation) .setCustomButton((R.string.btn_default_s)) { - AppConfig.elevation = - App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt() + AppConfig.elevation = AppConfig.sysElevation recreateActivities() } .show {