From 426e09c457f8682765f267cfa54e05d749e16a0d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 16 Feb 2022 15:07:54 +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 | 23 +++++++++++++------ 1 file changed, 16 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 0697aeac9..8985d324d 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 @@ -149,11 +149,20 @@ class TextFile(private val book: Book) { val chapterLength = chapterContent.toByteArray(charset).size val lastStart = toc.lastOrNull()?.start ?: curOffset if (curOffset + chapterLength - lastStart > maxLengthWithToc) { + toc.lastOrNull()?.let { + it.end = it.start + } toc.addAll(analyze(lastStart, curOffset + chapterLength)) - } - //如果 seekPos == 0 && chapterStart != 0 表示当前block处前面有一段内容 - //第一种情况一定是序章 第二种情况是上一个章节的内容 - if (seekPos == 0 && chapterStart != 0) { //获取当前章节的内容 + //创建当前章节 + val curChapter = BookChapter() + curChapter.title = matcher.group() + curChapter.start = curOffset + chapterLength + toc.add(curChapter) + } else if (seekPos == 0 && chapterStart != 0) { + /* + * 如果 seekPos == 0 && chapterStart != 0 表示当前block处前面有一段内容 + * 第一种情况一定是序章 第二种情况是上一个章节的内容 + */ if (toc.isEmpty()) { //如果当前没有章节,那么就是序章 //加入简介 if (StringUtils.trim(chapterContent).isNotEmpty()) { @@ -186,7 +195,7 @@ class TextFile(private val book: Book) { if (toc.isNotEmpty()) { //获取章节内容 //获取上一章节 val lastChapter = toc.last() - toc.last().isVolume = + lastChapter.isVolume = chapterContent.substringAfter(lastChapter.title).isBlank() lastChapter.end = lastChapter.start!! + chapterContent.toByteArray(charset).size.toLong() @@ -264,7 +273,7 @@ class TextFile(private val book: Book) { //分章的位置 chapterPos = 0 while (strLength > 0) { - ++chapterPos + chapterPos++ //是否长度超过一章 if (strLength > maxLengthWithNoToc) { //在buffer中一章的终止点 var end = length @@ -297,7 +306,7 @@ class TextFile(private val book: Book) { //设置结尾章节 if (bufferStart > 100) { val chapter = BookChapter() - chapter.title = "第${blockPos}章(${chapterPos + 1})" + chapter.title = "第${blockPos}章(${chapterPos})" chapter.start = toc.lastOrNull()?.end ?: curOffset chapter.end = chapter.start!! + bufferStart toc.add(chapter)