This commit is contained in:
Horis
2025-12-16 23:14:06 +08:00
parent baba6159d2
commit 2d4fabf0ac
16 changed files with 93 additions and 69 deletions
+1 -1
View File
@@ -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,16 +122,14 @@ 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 {
this.eraseColor(Color.WHITE)
page.render(this, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY)
}
(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)
}