From 55e8af89af3f399067080a46cea659c549271af2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 17 Feb 2022 12:25: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 | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 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 40659242f..9b06dd5d0 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 @@ -151,17 +151,25 @@ class TextFile(private val book: Book) { val chapterContent = blockContent.substring(seekPos, chapterStart) val chapterLength = chapterContent.toByteArray(charset).size val lastStart = toc.lastOrNull()?.start ?: curOffset - if (book.getSplitLongChapter() && curOffset + chapterLength - lastStart > maxLengthWithToc) { + if (book.getSplitLongChapter() + && curOffset + chapterLength - lastStart > maxLengthWithToc + ) { toc.lastOrNull()?.let { it.end = it.start } //章节字数太多进行拆分 - toc.addAll( - analyze( - lastStart + matcher.group().length, - curOffset + chapterLength - ) + val lastTitle = toc.lastOrNull()?.title + val lastTitleLength = lastTitle?.toByteArray(charset)?.size ?: 0 + val chapters = analyze( + lastStart + lastTitleLength, + curOffset + chapterLength ) + lastTitle?.let { + chapters.forEachIndexed { index, bookChapter -> + bookChapter.title = "$lastTitle(${index + 1})" + } + } + toc.addAll(chapters) //创建当前章节 val curChapter = BookChapter() curChapter.title = matcher.group() @@ -189,7 +197,7 @@ class TextFile(private val book: Book) { } else { //否则就block分割之后,上一个章节的剩余内容 //获取上一章节 val lastChapter = toc.last() - toc.last().isVolume = + lastChapter.isVolume = chapterContent.substringAfter(lastChapter.title).isBlank() //将当前段落添加上一章去 lastChapter.end =