优化
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ android {
|
||||
defaultConfig {
|
||||
applicationId "io.legado.app"
|
||||
minSdk 21
|
||||
targetSdk 35
|
||||
targetSdk 36
|
||||
versionCode 10000 + gitCommits
|
||||
versionName version
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
> `{"example":"https://www.example.com/js/example.js", ...}` 自动复用已经下载的js文件
|
||||
|
||||
> 注意此处定义的函数可能会被多个线程同时调用,在函数里的全局变量内容将会共享使用,对其进行修改可能会出现竞争问题
|
||||
> 函数内不可声明全局变量,函数外的全局变量不可再赋值,否则会抛出 `无法修改密封对象的属性` 异常
|
||||
|
||||
* 并发率
|
||||
> 并发限制,单位ms,可填写两种格式
|
||||
|
||||
@@ -46,9 +46,7 @@ suspend fun OkHttpClient.newCallResponseBody(
|
||||
retry: Int = 0,
|
||||
builder: Request.Builder.() -> Unit
|
||||
): ResponseBody {
|
||||
return newCallResponse(retry, builder).let {
|
||||
it.body ?: throw IOException(it.message)
|
||||
}
|
||||
return newCallResponse(retry, builder).body
|
||||
}
|
||||
|
||||
suspend fun OkHttpClient.newCallStrResponse(
|
||||
@@ -56,7 +54,7 @@ suspend fun OkHttpClient.newCallStrResponse(
|
||||
builder: Request.Builder.() -> Unit
|
||||
): StrResponse {
|
||||
return newCallResponse(retry, builder).let {
|
||||
StrResponse(it, it.body?.text() ?: it.message)
|
||||
StrResponse(it, it.body.text())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +140,7 @@ fun Request.Builder.postForm(encodedForm: String) {
|
||||
post(encodedForm.toRequestBody(formContentType))
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun Request.Builder.postForm(form: Map<String, String>, encoded: Boolean = false) {
|
||||
val formBody = FormBody.Builder()
|
||||
form.forEach {
|
||||
|
||||
@@ -36,8 +36,8 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
|
||||
if (!res.isSuccessful) {
|
||||
throw NoStackTraceException("获取新版本出错(${res.code})")
|
||||
}
|
||||
val body = res.body?.text()
|
||||
if (body.isNullOrBlank()) {
|
||||
val body = res.body.text()
|
||||
if (body.isBlank()) {
|
||||
throw NoStackTraceException("获取新版本出错")
|
||||
}
|
||||
return GSON.fromJsonObject<GithubRelease>(body)
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.legado.app.utils.findNSPrefix
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import io.legado.app.utils.toRequestBody
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
@@ -36,7 +37,6 @@ import java.time.LocalDateTime
|
||||
import java.time.ZoneOffset
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
open class WebDav(
|
||||
@@ -169,7 +169,7 @@ open class WebDav(
|
||||
method("PROPFIND", requestBody)
|
||||
}.apply {
|
||||
checkResult(this)
|
||||
}.body?.text()
|
||||
}.body.text()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,7 +252,7 @@ open class WebDav(
|
||||
method("PROPFIND", requestBody)
|
||||
}.use { it.isSuccessful }
|
||||
}.onFailure {
|
||||
coroutineContext.ensureActive()
|
||||
currentCoroutineContext().ensureActive()
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ open class WebDav(
|
||||
method("PROPFIND", requestBody)
|
||||
}.use { it.code != 401 }
|
||||
}.onFailure {
|
||||
coroutineContext.ensureActive()
|
||||
currentCoroutineContext().ensureActive()
|
||||
}.getOrDefault(true)
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ open class WebDav(
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
coroutineContext.ensureActive()
|
||||
currentCoroutineContext().ensureActive()
|
||||
AppLog.put("WebDav创建目录失败\n${it.localizedMessage}", it)
|
||||
}.isSuccess
|
||||
}
|
||||
@@ -346,7 +346,7 @@ open class WebDav(
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
coroutineContext.ensureActive()
|
||||
currentCoroutineContext().ensureActive()
|
||||
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
|
||||
throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
|
||||
}
|
||||
@@ -367,7 +367,7 @@ open class WebDav(
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
coroutineContext.ensureActive()
|
||||
currentCoroutineContext().ensureActive()
|
||||
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
|
||||
throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
|
||||
}
|
||||
@@ -388,7 +388,7 @@ open class WebDav(
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
coroutineContext.ensureActive()
|
||||
currentCoroutineContext().ensureActive()
|
||||
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
|
||||
throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
|
||||
}
|
||||
@@ -401,8 +401,8 @@ open class WebDav(
|
||||
url(url)
|
||||
}.apply {
|
||||
checkResult(this)
|
||||
}.body?.byteStream()
|
||||
return byteStream ?: throw WebDavException("WebDav下载出错\nNull Exception")
|
||||
}.body.byteStream()
|
||||
return byteStream
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,7 +419,7 @@ open class WebDav(
|
||||
checkResult(it)
|
||||
}
|
||||
}.onFailure {
|
||||
coroutineContext.ensureActive()
|
||||
currentCoroutineContext().ensureActive()
|
||||
AppLog.put("WebDav删除失败\n${it.localizedMessage}", it)
|
||||
}.isSuccess
|
||||
}
|
||||
@@ -429,7 +429,7 @@ open class WebDav(
|
||||
*/
|
||||
private fun checkResult(response: Response) {
|
||||
if (!response.isSuccessful) {
|
||||
val body = response.body?.string()
|
||||
val body = response.body.string()
|
||||
if (response.code == 401) {
|
||||
val headers = response.headers("WWW-Authenticate")
|
||||
val supportBasicAuth = headers.any {
|
||||
@@ -440,7 +440,7 @@ open class WebDav(
|
||||
}
|
||||
}
|
||||
|
||||
if (response.message.isNotBlank() || body.isNullOrBlank()) {
|
||||
if (response.message.isNotBlank() || body.isBlank()) {
|
||||
throw WebDavException("${url}\n${response.code}:${response.message}")
|
||||
}
|
||||
val document = Jsoup.parse(body)
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.pdf.PdfRenderer
|
||||
import android.os.ParcelFileDescriptor
|
||||
import androidx.core.graphics.createBitmap
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
@@ -121,13 +122,11 @@ class PdfFile(var book: Book) {
|
||||
if (index >= renderer.pageCount) {
|
||||
return null
|
||||
}
|
||||
return renderer.openPage(index)?.use { page ->
|
||||
Bitmap.createBitmap(
|
||||
return renderer.openPage(index).use { page ->
|
||||
createBitmap(
|
||||
SystemUtils.screenWidthPx,
|
||||
(SystemUtils.screenWidthPx.toDouble() * page.height / page.width).toInt(),
|
||||
Bitmap.Config.ARGB_8888
|
||||
)
|
||||
.apply {
|
||||
(SystemUtils.screenWidthPx.toDouble() * page.height / page.width).toInt()
|
||||
).apply {
|
||||
this.eraseColor(Color.WHITE)
|
||||
page.render(this, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY)
|
||||
}
|
||||
@@ -168,7 +167,7 @@ class PdfFile(var book: Book) {
|
||||
null
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
} catch (_: Exception) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class AutoReadDialog : BaseDialogFragment(R.layout.dialog_auto_read) {
|
||||
val bottomDialog = (activity as ReadBookActivity).bottomDialog++
|
||||
if (bottomDialog > 0) {
|
||||
dismiss()
|
||||
return
|
||||
return@run
|
||||
}
|
||||
val bg = requireContext().bottomBackground
|
||||
val isLight = ColorUtils.isColorLight(bg)
|
||||
|
||||
@@ -10,8 +10,14 @@ import android.graphics.drawable.Drawable
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import splitties.init.appCtx
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.ObjectInputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.io.Serializable
|
||||
import java.util.Collections
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import kotlin.math.min
|
||||
@@ -458,6 +464,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
|
||||
*/
|
||||
private object Utils {
|
||||
|
||||
@Suppress("ConstPropertyName")
|
||||
private const val mSeparator = ' '
|
||||
|
||||
/**
|
||||
@@ -762,8 +769,8 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
|
||||
|
||||
var fileSize: Long = 0
|
||||
if (mostLongUsedFile != null) {
|
||||
fileSize = calculateSize(mostLongUsedFile!!)
|
||||
if (mostLongUsedFile!!.delete()) {
|
||||
fileSize = calculateSize(mostLongUsedFile)
|
||||
if (mostLongUsedFile.delete()) {
|
||||
lastUsageDates.remove(mostLongUsedFile)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,22 @@ package io.legado.app.utils.compress
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import io.legado.app.utils.DebugLog
|
||||
import io.legado.app.utils.compress.ZipUtils.zipFile
|
||||
import io.legado.app.utils.printOnDebug
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.*
|
||||
import java.util.zip.*
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipInputStream
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
@@ -241,7 +252,7 @@ object ZipUtils {
|
||||
if (!entryFile.canonicalPath.startsWith(dir.canonicalPath)) {
|
||||
throw SecurityException("压缩文件只能解压到指定路径")
|
||||
}
|
||||
if (entry!!.isDirectory) {
|
||||
if (entry.isDirectory) {
|
||||
if (!entryFile.exists()) {
|
||||
entryFile.mkdirs()
|
||||
}
|
||||
@@ -286,7 +297,7 @@ object ZipUtils {
|
||||
if (entry!!.isDirectory) {
|
||||
continue
|
||||
}
|
||||
val fileName = entry!!.name
|
||||
val fileName = entry.name
|
||||
if (filter != null && filter.invoke(fileName))
|
||||
fileNames.add(fileName)
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
buildscript {
|
||||
ext{
|
||||
compile_sdk_version = 35
|
||||
build_tool_version = '34.0.0'
|
||||
compile_sdk_version = 36
|
||||
// build_tool_version = '34.0.0'
|
||||
// kotlin_version = '1.9.22'
|
||||
// ksp_version = "1.0.17"
|
||||
// agp_version = '8.2.2'
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ android.useAndroidX=true
|
||||
android.enableJetifier=false
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
||||
kotlin.incremental.useClasspathSnapshot=true
|
||||
# kotlin.incremental.useClasspathSnapshot=true
|
||||
android.enableResourceOptimizations=true
|
||||
# android.enableNewResourceShrinker' is deprecated.
|
||||
# It was removed in version 8.0 of the Android Gradle plugin.
|
||||
|
||||
+26
-19
@@ -1,53 +1,60 @@
|
||||
[versions]
|
||||
|
||||
kotlin = "2.2.0"
|
||||
ksp = "2.2.0-2.0.2"
|
||||
agp = "8.10.1"
|
||||
appcompat = "1.7.0"
|
||||
kotlin = "2.3.0"
|
||||
ksp = "2.3.3"
|
||||
agp = "8.13.2"
|
||||
appcompat = "1.7.1"
|
||||
colorpicker = "1.1.0"
|
||||
commonsText = "1.13.1"
|
||||
commonsText = "1.15.0"
|
||||
constraintlayout = "2.2.1"
|
||||
core = "1.16.0"
|
||||
core = "1.17.0"
|
||||
#noinspection GradleDependency
|
||||
firebaseBom = "33.2.0"
|
||||
flexbox = "3.0.0"
|
||||
fragment = "1.8.7"
|
||||
fragment = "1.8.9"
|
||||
|
||||
#不要更新版本
|
||||
#noinspection GradleDependency
|
||||
hutool = "5.8.22"
|
||||
|
||||
libarchive = "1.1.6"
|
||||
lifecycle = "2.9.0"
|
||||
glide = "4.16.0"
|
||||
gson = "2.13.1"
|
||||
jsonPath = "2.9.0"
|
||||
#noinspection GradleDependency
|
||||
lifecycle = "2.9.4"
|
||||
glide = "5.0.5"
|
||||
gson = "2.13.2"
|
||||
jsonPath = "2.10.0"
|
||||
# issue #3811,不要更新版本,新版引入了一个破坏性变更(详见https://github.com/jhy/jsoup/pull/2017)
|
||||
# 若要升级请确保相关代码不会受此变更影响(如AnalyzeByJSoup.kt、JsoupXpath库等)
|
||||
#noinspection GradleDependency
|
||||
jsoup = "1.16.2"
|
||||
jsoupxpath = "2.5.3"
|
||||
coroutines = "1.10.2"
|
||||
liveeventbus = "1.8.14"
|
||||
markwon = "4.6.2"
|
||||
material = "1.12.0"
|
||||
media = "1.7.0"
|
||||
media3 = "1.6.1"
|
||||
material = "1.13.0"
|
||||
media = "1.7.1"
|
||||
media3 = "1.8.0"
|
||||
nanoHttpd = "2.3.1"
|
||||
okhttp = "5.1.0"
|
||||
okhttp = "5.3.2"
|
||||
preference = "1.2.1"
|
||||
#noinspection GradleDependency
|
||||
protobufJavalite = "4.26.1"
|
||||
quickChineseTransfer = "0.2.16"
|
||||
#noinspection GradleDependency
|
||||
room = "2.7.1"
|
||||
splitties = "3.0.0"
|
||||
rhino = "1.8.0"
|
||||
rhino = "1.8.1"
|
||||
desugar = "2.1.5"
|
||||
|
||||
activity = "1.10.1"
|
||||
#noinspection GradleDependency
|
||||
activity = "1.11.0"
|
||||
#kotlinxSerialization = "1.8.0"
|
||||
swiperefreshlayout = "1.1.0"
|
||||
swiperefreshlayout = "1.2.0"
|
||||
#noinspection GradleDependency
|
||||
recyclerview = "1.2.0"
|
||||
#noinspection GradleDependency
|
||||
viewpager2 = "1.0.0"
|
||||
webkit = "1.13.0"
|
||||
webkit = "1.14.0"
|
||||
collection = "1.5.0"
|
||||
|
||||
zxingLite = "3.3.0"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#Tue Aug 27 18:19:17 CST 2024
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -13,7 +13,7 @@ android {
|
||||
}
|
||||
defaultConfig {
|
||||
minSdk 21
|
||||
targetSdk 35
|
||||
targetSdk 36
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
|
||||
@@ -15,7 +15,7 @@ android {
|
||||
}
|
||||
defaultConfig {
|
||||
minSdk 21
|
||||
targetSdk 35
|
||||
targetSdk 36
|
||||
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
thiz1 = Context.toObject(thiz1, topLevel)
|
||||
}
|
||||
val engineScope = getRuntimeScope(context)
|
||||
val localScope = if (thiz1 != null) thiz1 as Scriptable else engineScope
|
||||
val localScope = thiz1 ?: engineScope
|
||||
val obj = ScriptableObject.getProperty(localScope, name) as? Function
|
||||
?: throw NoSuchMethodException("no such method: $name")
|
||||
var scope = obj.parentScope
|
||||
@@ -229,7 +229,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
override fun <T> getInterface(clazz: Class<T>): T? {
|
||||
return try {
|
||||
implementor.getInterface(null, clazz)
|
||||
} catch (var3: ScriptException) {
|
||||
} catch (_: ScriptException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -240,7 +240,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
} else {
|
||||
try {
|
||||
implementor.getInterface(obj, paramClass)
|
||||
} catch (var4: ScriptException) {
|
||||
} catch (_: ScriptException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
if (System.getSecurityManager() != null) {
|
||||
try {
|
||||
AccessController.checkPermission(AllPermission())
|
||||
} catch (var6: AccessControlException) {
|
||||
} catch (_: AccessControlException) {
|
||||
accessContext = AccessController.getContext()
|
||||
}
|
||||
}
|
||||
@@ -413,7 +413,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
obj1 = Context.toObject(obj1, topLevel)
|
||||
}
|
||||
val engineScope = getRuntimeScope(context)
|
||||
val localScope = if (obj1 != null) obj1 as Scriptable else engineScope
|
||||
val localScope = obj1 ?: engineScope
|
||||
val methods = clazz.methods
|
||||
val methodsSize = methods.size
|
||||
for (index in 0 until methodsSize) {
|
||||
|
||||
Reference in New Issue
Block a user