pull/480/head
gedoor 4 years ago
parent cf919ee682
commit 8a51fd77cf
  1. 6
      app/src/main/java/io/legado/app/App.kt
  2. 4
      app/src/main/java/io/legado/app/constant/AppConst.kt
  3. 149
      app/src/main/java/io/legado/app/help/AppConfig.kt
  4. 38
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  5. 6
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  6. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  7. 1
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  8. 3
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt

@ -17,6 +17,7 @@ import io.legado.app.data.AppDatabase
import io.legado.app.help.* import io.legado.app.help.*
import io.legado.app.utils.LanguageUtils import io.legado.app.utils.LanguageUtils
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import org.jetbrains.anko.defaultSharedPreferences
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
class App : MultiDexApplication() { class App : MultiDexApplication() {
@ -33,6 +34,8 @@ class App : MultiDexApplication() {
lateinit var androidId: String lateinit var androidId: String
var versionCode = 0 var versionCode = 0
var versionName = "" var versionName = ""
} }
override fun onCreate() { override fun onCreate() {
@ -53,8 +56,8 @@ class App : MultiDexApplication() {
.supportBroadcast(this) .supportBroadcast(this)
.lifecycleObserverAlwaysActive(true) .lifecycleObserverAlwaysActive(true)
.autoClear(false) .autoClear(false)
registerActivityLifecycleCallbacks(ActivityHelp) registerActivityLifecycleCallbacks(ActivityHelp)
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
} }
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
@ -66,7 +69,6 @@ class App : MultiDexApplication() {
} }
fun applyDayNight() { fun applyDayNight() {
AppConfig.upEInkMode()
ReadBookConfig.upBg() ReadBookConfig.upBg()
ThemeConfig.applyTheme(this) ThemeConfig.applyTheme(this)
initNightMode() initNightMode()

@ -1,6 +1,8 @@
package io.legado.app.constant package io.legado.app.constant
import android.annotation.SuppressLint import android.annotation.SuppressLint
import io.legado.app.App
import io.legado.app.R
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import javax.script.ScriptEngine import javax.script.ScriptEngine
import javax.script.ScriptEngineManager import javax.script.ScriptEngineManager
@ -69,4 +71,6 @@ object AppConst {
"com.android.internal.view.menu.ListMenuItemView", "com.android.internal.view.menu.ListMenuItemView",
"androidx.appcompat.view.menu.ListMenuItemView" "androidx.appcompat.view.menu.ListMenuItemView"
) )
val sysElevation = App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt()
} }

