|
|
@ -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) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { |
|
|
|
upConfig() |
|
|
|
when (key) { |
|
|
|
isGooglePlay = App.INSTANCE.channel == "google" |
|
|
|
PreferKey.themeMode -> { |
|
|
|
isCoolApk = App.INSTANCE.channel == "coolApk" |
|
|
|
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 upConfig() { |
|
|
|
|
|
|
|
upEInkMode() |
|
|
|
|
|
|
|
upReplaceEnableDefault() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|