Merge pull request #480 from gedoor/master

update
pull/481/head
Antecer 4 years ago committed by GitHub
commit 8d45bb42c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/src/main/java/io/legado/app/App.kt
  2. 8
      app/src/main/java/io/legado/app/constant/AppConst.kt
  3. 20
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  4. 2
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  5. 9
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  6. 5
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  7. 152
      app/src/main/java/io/legado/app/help/AppConfig.kt
  8. 9
      app/src/main/java/io/legado/app/help/LocalConfig.kt
  9. 38
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  10. 7
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  11. 7
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  12. 4
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  13. 1
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  14. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  15. 32
      app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt
  16. 18
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  17. 34
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  18. 3
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  19. 8
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  20. 12
      app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt
  21. 6
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  22. 2
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt
  23. 7
      app/src/main/res/values/pref_key_value.xml
  24. 4
      app/src/main/res/xml/pref_config_other.xml

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

@ -1,6 +1,8 @@
package io.legado.app.constant
import android.annotation.SuppressLint
import io.legado.app.App
import io.legado.app.R
import java.text.SimpleDateFormat
import javax.script.ScriptEngine
import javax.script.ScriptEngineManager
@ -16,10 +18,6 @@ object AppConst {
const val UA_NAME = "User-Agent"
val userAgent: String by lazy {
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
}
val SCRIPT_ENGINE: ScriptEngine by lazy {
ScriptEngineManager().getEngineByName("rhino")
}
@ -69,4 +67,6 @@ object AppConst {
"com.android.internal.view.menu.ListMenuItemView",
"androidx.appcompat.view.menu.ListMenuItemView"
)
val sysElevation = App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt()
}