@ -2,28 +2,66 @@ package io.legado.app.help
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.SharedPreferences
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.AppConst
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.utils.* import io.legado.app.utils.*
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
object AppConfig { object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
var isEInkMode: Boolean = false private val context get() = App.INSTANCE
val isGooglePlay: Boolean val isGooglePlay = context.channel == "google"
val isCoolApk: Boolean val isCoolApk = context.channel == "coolApk"
var replaceEnableDefault: Boolean = true var replaceEnableDefault = context.getPrefBoolean(PreferKey.replaceEnableDefault, true)
val sysElevation = App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt() var isEInkMode = context.getPrefString(PreferKey.themeMode) == "3"
var clickActionTL = context.getPrefInt(PreferKey.clickActionTL, 2)
init { var clickActionTC = context.getPrefInt(PreferKey.clickActionTC, 2)
upConfig() var clickActionTR = context.getPrefInt(PreferKey.clickActionTR, 1)
isGooglePlay = App.INSTANCE.channel == "google" var clickActionML = context.getPrefInt(PreferKey.clickActionML, 2)
isCoolApk = App.INSTANCE.channel == "coolApk" var clickActionMC = context.getPrefInt(PreferKey.clickActionMC, 0)
} var clickActionMR = context.getPrefInt(PreferKey.clickActionMR, 1)
var clickActionBL = context.getPrefInt(PreferKey.clickActionBL, 2)
fun upConfig() { var clickActionBC = context.getPrefInt(PreferKey.clickActionBC, 1)
upEInkMode() var clickActionBR = context.getPrefInt(PreferKey.clickActionBR, 1)
upReplaceEnableDefault()
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
when (key) {
PreferKey.themeMode -> {
isEInkMode = context.getPrefString(PreferKey.themeMode) == "3"
}
PreferKey.clickActionTL -> {
clickActionTL = context.getPrefInt(PreferKey.clickActionTL, 2)
}
PreferKey.clickActionTC -> {
clickActionTC = context.getPrefInt(PreferKey.clickActionTC, 2)
}
PreferKey.clickActionTR -> {
clickActionTR = context.getPrefInt(PreferKey.clickActionTR, 2)
}
PreferKey.clickActionML -> {
clickActionML = context.getPrefInt(PreferKey.clickActionML, 2)
}
PreferKey.clickActionMC -> {
clickActionMC = context.getPrefInt(PreferKey.clickActionMC, 2)
}
PreferKey.clickActionMR -> {
clickActionMR = context.getPrefInt(PreferKey.clickActionMR, 2)
}
PreferKey.clickActionBL -> {
clickActionBL = context.getPrefInt(PreferKey.clickActionBL, 2)
}
PreferKey.clickActionBC -> {
clickActionBC = context.getPrefInt(PreferKey.clickActionBC, 2)
}
PreferKey.clickActionBR -> {
clickActionBR = context.getPrefInt(PreferKey.clickActionBR, 2)
}
PreferKey.readBodyToLh -> {
ReadBookConfig.readBodyToLh = context.getPrefBoolean(PreferKey.readBodyToLh, true)
}
}
} }
fun isNightTheme(context: Context): Boolean { fun isNightTheme(context: Context): Boolean {
@ -36,115 +74,94 @@ object AppConfig {
} }
var isNightTheme: Boolean var isNightTheme: Boolean
get() = isNightTheme(App.INSTANCE) get() = isNightTheme(context)
set(value) { set(value) {
if (isNightTheme != value) { if (isNightTheme != value) {
if (value) { if (value) {
App.INSTANCE.putPrefString(PreferKey.themeMode, "2") context.putPrefString(PreferKey.themeMode, "2")
} else { } else {
App.INSTANCE.putPrefString(PreferKey.themeMode, "1") context.putPrefString(PreferKey.themeMode, "1")
} }
} }
} }
fun upEInkMode() {
isEInkMode = App.INSTANCE.getPrefString(PreferKey.themeMode) == "3"
}
var isTransparentStatusBar: Boolean var isTransparentStatusBar: Boolean
get() = App.INSTANCE.getPrefBoolean(PreferKey.transparentStatusBar) get() = context.getPrefBoolean(PreferKey.transparentStatusBar)
set(value) { set(value) {
App.INSTANCE.putPrefBoolean(PreferKey.transparentStatusBar, value) context.putPrefBoolean(PreferKey.transparentStatusBar, value)
} }
val requestedDirection: String? val requestedDirection: String?
get() = App.INSTANCE.getPrefString(R.string.pk_requested_direction) get() = context.getPrefString(R.string.pk_requested_direction)
var backupPath: String? var backupPath: String?
get() = App.INSTANCE.getPrefString(PreferKey.backupPath) get() = context.getPrefString(PreferKey.backupPath)
set(value) { set(value) {
if (value.isNullOrEmpty()) { if (value.isNullOrEmpty()) {
App.INSTANCE.removePref(PreferKey.backupPath) context.removePref(PreferKey.backupPath)
} else { } else {
App.INSTANCE.putPrefString(PreferKey.backupPath, value) context.putPrefString(PreferKey.backupPath, value)
} }
} }
var isShowRSS: Boolean var isShowRSS: Boolean
get() = App.INSTANCE.getPrefBoolean(PreferKey.showRss, true) get() = context.getPrefBoolean(PreferKey.showRss, true)
set(value) { set(value) {
App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) context.putPrefBoolean(PreferKey.showRss, value)
} }
val autoRefreshBook: Boolean val autoRefreshBook: Boolean
get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh) get() = context.getPrefBoolean(R.string.pk_auto_refresh)
var threadCount: Int var threadCount: Int
get() = App.INSTANCE.getPrefInt(PreferKey.threadCount, 16) get() = context.getPrefInt(PreferKey.threadCount, 16)
set(value) { set(value) {
App.INSTANCE.putPrefInt(PreferKey.threadCount, value) context.putPrefInt(PreferKey.threadCount, value)
} }
var importBookPath: String? var importBookPath: String?
get() = App.INSTANCE.getPrefString("importBookPath") get() = context.getPrefString("importBookPath")
set(value) { set(value) {
if (value == null) { if (value == null) {
App.INSTANCE.removePref("importBookPath") context.removePref("importBookPath")
} else { } else {
App.INSTANCE.putPrefString("importBookPath", value) context.putPrefString("importBookPath", value)
} }
} }
var ttsSpeechRate: Int var ttsSpeechRate: Int
get() = App.INSTANCE.getPrefInt(PreferKey.ttsSpeechRate, 5) get() = context.getPrefInt(PreferKey.ttsSpeechRate, 5)
set(value) { set(value) {
App.INSTANCE.putPrefInt(PreferKey.ttsSpeechRate, value) context.putPrefInt(PreferKey.ttsSpeechRate, value)
} }
var chineseConverterType: Int var chineseConverterType: Int
get() = App.INSTANCE.getPrefInt(PreferKey.chineseConverterType) get() = context.getPrefInt(PreferKey.chineseConverterType)
set(value) { set(value) {
App.INSTANCE.putPrefInt(PreferKey.chineseConverterType, value) context.putPrefInt(PreferKey.chineseConverterType, value)
} }
var systemTypefaces: Int var systemTypefaces: Int
get() = App.INSTANCE.getPrefInt(PreferKey.systemTypefaces) get() = context.getPrefInt(PreferKey.systemTypefaces)
set(value) { set(value) {
App.INSTANCE.putPrefInt(PreferKey.systemTypefaces, value) context.putPrefInt(PreferKey.systemTypefaces, value)
} }
var elevation: Int var elevation: Int
@SuppressLint("PrivateResource") @SuppressLint("PrivateResource")
get() = App.INSTANCE.getPrefInt(PreferKey.barElevation, sysElevation) get() = context.getPrefInt(PreferKey.barElevation, AppConst.sysElevation)
set(value) { set(value) {
App.INSTANCE.putPrefInt(PreferKey.barElevation, value) context.putPrefInt(PreferKey.barElevation, value)
} }
val autoChangeSource: Boolean val autoChangeSource: Boolean
get() = App.INSTANCE.getPrefBoolean(PreferKey.autoChangeSource, true) get() = context.getPrefBoolean(PreferKey.autoChangeSource, true)
val readBodyToLh: Boolean
get() = App.INSTANCE.getPrefBoolean(PreferKey.readBodyToLh, true)
fun upReplaceEnableDefault() {
replaceEnableDefault =
App.INSTANCE.getPrefBoolean(PreferKey.replaceEnableDefault, true)
}
val changeSourceLoadInfo get() = App.INSTANCE.getPrefBoolean(PreferKey.changeSourceLoadToc) val changeSourceLoadInfo get() = context.getPrefBoolean(PreferKey.changeSourceLoadToc)
val changeSourceLoadToc get() = App.INSTANCE.getPrefBoolean(PreferKey.changeSourceLoadToc) val changeSourceLoadToc get() = context.getPrefBoolean(PreferKey.changeSourceLoadToc)
val importKeepName get() = App.INSTANCE.getPrefBoolean(PreferKey.importKeepName) val importKeepName get() = context.getPrefBoolean(PreferKey.importKeepName)
val clickActionTL get() = App.INSTANCE.getPrefInt(PreferKey.clickActionTL, 2)
val clickActionTC get() = App.INSTANCE.getPrefInt(PreferKey.clickActionTC, 2)
val clickActionTR get() = App.INSTANCE.getPrefInt(PreferKey.clickActionTR, 1)
val clickActionML get() = App.INSTANCE.getPrefInt(PreferKey.clickActionML, 2)
val clickActionMC get() = App.INSTANCE.getPrefInt(PreferKey.clickActionMC, 0)
val clickActionMR get() = App.INSTANCE.getPrefInt(PreferKey.clickActionMR, 1)
val clickActionBL get() = App.INSTANCE.getPrefInt(PreferKey.clickActionBL, 2)
val clickActionBC get() = App.INSTANCE.getPrefInt(PreferKey.clickActionBC, 1)
val clickActionBR get() = App.INSTANCE.getPrefInt(PreferKey.clickActionBR, 1)
} }

