mirror of
https://github.com/gedoor/legado.git
synced 2024-07-17 00:58:29 +08:00
优化
This commit is contained in:
parent
d6ff9d06ad
commit
84e1b14f8e
@ -1,6 +1,8 @@
|
||||
package io.legado.app.model
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.util.Log
|
||||
import io.legado.app.BuildConfig
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.data.entities.*
|
||||
import io.legado.app.help.book.isWebFile
|
||||
@ -30,16 +32,19 @@ object Debug {
|
||||
@Synchronized
|
||||
fun log(
|
||||
sourceUrl: String?,
|
||||
msg: String? = "",
|
||||
msg: String = "",
|
||||
print: Boolean = true,
|
||||
isHtml: Boolean = false,
|
||||
showTime: Boolean = true,
|
||||
state: Int = 1
|
||||
) {
|
||||
if (BuildConfig.DEBUG && !isHtml) {
|
||||
Log.d("sourceDebug", msg)
|
||||
}
|
||||
//调试信息始终要执行
|
||||
callback?.let {
|
||||
if ((debugSource != sourceUrl || !print)) return
|
||||
var printMsg = msg ?: ""
|
||||
var printMsg = msg
|
||||
if (isHtml) {
|
||||
printMsg = HtmlFormatter.format(msg)
|
||||
}
|
||||
@ -49,8 +54,8 @@ object Debug {
|
||||
}
|
||||
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) {
|
||||
printMsg = HtmlFormatter.format(msg)
|
||||
}
|
||||
@ -66,7 +71,7 @@ object Debug {
|
||||
|
||||
@Synchronized
|
||||
fun log(msg: String?) {
|
||||
log(debugSource, msg, true)
|
||||
log(debugSource, msg ?: "", true)
|
||||
}
|
||||
|
||||
fun cancelDebug(destroy: Boolean = false) {
|
||||
@ -162,11 +167,13 @@ object Debug {
|
||||
log(bookSource.bookSourceUrl, "⇒开始访问详情页:$key")
|
||||
infoDebug(scope, bookSource, book)
|
||||
}
|
||||
|
||||
key.contains("::") -> {
|
||||
val url = key.substringAfter("::")
|
||||
log(bookSource.bookSourceUrl, "⇒开始访问发现页:$url")
|
||||
exploreDebug(scope, bookSource, url)
|
||||
}
|
||||
|
||||
key.startsWith("++") -> {
|
||||
val url = key.substring(2)
|
||||
val book = Book()
|
||||
@ -175,6 +182,7 @@ object Debug {
|
||||
log(bookSource.bookSourceUrl, "⇒开始访目录页:$url")
|
||||
tocDebug(scope, bookSource, book)
|
||||
}
|
||||
|
||||
key.startsWith("--") -> {
|
||||
val url = key.substring(2)
|
||||
val book = Book()
|
||||
@ -185,6 +193,7 @@ object Debug {
|
||||
chapter.url = url
|
||||
contentDebug(scope, bookSource, book, chapter, null)
|
||||
}
|
||||
|
||||
else -> {
|
||||
log(bookSource.bookSourceUrl, "⇒开始搜索关键字:$key")
|
||||
searchDebug(scope, bookSource, key)
|
||||
|
@ -75,7 +75,7 @@ object Rss {
|
||||
val res = analyzeUrl.getStrResponseAwait()
|
||||
checkRedirect(rssSource, res)
|
||||
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)
|
||||
analyzeRule.setContent(res.body)
|
||||
.setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link))
|
||||
|
@ -48,7 +48,7 @@ object BookContent {
|
||||
} else {
|
||||
nextChapterUrl
|
||||
}
|
||||
val content = StringBuilder()
|
||||
val contentList = arrayListOf<String>()
|
||||
val nextUrlList = arrayListOf(redirectUrl)
|
||||
val contentRule = bookSource.getContentRule()
|
||||
val analyzeRule = AnalyzeRule(book, bookSource)
|
||||
@ -72,7 +72,7 @@ object BookContent {
|
||||
var contentData = analyzeContent(
|
||||
book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl
|
||||
)
|
||||
content.append(contentData.first)
|
||||
contentList.add(contentData.first)
|
||||
if (contentData.second.size == 1) {
|
||||
var nextUrl = contentData.second[0]
|
||||
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
|
||||
@ -95,7 +95,8 @@ object BookContent {
|
||||
)
|
||||
nextUrl =
|
||||
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}")
|
||||
@ -119,11 +120,11 @@ object BookContent {
|
||||
}
|
||||
asyncArray.forEach { coroutine ->
|
||||
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
|
||||
if (!replaceRegex.isNullOrEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user