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