Răsfoiți Sursa

优化

优化报错提示;
buildDir 已弃用。 https://docs.gradle.org/current/userguide/upgrading_version_8.html#project_builddir ;
其他优化。
adhu2018 3 ani în urmă
părinte
comite
2c21a71230

+ 2 - 2
.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/
 

+ 2 - 0
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
             }
         }

+ 1 - 1
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")
 }
 
 /**

+ 4 - 0
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)
         }

+ 1 - 1
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 {

+ 1 - 1
app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt

@@ -143,7 +143,7 @@ class AnalyzeByJSonPath(json: Any) {
             val results = ArrayList<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

+ 1 - 1
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<Int>()
 
             /**

+ 1 - 1
app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt

@@ -63,7 +63,7 @@ class AnalyzeByXPath(doc: Any) {
             val results = ArrayList<List<JXNode>>()
             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

+ 2 - 4
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("<img src=").append('"').append(it).append('"').append(" >")
                             .append('\n')

+ 0 - 3
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
             }

+ 1 - 1
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() {

+ 1 - 1
build.gradle

@@ -23,5 +23,5 @@ plugins {
 }
 
 tasks.register('clean', Delete) {
-    delete rootProject.buildDir
+    delete rootProject.layout.buildDirectory
 }