From ebe22a79d86a8f3ab946850aa3165d96ffc52244 Mon Sep 17 00:00:00 2001 From: adhu2018 <41824074+adhu2018@users.noreply.github.com> Date: Wed, 1 Nov 2023 17:25:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去除无用引用 --- app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt | 1 - app/src/main/java/io/legado/app/model/CheckSource.kt | 1 - app/src/main/java/io/legado/app/model/localBook/LocalBook.kt | 1 - app/src/main/java/io/legado/app/model/localBook/UmdFile.kt | 2 -- app/src/main/java/io/legado/app/service/ExportBookService.kt | 1 - .../java/io/legado/app/ui/book/read/page/entities/TextLine.kt | 2 -- .../app/ui/book/read/page/entities/column/ReviewColumn.kt | 1 - .../java/io/legado/app/ui/book/toc/rule/TxtTocRuleAdapter.kt | 1 - 8 files changed, 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt index b4cf2d3089a8..e62651f969d9 100644 --- a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt @@ -2,7 +2,6 @@ package io.legado.app.data.entities import androidx.room.Entity import androidx.room.PrimaryKey -import io.legado.app.utils.GSON @Entity(tableName = "txtTocRules") diff --git a/app/src/main/java/io/legado/app/model/CheckSource.kt b/app/src/main/java/io/legado/app/model/CheckSource.kt index d30a66918a1a..a55b49a3a998 100644 --- a/app/src/main/java/io/legado/app/model/CheckSource.kt +++ b/app/src/main/java/io/legado/app/model/CheckSource.kt @@ -3,7 +3,6 @@ package io.legado.app.model import android.content.Context import io.legado.app.R import io.legado.app.constant.IntentAction -import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSourcePart import io.legado.app.help.CacheManager import io.legado.app.help.IntentData diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index 0720f5a1b900..15bcac44bfca 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -24,7 +24,6 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.* import kotlinx.coroutines.runBlocking import org.apache.commons.text.StringEscapeUtils -import org.jsoup.nodes.Entities import splitties.init.appCtx import java.io.* import java.util.regex.Pattern diff --git a/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt b/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt index 6e5ddf9ed830..1f4d96d63682 100644 --- a/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt @@ -5,8 +5,6 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.utils.* import me.ag2s.umdlib.domain.UmdBook import me.ag2s.umdlib.umd.UmdReader -import splitties.init.appCtx - import java.io.File import java.io.InputStream diff --git a/app/src/main/java/io/legado/app/service/ExportBookService.kt b/app/src/main/java/io/legado/app/service/ExportBookService.kt index 5b6353d67132..6509a3c6acb8 100644 --- a/app/src/main/java/io/legado/app/service/ExportBookService.kt +++ b/app/src/main/java/io/legado/app/service/ExportBookService.kt @@ -38,7 +38,6 @@ import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.MD5Utils import io.legado.app.utils.NetworkUtils import io.legado.app.utils.activityPendingIntent -import io.legado.app.utils.buildMainHandler import io.legado.app.utils.cnCompare import io.legado.app.utils.createFolderIfNotExist import io.legado.app.utils.isContentScheme diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 65f53cb47351..1a14ef62bec9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -1,11 +1,9 @@ package io.legado.app.ui.book.read.page.entities import android.graphics.Paint.FontMetrics -import android.text.TextPaint import androidx.annotation.Keep import io.legado.app.ui.book.read.page.entities.column.BaseColumn import io.legado.app.ui.book.read.page.provider.ChapterProvider -import io.legado.app.utils.textHeight /** * 行信息 diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt index 8b54feca75cf..748f1b57cee9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/column/ReviewColumn.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.book.read.page.entities.column import android.graphics.Canvas import android.graphics.Paint import android.graphics.Path -import android.text.StaticLayout import androidx.annotation.Keep import io.legado.app.ui.book.read.page.provider.ChapterProvider diff --git a/app/src/main/java/io/legado/app/ui/book/toc/rule/TxtTocRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/rule/TxtTocRuleAdapter.kt index eb26474b06c9..3cfc4e719f5f 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/rule/TxtTocRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/rule/TxtTocRuleAdapter.kt @@ -11,7 +11,6 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter -import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.TxtTocRule import io.legado.app.databinding.ItemTxtTocRuleBinding import io.legado.app.lib.theme.backgroundColor From 060ffd64b289dcd1999e7e22ac62643a6197b93c Mon Sep 17 00:00:00 2001 From: adhu2018 <41824074+adhu2018@users.noreply.github.com> Date: Wed, 1 Nov 2023 17:43:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化报错提示; buildDir 已弃用。 https://docs.gradle.org/current/userguide/upgrading_version_8.html#project_builddir ; 其他优化。 --- .gitignore | 4 ++-- .../main/java/io/legado/app/data/entities/ReplaceRule.kt | 2 ++ app/src/main/java/io/legado/app/help/book/BookExtensions.kt | 2 +- .../main/java/io/legado/app/help/http/ObsoleteUrlFactory.kt | 4 ++++ app/src/main/java/io/legado/app/lib/prefs/Preference.kt | 2 +- .../io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt | 2 +- .../java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt | 2 +- .../java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt | 2 +- app/src/main/java/io/legado/app/model/localBook/PdfFile.kt | 6 ++---- .../io/legado/app/ui/widget/anima/RefreshProgressBar.kt | 3 --- .../java/io/legado/app/ui/widget/code/CodeViewExtensions.kt | 2 +- build.gradle | 2 +- 12 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 04fb0b4f1480..5ba10ef1c8ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.iml .gradle -/local.properties +local.properties .DS_Store /build /captures @@ -12,5 +12,5 @@ node_modules/ /app/google /app/gradle.properties package-lock.json -.idea/* +.idea/ diff --git a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt index 62586271afb9..a8e375a28cb0 100644 --- a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt @@ -7,6 +7,7 @@ import androidx.room.Entity import androidx.room.Index import androidx.room.PrimaryKey import io.legado.app.R +import io.legado.app.constant.AppLog import io.legado.app.exception.NoStackTraceException import kotlinx.parcelize.Parcelize import splitties.init.appCtx @@ -84,6 +85,7 @@ data class ReplaceRule( try { Pattern.compile(pattern) } catch (ex: PatternSyntaxException) { + AppLog.put(ex.message) return false } } diff --git a/app/src/main/java/io/legado/app/help/book/BookExtensions.kt b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt index db1d15b9e1b8..d5c2b821ea1c 100644 --- a/app/src/main/java/io/legado/app/help/book/BookExtensions.kt +++ b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt @@ -243,7 +243,7 @@ fun Book.getExportFileName(suffix: String): String { RhinoScriptEngine.eval(jsStr, bindings).toString() + "." + suffix }.onFailure { AppLog.put("导出书名规则错误,使用默认规则\n${it.localizedMessage}", it) - }.getOrDefault("${name} 作者:${getRealAuthor()}.$suffix") + }.getOrDefault("$name 作者:${getRealAuthor()}.$suffix") } /** diff --git a/app/src/main/java/io/legado/app/help/http/ObsoleteUrlFactory.kt b/app/src/main/java/io/legado/app/help/http/ObsoleteUrlFactory.kt index 39dc334c65e3..5d9a67b36ae3 100644 --- a/app/src/main/java/io/legado/app/help/http/ObsoleteUrlFactory.kt +++ b/app/src/main/java/io/legado/app/help/http/ObsoleteUrlFactory.kt @@ -1,5 +1,7 @@ package io.legado.app.help.http +import android.os.Build +import androidx.annotation.RequiresApi import io.legado.app.help.http.CookieManager.cookieJarHeader import io.legado.app.help.http.SSLHelper.unsafeTrustManager import okhttp3.Call @@ -797,6 +799,7 @@ class ObsoleteUrlFactory(private var client: OkHttpClient) : URLStreamHandlerFac } // Should only be invoked on Java 8+ or Android API 24+. + @RequiresApi(Build.VERSION_CODES.N) override fun getContentLengthLong(): Long { return delegate.contentLengthLong } @@ -846,6 +849,7 @@ class ObsoleteUrlFactory(private var client: OkHttpClient) : URLStreamHandlerFac } // Should only be invoked on Java 8+ or Android API 24+. + @RequiresApi(Build.VERSION_CODES.N) override fun getHeaderFieldLong(field: String, defaultValue: Long): Long { return delegate.getHeaderFieldLong(field, defaultValue) } diff --git a/app/src/main/java/io/legado/app/lib/prefs/Preference.kt b/app/src/main/java/io/legado/app/lib/prefs/Preference.kt index 784c2972b091..619b5cc9826e 100644 --- a/app/src/main/java/io/legado/app/lib/prefs/Preference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/Preference.kt @@ -51,7 +51,7 @@ open class Preference(context: Context, attrs: AttributeSet) : val tvTitle = viewHolder.findViewById(R.id.preference_title) as? TextView tvTitle?.let { tvTitle.text = title - tvTitle.isVisible = title != null && title.isNotEmpty() + tvTitle.isVisible = !title.isNullOrEmpty() } val tvSummary = viewHolder.findViewById(R.id.preference_desc) as? TextView tvSummary?.let { diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt index b5b672e5bafd..71d9006ce17a 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt @@ -143,7 +143,7 @@ class AnalyzeByJSonPath(json: Any) { val results = ArrayList>() for (rl in rules) { val temp = getList(rl) - if (temp != null && temp.isNotEmpty()) { + if (!temp.isNullOrEmpty()) { results.add(temp) if (temp.isNotEmpty() && ruleAnalyzes.elementsType == "||") { break diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index 05ae18c68da7..4963df95f168 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -303,7 +303,7 @@ class AnalyzeByJSoup(doc: Any) { } val len = elements.size - val lastIndexes = (indexDefault.size - 1).takeIf { it != -1 } ?: indexes.size - 1 + val lastIndexes = (indexDefault.size - 1).takeIf { it != -1 } ?: (indexes.size - 1) val indexSet = mutableSetOf() /** diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt index 0495a0916ffd..b0d52cf3ac39 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt @@ -63,7 +63,7 @@ class AnalyzeByXPath(doc: Any) { val results = ArrayList>() for (rl in rules) { val temp = getElements(rl) - if (temp != null && temp.isNotEmpty()) { + if (!temp.isNullOrEmpty()) { results.add(temp) if (temp.isNotEmpty() && ruleAnalyzes.elementsType == "||") { break diff --git a/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt b/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt index 6b44617dd72f..4b7e0433ae27 100644 --- a/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/PdfFile.kt @@ -80,9 +80,7 @@ class PdfFile(var book: Book) { if (!File(book.coverUrl!!).exists()) { FileOutputStream(FileUtils.createFileIfNotExist(book.coverUrl!!)).use { out -> - openPdfPage(renderer, 0)?.let { cover -> - cover.compress(Bitmap.CompressFormat.JPEG, 90, out) - } + openPdfPage(renderer, 0)?.compress(Bitmap.CompressFormat.JPEG, 90, out) out.flush() } } @@ -159,7 +157,7 @@ class PdfFile(var book: Book) { buildString { val start = chapter.index * PAGE_SIZE - val end = Math.min((chapter.index + 1) * PAGE_SIZE, renderer.pageCount) + val end = ((chapter.index + 1) * PAGE_SIZE).coerceAtMost(renderer.pageCount) (start until end).forEach { append("") .append('\n') diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt b/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt index 3a0af5b03346..ad2a46b39fb3 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt @@ -75,9 +75,6 @@ class RefreshProgressBar @JvmOverloads constructor( if (secondDurProgress > 0 && secondMaxProgress > 0) { var secondDur = secondDurProgress - if (secondDur < 0) { - secondDur = 0 - } if (secondDur > secondMaxProgress) { secondDur = secondMaxProgress } diff --git a/app/src/main/java/io/legado/app/ui/widget/code/CodeViewExtensions.kt b/app/src/main/java/io/legado/app/ui/widget/code/CodeViewExtensions.kt index e8d92759ea51..afefa8cd9c09 100644 --- a/app/src/main/java/io/legado/app/ui/widget/code/CodeViewExtensions.kt +++ b/app/src/main/java/io/legado/app/ui/widget/code/CodeViewExtensions.kt @@ -13,7 +13,7 @@ val legadoPattern: Pattern = Pattern.compile("\\|\\||&&|%%|@js:|@Json:|@css:|@@| val jsonPattern: Pattern = Pattern.compile("\"[A-Za-z0-9]*?\"\\:|\"|\\{|\\}|\\[|\\]") val wrapPattern: Pattern = Pattern.compile("\\\\n") val operationPattern: Pattern = - Pattern.compile(":|==|>|<|!=|>=|<=|->|=|>|<|%|-|-=|%=|\\+|\\-|\\-=|\\+=|\\^|\\&|\\|::|\\?|\\*") + Pattern.compile(":|==|>|<|!=|>=|<=|->|=|%|-|-=|%=|\\+|\\-|\\-=|\\+=|\\^|\\&|\\|::|\\?|\\*") val jsPattern: Pattern = Pattern.compile("var") fun CodeView.addLegadoPattern() { diff --git a/build.gradle b/build.gradle index c21da313c201..b7fbe93f340b 100644 --- a/build.gradle +++ b/build.gradle @@ -23,5 +23,5 @@ plugins { } tasks.register('clean', Delete) { - delete rootProject.buildDir + delete rootProject.layout.buildDirectory }