feat: 优化代码

pull/120/head
kunfei 5 years ago
parent ad19ebc258
commit bfa4e10b4a
  1. 21
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@ -33,10 +33,14 @@ object BookContent {
)
)
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
val analyzeRule = AnalyzeRule(book)
val content = StringBuilder()
val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule()
var contentData = analyzeContent(body, contentRule, book, bookChapter, bookSource, baseUrl)
var contentData = analyzeContent(
analyzeRule.setContent(body, baseUrl),
contentRule, bookChapter, bookSource
)
content.append(contentData.content.replace(bookChapter.title, ""))
if (contentData.nextUrl.size == 1) {
var nextUrl = contentData.nextUrl[0]
@ -58,8 +62,8 @@ object BookContent {
.body?.let { nextBody ->
contentData =
analyzeContent(
nextBody, contentRule, book,
bookChapter, bookSource, baseUrl, false
analyzeRule.setContent(nextBody, nextUrl),
contentRule, bookChapter, bookSource, false
)
nextUrl =
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else ""
@ -83,8 +87,8 @@ object BookContent {
.body?.let {
contentData =
analyzeContent(
it, contentRule, book, bookChapter,
bookSource, item.nextUrl, false
analyzeRule.setContent(it, item.nextUrl),
contentRule, bookChapter, bookSource, false
)
item.content = contentData.content
}
@ -94,6 +98,7 @@ object BookContent {
content.append(item.content)
}
}
Debug.log(bookSource.bookSourceUrl, "┌获取章节名称")
Debug.log(bookSource.bookSourceUrl, "${bookChapter.title}")
Debug.log(bookSource.bookSourceUrl, "┌获取正文内容")
@ -103,17 +108,13 @@ object BookContent {
@Throws(Exception::class)
private fun analyzeContent(
body: String,
analyzeRule: AnalyzeRule,
contentRule: ContentRule,
book: Book,
chapter: BookChapter,
bookSource: BookSource,
baseUrl: String,
printLog: Boolean = true
): ContentData<List<String>> {
val nextUrlList = arrayListOf<String>()
val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body, baseUrl)
analyzeRule.chapter = chapter
val nextUrlRule = contentRule.nextContentUrl
if (!nextUrlRule.isNullOrEmpty()) {

Loading…
Cancel
Save