kunfei 3 лет назад
Родитель
Сommit
bdba8b85a6

+ 14 - 5
app/src/main/java/io/legado/app/model/Debug.kt

@@ -1,6 +1,8 @@
 package io.legado.app.model
 package io.legado.app.model
 
 
 import android.annotation.SuppressLint
 import android.annotation.SuppressLint
+import android.util.Log
+import io.legado.app.BuildConfig
 import io.legado.app.constant.AppPattern
 import io.legado.app.constant.AppPattern
 import io.legado.app.data.entities.*
 import io.legado.app.data.entities.*
 import io.legado.app.help.book.isWebFile
 import io.legado.app.help.book.isWebFile
@@ -30,16 +32,19 @@ object Debug {
     @Synchronized
     @Synchronized
     fun log(
     fun log(
         sourceUrl: String?,
         sourceUrl: String?,
-        msg: String? = "",
+        msg: String = "",
         print: Boolean = true,
         print: Boolean = true,
         isHtml: Boolean = false,
         isHtml: Boolean = false,
         showTime: Boolean = true,
         showTime: Boolean = true,
         state: Int = 1
         state: Int = 1
     ) {
     ) {
+        if (BuildConfig.DEBUG && !isHtml) {
+            Log.d("sourceDebug", msg)
+        }
         //调试信息始终要执行
         //调试信息始终要执行
         callback?.let {
         callback?.let {
             if ((debugSource != sourceUrl || !print)) return
             if ((debugSource != sourceUrl || !print)) return
-            var printMsg = msg ?: ""
+            var printMsg = msg
             if (isHtml) {
             if (isHtml) {
                 printMsg = HtmlFormatter.format(msg)
                 printMsg = HtmlFormatter.format(msg)
             }
             }
@@ -49,8 +54,8 @@ object Debug {
             }
             }
             it.printLog(state, printMsg)
             it.printLog(state, printMsg)
         }
         }
-        if (isChecking && sourceUrl != null && (msg ?: "").length < 30) {
-            var printMsg = msg ?: ""
+        if (isChecking && sourceUrl != null && (msg).length < 30) {
+            var printMsg = msg
             if (isHtml) {
             if (isHtml) {
                 printMsg = HtmlFormatter.format(msg)
                 printMsg = HtmlFormatter.format(msg)
             }
             }
@@ -66,7 +71,7 @@ object Debug {
 
 
     @Synchronized
     @Synchronized
     fun log(msg: String?) {
     fun log(msg: String?) {
-        log(debugSource, msg, true)
+        log(debugSource, msg ?: "", true)
     }
     }
 
 
     fun cancelDebug(destroy: Boolean = false) {
     fun cancelDebug(destroy: Boolean = false) {
@@ -162,11 +167,13 @@ object Debug {
                 log(bookSource.bookSourceUrl, "⇒开始访问详情页:$key")
                 log(bookSource.bookSourceUrl, "⇒开始访问详情页:$key")
                 infoDebug(scope, bookSource, book)
                 infoDebug(scope, bookSource, book)
             }
             }
+
             key.contains("::") -> {
             key.contains("::") -> {
                 val url = key.substringAfter("::")
                 val url = key.substringAfter("::")
                 log(bookSource.bookSourceUrl, "⇒开始访问发现页:$url")
                 log(bookSource.bookSourceUrl, "⇒开始访问发现页:$url")
                 exploreDebug(scope, bookSource, url)
                 exploreDebug(scope, bookSource, url)
             }
             }
+
             key.startsWith("++") -> {
             key.startsWith("++") -> {
                 val url = key.substring(2)
                 val url = key.substring(2)
                 val book = Book()
                 val book = Book()
@@ -175,6 +182,7 @@ object Debug {
                 log(bookSource.bookSourceUrl, "⇒开始访目录页:$url")
                 log(bookSource.bookSourceUrl, "⇒开始访目录页:$url")
                 tocDebug(scope, bookSource, book)
                 tocDebug(scope, bookSource, book)
             }
             }
+
             key.startsWith("--") -> {
             key.startsWith("--") -> {
                 val url = key.substring(2)
                 val url = key.substring(2)
                 val book = Book()
                 val book = Book()
@@ -185,6 +193,7 @@ object Debug {
                 chapter.url = url
                 chapter.url = url
                 contentDebug(scope, bookSource, book, chapter, null)
                 contentDebug(scope, bookSource, book, chapter, null)
             }
             }
+
             else -> {
             else -> {
                 log(bookSource.bookSourceUrl, "⇒开始搜索关键字:$key")
                 log(bookSource.bookSourceUrl, "⇒开始搜索关键字:$key")
                 searchDebug(scope, bookSource, key)
                 searchDebug(scope, bookSource, key)

+ 1 - 1
app/src/main/java/io/legado/app/model/rss/Rss.kt

@@ -75,7 +75,7 @@ object Rss {
         val res = analyzeUrl.getStrResponseAwait()
         val res = analyzeUrl.getStrResponseAwait()
         checkRedirect(rssSource, res)
         checkRedirect(rssSource, res)
         Debug.log(rssSource.sourceUrl, "≡获取成功:${rssSource.sourceUrl}")
         Debug.log(rssSource.sourceUrl, "≡获取成功:${rssSource.sourceUrl}")
-        Debug.log(rssSource.sourceUrl, res.body, state = 20)
+        Debug.log(rssSource.sourceUrl, res.body ?: "", state = 20)
         val analyzeRule = AnalyzeRule(rssArticle, rssSource)
         val analyzeRule = AnalyzeRule(rssArticle, rssSource)
         analyzeRule.setContent(res.body)
         analyzeRule.setContent(res.body)
             .setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link))
             .setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link))

+ 6 - 5
app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@@ -48,7 +48,7 @@ object BookContent {
         } else {
         } else {
             nextChapterUrl
             nextChapterUrl
         }
         }
-        val content = StringBuilder()
+        val contentList = arrayListOf<String>()
         val nextUrlList = arrayListOf(redirectUrl)
         val nextUrlList = arrayListOf(redirectUrl)
         val contentRule = bookSource.getContentRule()
         val contentRule = bookSource.getContentRule()
         val analyzeRule = AnalyzeRule(book, bookSource)
         val analyzeRule = AnalyzeRule(book, bookSource)
@@ -72,7 +72,7 @@ object BookContent {
         var contentData = analyzeContent(
         var contentData = analyzeContent(
             book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl
             book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl
         )
         )
-        content.append(contentData.first)
+        contentList.add(contentData.first)
         if (contentData.second.size == 1) {
         if (contentData.second.size == 1) {
             var nextUrl = contentData.second[0]
             var nextUrl = contentData.second[0]
             while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
             while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
@@ -95,7 +95,8 @@ object BookContent {
                     )
                     )
                     nextUrl =
                     nextUrl =
                         if (contentData.second.isNotEmpty()) contentData.second[0] else ""
                         if (contentData.second.isNotEmpty()) contentData.second[0] else ""
-                    content.append("\n").append(contentData.first)
+                    contentList.add(contentData.first)
+                    Debug.log(bookSource.bookSourceUrl, "第${contentList.size}页完成")
                 }
                 }
             }
             }
             Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
             Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
@@ -119,11 +120,11 @@ object BookContent {
                 }
                 }
                 asyncArray.forEach { coroutine ->
                 asyncArray.forEach { coroutine ->
                     coroutineContext.ensureActive()
                     coroutineContext.ensureActive()
-                    content.append("\n").append(coroutine.await())
+                    contentList.add(coroutine.await())
                 }
                 }
             }
             }
         }
         }
-        var contentStr = content.toString()
+        var contentStr = contentList.joinToString("\n")
         //全文替换
         //全文替换
         val replaceRegex = contentRule.replaceRegex
         val replaceRegex = contentRule.replaceRegex
         if (!replaceRegex.isNullOrEmpty()) {
         if (!replaceRegex.isNullOrEmpty()) {