From c10a9bfe8a5a262fde50fa2cb51fa3208ad7d1c1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 7 Jan 2022 22:49:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/localBook/TextFile.kt | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/TextFile.kt b/app/src/main/java/io/legado/app/model/localBook/TextFile.kt index 04a684c96..9a3f434b8 100644 --- a/app/src/main/java/io/legado/app/model/localBook/TextFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/TextFile.kt @@ -188,11 +188,10 @@ class TextFile(private val book: Book) { lastChapter.end = curOffset } } - for (i in toc.indices) { - val bean = toc[i] - bean.index = i - bean.bookUrl = book.bookUrl - bean.url = (MD5Utils.md5Encode16(book.originName + i + bean.title)) + toc.forEachIndexed { index, bookChapter -> + bookChapter.index = index + bookChapter.bookUrl = book.bookUrl + bookChapter.url = MD5Utils.md5Encode16(book.originName + index + bookChapter.title) } book.latestChapterTitle = toc.last().title book.totalChapterNum = toc.size @@ -249,7 +248,7 @@ class TextFile(private val book: Book) { } val chapter = BookChapter() chapter.title = "第${blockPos}章($chapterPos)" - chapter.start = curOffset + chapterOffset + 1 + chapter.start = curOffset + chapterOffset chapter.end = curOffset + end toc.add(chapter) //减去已经被分配的长度 @@ -259,7 +258,7 @@ class TextFile(private val book: Book) { } else { val chapter = BookChapter() chapter.title = "第" + blockPos + "章" + "(" + chapterPos + ")" - chapter.start = curOffset + chapterOffset + 1 + chapter.start = curOffset + chapterOffset chapter.end = curOffset + length toc.add(chapter) strLength = 0 @@ -271,11 +270,10 @@ class TextFile(private val book: Book) { } } - for (i in toc.indices) { - val bean = toc[i] - bean.index = i - bean.bookUrl = book.bookUrl - bean.url = (MD5Utils.md5Encode16(book.originName + i + bean.title)) + toc.forEachIndexed { index, bookChapter -> + bookChapter.index = index + bookChapter.bookUrl = book.bookUrl + bookChapter.url = MD5Utils.md5Encode16(book.originName + index + bookChapter.title) } book.latestChapterTitle = toc.last().title book.totalChapterNum = toc.size @@ -288,8 +286,8 @@ class TextFile(private val book: Book) { } private fun getTocRule(content: String): Pattern? { - tocRules.addAll(getTocRules(content, true)) - tocRules.addAll(getTocRules(content, false)) + tocRules.addAll(getTocRules(content, getTocRules().reversed())) + tocRules.addAll(getTocRules(content, appDb.txtTocRuleDao.disabled.reversed())) return tocRules.firstOrNull() } @@ -298,13 +296,8 @@ class TextFile(private val book: Book) { return tocRules.firstOrNull() } - private fun getTocRules(content: String, isMain: Boolean): ArrayList { + private fun getTocRules(content: String, rules: List): ArrayList { val list = arrayListOf() - val rules = if (isMain) { - getTocRules().reversed() - } else { - appDb.txtTocRuleDao.disabled.reversed() - } var maxCs = 0 for (tocRule in rules) { val pattern = Pattern.compile(tocRule.rule, Pattern.MULTILINE)