@ -22,8 +22,9 @@ import java.io.File
object ReadBookConfig { object ReadBookConfig {
const val configFileName = "readConfig.json" const val configFileName = "readConfig.json"
const val shareConfigFileName = "shareReadConfig.json" const val shareConfigFileName = "shareReadConfig.json"
val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, configFileName) val context get() = App.INSTANCE
val shareConfigFilePath = FileUtils.getPath(App.INSTANCE.filesDir, shareConfigFileName) val configFilePath = FileUtils.getPath(context.filesDir, configFileName)
val shareConfigFilePath = FileUtils.getPath(context.filesDir, shareConfigFileName)
val configList: ArrayList<Config> = arrayListOf() val configList: ArrayList<Config> = arrayListOf()
lateinit var shareConfig: Config lateinit var shareConfig: Config
var durConfig var durConfig
@ -85,7 +86,7 @@ object ReadBookConfig {
} }
fun upBg() { fun upBg() {
val resources = App.INSTANCE.resources val resources = context.resources
val dm = resources.displayMetrics val dm = resources.displayMetrics
val width = dm.widthPixels val width = dm.widthPixels
val height = dm.heightPixels val height = dm.heightPixels
@ -134,29 +135,30 @@ object ReadBookConfig {
} }
//配置写入读取 //配置写入读取
var autoReadSpeed = App.INSTANCE.getPrefInt(PreferKey.autoReadSpeed, 46) var readBodyToLh = context.getPrefBoolean(PreferKey.readBodyToLh, true)
var autoReadSpeed = context.getPrefInt(PreferKey.autoReadSpeed, 46)
set(value) { set(value) {
field = value field = value
App.INSTANCE.putPrefInt(PreferKey.autoReadSpeed, value) context.putPrefInt(PreferKey.autoReadSpeed, value)
} }
var styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) var styleSelect = context.getPrefInt(PreferKey.readStyleSelect)
set(value) { set(value) {
field = value field = value
if (App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) != value) { if (context.getPrefInt(PreferKey.readStyleSelect) != value) {
App.INSTANCE.putPrefInt(PreferKey.readStyleSelect, value) context.putPrefInt(PreferKey.readStyleSelect, value)
} }
} }
var shareLayout = App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) var shareLayout = context.getPrefBoolean(PreferKey.shareLayout)
set(value) { set(value) {
field = value field = value
if (App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) != value) { if (context.getPrefBoolean(PreferKey.shareLayout) != value) {
App.INSTANCE.putPrefBoolean(PreferKey.shareLayout, value) context.putPrefBoolean(PreferKey.shareLayout, value)
} }
} }
val textFullJustify get() = App.INSTANCE.getPrefBoolean(PreferKey.textFullJustify, true) val textFullJustify get() = context.getPrefBoolean(PreferKey.textFullJustify, true)
val textBottomJustify get() = App.INSTANCE.getPrefBoolean(PreferKey.textBottomJustify, true) val textBottomJustify get() = context.getPrefBoolean(PreferKey.textBottomJustify, true)
var hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) var hideStatusBar = context.getPrefBoolean(PreferKey.hideStatusBar)
var hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) var hideNavigationBar = context.getPrefBoolean(PreferKey.hideNavigationBar)
val config get() = if (shareLayout) shareConfig else durConfig val config get() = if (shareLayout) shareConfig else durConfig
@ -489,7 +491,7 @@ object ReadBookConfig {
fun curBgDrawable(width: Int, height: Int): Drawable { fun curBgDrawable(width: Int, height: Int): Drawable {
var bgDrawable: Drawable? = null var bgDrawable: Drawable? = null
val resources = App.INSTANCE.resources val resources = context.resources
try { try {
bgDrawable = when (curBgType()) { bgDrawable = when (curBgType()) {
0 -> ColorDrawable(Color.parseColor(curBgStr())) 0 -> ColorDrawable(Color.parseColor(curBgStr()))
@ -497,7 +499,7 @@ object ReadBookConfig {
BitmapDrawable( BitmapDrawable(
resources, resources,
BitmapUtils.decodeAssetsBitmap( BitmapUtils.decodeAssetsBitmap(
App.INSTANCE, context,
"bg" + File.separator + curBgStr(), "bg" + File.separator + curBgStr(),
width, width,
height height
@ -512,7 +514,7 @@ object ReadBookConfig {
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
return bgDrawable ?: ColorDrawable(App.INSTANCE.getCompatColor(R.color.background)) return bgDrawable ?: ColorDrawable(context.getCompatColor(R.color.background))
} }
} }
} }

@ -13,7 +13,10 @@ import io.legado.app.R
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
import io.legado.app.help.* import io.legado.app.help.DefaultData
import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ThemeConfig
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.* import io.legado.app.utils.*
@ -206,7 +209,6 @@ object Restore {
} }
} }
edit.apply() edit.apply()
AppConfig.upConfig()
} }
ReadBookConfig.apply { ReadBookConfig.apply {
styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect)

@ -21,7 +21,8 @@ import io.legado.app.help.AppConfig
import io.legado.app.help.LocalConfig import io.legado.app.help.LocalConfig
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.* import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
@ -208,7 +209,7 @@ abstract class ReadBookBaseActivity :
* 适配刘海 * 适配刘海
*/ */
private fun upLayoutInDisplayCutoutMode() { private fun upLayoutInDisplayCutoutMode() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && AppConfig.readBodyToLh) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && ReadBookConfig.readBodyToLh) {
window.attributes = window.attributes.apply { window.attributes = window.attributes.apply {
layoutInDisplayCutoutMode = layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES

@ -120,7 +120,6 @@ class OtherConfigFragment : BasePreferenceFragment(),
key, key,
getPrefString(PreferKey.defaultCover) getPrefString(PreferKey.defaultCover)
) )
PreferKey.replaceEnableDefault -> AppConfig.upReplaceEnableDefault()
PreferKey.language -> listView.postDelayed({ PreferKey.language -> listView.postDelayed({
LanguageUtils.setConfiguration(App.INSTANCE) LanguageUtils.setConfiguration(App.INSTANCE)
val intent = Intent(App.INSTANCE, MainActivity::class.java) val intent = Intent(App.INSTANCE, MainActivity::class.java)

@ -12,6 +12,7 @@ import androidx.preference.Preference
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BasePreferenceFragment import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -158,7 +159,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
.setMinValue(0) .setMinValue(0)
.setValue(AppConfig.elevation) .setValue(AppConfig.elevation)
.setCustomButton((R.string.btn_default_s)) { .setCustomButton((R.string.btn_default_s)) {
AppConfig.elevation = AppConfig.sysElevation AppConfig.elevation = AppConst.sysElevation
recreateActivities() recreateActivities()
} }
.show { .show {

Loading…
Cancel
Save