|
|
@ -1,29 +1,55 @@ |
|
|
|
package io.legado.app.help |
|
|
|
package io.legado.app.help |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
var userAgent: String = getPrefUserAgent() |
|
|
|
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) |
|
|
|
|
|
|
|
PreferKey.userAgent -> userAgent = getPrefUserAgent() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun isNightTheme(context: Context): Boolean { |
|
|
|
fun isNightTheme(context: Context): Boolean { |
|
|
@ -36,117 +62,97 @@ 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 |
|
|
|
val isShowRSS: Boolean |
|
|
|
get() = App.INSTANCE.getPrefBoolean(PreferKey.showRss, true) |
|
|
|
get() = context.getPrefBoolean(PreferKey.showRss, true) |
|
|
|
set(value) { |
|
|
|
|
|
|
|
App.INSTANCE.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") |
|
|
|
get() = context.getPrefInt(PreferKey.barElevation, AppConst.sysElevation) |
|
|
|
get() = App.INSTANCE.getPrefInt(PreferKey.barElevation, 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 clickActionTopLeft get() = App.INSTANCE.getPrefInt(PreferKey.clickActionTopLeft, 2) |
|
|
|
private fun getPrefUserAgent(): String { |
|
|
|
val clickActionTopCenter get() = App.INSTANCE.getPrefInt(PreferKey.clickActionTopCenter, 2) |
|
|
|
val ua = context.getPrefString(PreferKey.userAgent) |
|
|
|
val clickActionTopRight get() = App.INSTANCE.getPrefInt(PreferKey.clickActionTopRight, 1) |
|
|
|
if (ua.isNullOrBlank()) { |
|
|
|
val clickActionMiddleLeft get() = App.INSTANCE.getPrefInt(PreferKey.clickActionMiddleLeft, 2) |
|
|
|
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" |
|
|
|
val clickActionMiddleCenter |
|
|
|
} |
|
|
|
get() = App.INSTANCE.getPrefInt(PreferKey.clickActionMiddleCenter, 0) |
|
|
|
return ua |
|
|
|
val clickActionMiddleRight get() = App.INSTANCE.getPrefInt(PreferKey.clickActionMiddleRight, 1) |
|
|
|
} |
|
|
|
val clickActionBottomLeft get() = App.INSTANCE.getPrefInt(PreferKey.clickActionBottomLeft, 2) |
|
|
|
|
|
|
|
val clickActionBottomCenter |
|
|
|
|
|
|
|
get() = App.INSTANCE.getPrefInt(PreferKey.clickActionBottomCenter, 1) |
|
|
|
|
|
|
|
val clickActionBottomRight get() = App.INSTANCE.getPrefInt(PreferKey.clickActionBottomRight, 1) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|