@ -1,19 +1,19 @@
package io.legado.app.constant
object PreferKey {
const val versionCode = "versionCode"
const val language = "language"
const val themeMode = "themeMode"
const val userAgent = "userAgent"
const val hideStatusBar = "hideStatusBar"
const val clickActionTopLeft = "clickActionTopLeft"
const val clickActionTopCenter = "clickActionTopCenter"
const val clickActionTopRight = "clickActionTopRight"
const val clickActionMiddleLeft = "clickActionMiddleLeft"
const val clickActionMiddleCenter = "clickActionMiddleCenter"
const val clickActionMiddleRight = "clickActionMiddleRight"
const val clickActionBottomLeft = "clickActionBottomLeft"
const val clickActionBottomCenter = "clickActionBottomCenter"
const val clickActionBottomRight = "clickActionBottomRight"
const val clickActionTL = "clickActionTopLeft"
const val clickActionTC = "clickActionTopCenter"
const val clickActionTR = "clickActionTopRight"
const val clickActionML = "clickActionMiddleLeft"
const val clickActionMC = "clickActionMiddleCenter"
const val clickActionMR = "clickActionMiddleRight"
const val clickActionBL = "clickActionBottomLeft"
const val clickActionBC = "clickActionBottomCenter"
const val clickActionBR = "clickActionBottomRight"
const val hideNavigationBar = "hideNavigationBar"
const val precisionSearch = "precisionSearch"
const val speakEngine = "speakEngine"

@ -65,7 +65,7 @@ data class BookChapter(
val urlArray = url.split(AnalyzeUrl.splitUrlRegex)
var absoluteUrl = NetworkUtils.getAbsoluteURL(baseUrl, urlArray[0])!!
if (urlArray.size > 1) {
absoluteUrl += urlArray[1]
absoluteUrl = "$absoluteUrl,${urlArray[1]}"
}
return absoluteUrl
}

@ -5,11 +5,14 @@ import android.text.TextUtils
import androidx.room.*
import io.legado.app.App
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.userAgent
import io.legado.app.constant.BookType
import io.legado.app.data.entities.rule.*
import io.legado.app.help.AppConfig
import io.legado.app.help.JsExtensions
import io.legado.app.utils.*
import io.legado.app.utils.ACache
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.splitNotBlank
import kotlinx.android.parcel.Parcelize
import javax.script.SimpleBindings
@ -51,7 +54,7 @@ data class BookSource(
@Throws(Exception::class)
fun getHeaderMap() = (HashMap<String, String>().apply {
this[AppConst.UA_NAME] = App.INSTANCE.getPrefString("user_agent") ?: userAgent
this[AppConst.UA_NAME] = AppConfig.userAgent
header?.let {
GSON.fromJsonObject<Map<String, String>>(
when {

@ -4,12 +4,11 @@ import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import io.legado.app.App
import io.legado.app.constant.AppConst
import io.legado.app.help.AppConfig
import io.legado.app.help.JsExtensions
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getPrefString
import kotlinx.android.parcel.Parcelize
import java.util.*
import javax.script.SimpleBindings
@ -54,7 +53,7 @@ data class RssSource(
@Throws(Exception::class)
fun getHeaderMap() = HashMap<String, String>().apply {
this[AppConst.UA_NAME] = App.INSTANCE.getPrefString("user_agent") ?: AppConst.userAgent
this[AppConst.UA_NAME] = AppConfig.userAgent
header?.let {
GSON.fromJsonObject<Map<String, String>>(
when {

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

@ -5,10 +5,19 @@ import androidx.core.content.edit
import io.legado.app.App
object LocalConfig {
private const val versionCodeKey = "versionCode"
private val localConfig =
App.INSTANCE.getSharedPreferences("local", Context.MODE_PRIVATE)
var versionCode
get() = localConfig.getInt(versionCodeKey, 0)
set(value) {
localConfig.edit {
putInt(versionCodeKey, value)
}
}
val isFirstOpenApp: Boolean
get() {
val value = localConfig.getBoolean("firstOpen", true)

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

@ -1,6 +1,7 @@
package io.legado.app.help.http
import io.legado.app.constant.AppConst
import io.legado.app.help.AppConfig
import io.legado.app.help.http.api.HttpGetApi
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.suspendCancellableCoroutine
@ -41,7 +42,7 @@ object HttpHelper {
fun simpleGet(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode)
.get(url, mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.get(url, mapOf(Pair(AppConst.UA_NAME, AppConfig.userAgent)))
.execute()
return response.body()
}
@ -51,7 +52,7 @@ object HttpHelper {
suspend fun simpleGetAsync(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode)
.getAsync(url, mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.getAsync(url, mapOf(Pair(AppConst.UA_NAME, AppConfig.userAgent)))
return response.body()
}
return null
@ -61,7 +62,7 @@ object HttpHelper {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
return getByteRetrofit(baseUrl)
.create(HttpGetApi::class.java)
.getMapByteAsync(url, mapOf(), mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.getMapByteAsync(url, mapOf(), mapOf(Pair(AppConst.UA_NAME, AppConfig.userAgent)))
.body()
}
return null

@ -13,7 +13,10 @@ import io.legado.app.R
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
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.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.*
@ -52,7 +55,6 @@ object Restore {
//默认忽略keys
private val ignorePrefKeys = arrayOf(
PreferKey.versionCode,
PreferKey.defaultCover
)
private val readPrefKeys = arrayOf(
@ -207,7 +209,6 @@ object Restore {
}
}
edit.apply()
AppConfig.upConfig()
}
ReadBookConfig.apply {
styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect)

@ -7,11 +7,11 @@ import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.load.model.LazyHeaders
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
import io.legado.app.constant.AppConst.UA_NAME
import io.legado.app.constant.AppConst.userAgent
import io.legado.app.constant.AppPattern.EXP_PATTERN
import io.legado.app.constant.AppPattern.JS_PATTERN
import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig
import io.legado.app.help.JsExtensions
import io.legado.app.help.http.*
import io.legado.app.help.http.api.HttpGetApi
@ -204,7 +204,7 @@ class AnalyzeUrl(
}
}
headerMap[UA_NAME] ?: let {
headerMap[UA_NAME] = userAgent
headerMap[UA_NAME] = AppConfig.userAgent
}
when (method) {
RequestMethod.GET -> {

@ -94,6 +94,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
BookHelp.getContent(book, chapter).let { content ->
val content1 = content?.let {
contentProcessor.getContent(book, chapter.title, it, false)
.joinToString("\n")
}
stringBuilder.append("\n\n")
.append(chapter.title)

@ -21,7 +21,8 @@ import io.legado.app.help.AppConfig
import io.legado.app.help.LocalConfig
import io.legado.app.help.ReadBookConfig
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.ThemeStore
import io.legado.app.lib.theme.backgroundColor
@ -208,7 +209,7 @@ abstract class ReadBookBaseActivity :
* 适配刘海
*/
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 {
layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES

@ -56,14 +56,14 @@ class ClickActionConfigDialog : BaseDialogFragment() {
}
private fun initData() = with(AppConfig) {
tv_top_left.text = actions[clickActionTopLeft]
tv_top_center.text = actions[clickActionTopCenter]
tv_top_right.text = actions[clickActionTopRight]
tv_middle_left.text = actions[clickActionMiddleLeft]
tv_middle_right.text = actions[clickActionMiddleRight]
tv_bottom_left.text = actions[clickActionBottomLeft]
tv_bottom_center.text = actions[clickActionBottomCenter]
tv_bottom_right.text = actions[clickActionBottomRight]
tv_top_left.text = actions[clickActionTL]
tv_top_center.text = actions[clickActionTC]
tv_top_right.text = actions[clickActionTR]
tv_middle_left.text = actions[clickActionML]
tv_middle_right.text = actions[clickActionMR]
tv_bottom_left.text = actions[clickActionBL]
tv_bottom_center.text = actions[clickActionBC]
tv_bottom_right.text = actions[clickActionBR]
}
private fun initViewEvent() {
@ -72,49 +72,49 @@ class ClickActionConfigDialog : BaseDialogFragment() {
}
tv_top_left.onClick {
selectAction { action ->
putPrefInt(PreferKey.clickActionTopLeft, action)
putPrefInt(PreferKey.clickActionTL, action)
(it as? TextView)?.text = actions[action]
}
}
tv_top_center.onClick {
selectAction { action ->
putPrefInt(PreferKey.clickActionTopCenter, action)
putPrefInt(PreferKey.clickActionTC, action)
(it as? TextView)?.text = actions[action]
}
}
tv_top_right.onClick {
selectAction { action ->
putPrefInt(PreferKey.clickActionTopRight, action)
putPrefInt(PreferKey.clickActionTR, action)
(it as? TextView)?.text = actions[action]
}
}
tv_middle_left.onClick {
selectAction { action ->
putPrefInt(PreferKey.clickActionMiddleLeft, action)
putPrefInt(PreferKey.clickActionML, action)
(it as? TextView)?.text = actions[action]
}
}
tv_middle_right.onClick {
selectAction { action ->
putPrefInt(PreferKey.clickActionMiddleRight, action)
putPrefInt(PreferKey.clickActionMR, action)
(it as? TextView)?.text = actions[action]
}
}
tv_bottom_left.onClick {
selectAction { action ->
putPrefInt(PreferKey.clickActionBottomLeft, action)
putPrefInt(PreferKey.clickActionBL, action)
(it as? TextView)?.text = actions[action]
}
}
tv_bottom_center.onClick {
selectAction { action ->
putPrefInt(PreferKey.clickActionBottomCenter, action)
putPrefInt(PreferKey.clickActionBC, action)
(it as? TextView)?.text = actions[action]
}
}
tv_bottom_right.onClick {
selectAction { action ->
putPrefInt(PreferKey.clickActionBottomRight, action)
putPrefInt(PreferKey.clickActionBR, action)
(it as? TextView)?.text = actions[action]
}
}

@ -261,31 +261,31 @@ class PageView(context: Context, attrs: AttributeSet) :
when {
isTextSelected -> isTextSelected = false
mcRect.contains(startX, startY) -> if (!isAbortAnim) {
click(AppConfig.clickActionMiddleCenter)
click(AppConfig.clickActionMC)
}
bcRect.contains(startX, startY) -> {
click(AppConfig.clickActionBottomCenter)
click(AppConfig.clickActionBC)
}
blRect.contains(startX, startY) -> {
click(AppConfig.clickActionBottomLeft)
click(AppConfig.clickActionBL)
}
brRect.contains(startX, startY) -> {
click(AppConfig.clickActionBottomRight)
click(AppConfig.clickActionBR)
}
mlRect.contains(startX, startY) -> {
click(AppConfig.clickActionMiddleLeft)
click(AppConfig.clickActionML)
}
mrRect.contains(startX, startY) -> {
click(AppConfig.clickActionMiddleRight)
click(AppConfig.clickActionMR)
}
tlRect.contains(startX, startY) -> {
click(AppConfig.clickActionTopLeft)
click(AppConfig.clickActionTL)
}
tcRect.contains(startX, startY) -> {
click(AppConfig.clickActionTopCenter)
click(AppConfig.clickActionTC)
}
trRect.contains(startX, startY) -> {
click(AppConfig.clickActionTopRight)
click(AppConfig.clickActionTR)
}
}
}

@ -1,5 +1,6 @@
package io.legado.app.ui.config
import android.annotation.SuppressLint
import android.app.Activity.RESULT_OK
import android.content.ComponentName
import android.content.Intent
@ -29,7 +30,9 @@ import io.legado.app.service.WebService
import io.legado.app.ui.main.MainActivity
import io.legado.app.ui.widget.image.CoverImageView
import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import java.io.File
@ -48,6 +51,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean(PreferKey.processText, isProcessTextEnabled())
addPreferencesFromResource(R.xml.pref_config_other)
upPreferenceSummary(PreferKey.userAgent, AppConfig.userAgent)
upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString())
upPreferenceSummary(PreferKey.webPort, webPort.toString())
upPreferenceSummary(PreferKey.defaultCover, getPrefString(PreferKey.defaultCover))
@ -66,6 +70,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) {
PreferKey.userAgent -> showUserAgentDialog()
PreferKey.threadCount -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.threads_num_title))
.setMaxValue(999)
@ -117,10 +122,8 @@ class OtherConfigFragment : BasePreferenceFragment(),
}
PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "")
PreferKey.defaultCover -> upPreferenceSummary(
key,
getPrefString(PreferKey.defaultCover)
key, getPrefString(PreferKey.defaultCover)
)
PreferKey.replaceEnableDefault -> AppConfig.upReplaceEnableDefault()
PreferKey.language -> listView.postDelayed({
LanguageUtils.setConfiguration(App.INSTANCE)
val intent = Intent(App.INSTANCE, MainActivity::class.java)
@ -128,6 +131,9 @@ class OtherConfigFragment : BasePreferenceFragment(),
App.INSTANCE.startActivity(intent)
Process.killProcess(Process.myPid())
}, 1000)
PreferKey.userAgent -> listView.post {
upPreferenceSummary(PreferKey.userAgent, AppConfig.userAgent)
}
}
}
@ -146,6 +152,28 @@ class OtherConfigFragment : BasePreferenceFragment(),
}
}
@SuppressLint("InflateParams")
private fun showUserAgentDialog() {
alert("UserAgent") {
var editText: AutoCompleteTextView? = null
customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
edit_view.setText(AppConfig.userAgent)
editText = edit_view
}
}
okButton {
val userAgent = editText?.text?.toString()
if (userAgent.isNullOrBlank()) {
removePref(PreferKey.userAgent)
} else {
putPrefString(PreferKey.userAgent, userAgent)
}
}
noButton()
}.show()
}
private fun clearCache() {
requireContext().alert(
titleResource = R.string.clear_cache,

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

@ -27,7 +27,9 @@ import io.legado.app.ui.main.explore.ExploreFragment
import io.legado.app.ui.main.my.MyFragment
import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
import io.legado.app.utils.getViewModel
import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.observeEvent
import kotlinx.android.synthetic.main.activity_main.*
import org.jetbrains.anko.toast
@ -101,8 +103,8 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
}
private fun upVersion() {
if (getPrefInt(PreferKey.versionCode) != App.versionCode) {
putPrefInt(PreferKey.versionCode, App.versionCode)
if (LocalConfig.versionCode != App.versionCode) {
LocalConfig.versionCode = App.versionCode
if (LocalConfig.isFirstOpenApp) {
val text = String(assets.open("help/appHelp.md").readBytes())
TextDialog.show(supportFragmentManager, text, TextDialog.MD)

@ -64,17 +64,20 @@ class QrCodeActivity : BaseActivity(R.layout.activity_qrcode_capture), QRCodeVie
.rationale(R.string.qr_per)
.onGranted {
zxingview.visibility = View.VISIBLE
zxingview.startSpotAndShowRect() // 显示扫描框,并开始识别
//TODO 显示扫描框,并开始识别
zxingview.startSpotAndShowRect()
}.request()
}
override fun onStop() {
zxingview.stopCamera() // 关闭摄像头预览,并且隐藏扫描框
//TODO 关闭摄像头预览,并且隐藏扫描框
zxingview.stopCamera()
super.onStop()
}
override fun onDestroy() {
zxingview.onDestroy() // 销毁二维码扫描控件
//TODO 销毁二维码扫描控件
zxingview.onDestroy()
super.onDestroy()
}
@ -96,7 +99,8 @@ class QrCodeActivity : BaseActivity(R.layout.activity_qrcode_capture), QRCodeVie
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
data?.data?.let {
zxingview.startSpotAndShowRect() // 显示扫描框,并开始识别
//TODO 显示扫描框,并开始识别
zxingview.startSpotAndShowRect()
if (resultCode == Activity.RESULT_OK && requestCode == requestQrImage) {
// 本来就用到 QRCodeView 时可直接调 QRCodeView 的方法,走通用的回调

@ -117,11 +117,13 @@ class ReplaceEditActivity :
if (view is EditText) {
val start = view.selectionStart
val end = view.selectionEnd
val edit = view.editableText//获取EditText的文字
//TODO 获取EditText的文字
val edit = view.editableText
if (start < 0 || start >= edit.length) {
edit.append(text)
} else {
edit.replace(start, end, text)//光标所在位置插入文字
//TODO 光标所在位置插入文字
edit.replace(start, end, text)
}
}
}

@ -80,7 +80,7 @@ object NetworkUtils {
fun getAbsoluteURL(baseURL: String?, relativePath: String?): String? {
if (baseURL.isNullOrEmpty()) return relativePath
if (relativePath.isNullOrEmpty()) return baseURL
if (relativePath.isAbsUrl()) return baseURL
if (relativePath.isAbsUrl()) return relativePath
var relativeUrl = relativePath
try {
val absoluteUrl = URL(baseURL.substringBefore(","))

@ -2,15 +2,8 @@
<resources>
<string name="pk_auto_refresh" translatable="false">auto_refresh</string>
<string name="pk_requested_direction" translatable="false">list_screen_direction</string>
<string name="pk_full_screen" translatable="false">full_screen</string>
<string name="pk_threads_num" translatable="false">threads_num</string>
<string name="pk_user_agent" translatable="false">user_agent</string>
<string name="pk_bookshelf_px" translatable="false">bookshelf_px</string>
<string name="pk_read_type" translatable="false">read_type</string>
<string name="pk_find_expand_group" translatable="false">expandGroupFind</string>
<string name="pk_default_read" translatable="false">defaultToRead</string>
<string name="pk_auto_download" translatable="false">autoDownload</string>
<string name="pk_check_update" translatable="false">checkUpdate</string>
<string name="legado_gzh" translatable="false">开源阅读</string>
<string name="source_rule_url" translatable="false">https://alanskycn.gitee.io/teachme/</string>

@ -51,6 +51,10 @@
app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category">
<io.legado.app.ui.widget.prefs.Preference
android:key="userAgent"
android:title="UserAgent" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="replaceEnableDefault"

Loading…
Cancel
Save