From b6f7f48b2fb6815a4c6ae47ed23a9f9d25309e79 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 26 Mar 2020 19:03:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/localBook/AnalyzeTxtFile.kt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 96de16e8c..3776924ba 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -86,16 +86,25 @@ class AnalyzeTxtFile { } //如果 seekPos == 0 && nextChapterPos != 0 表示当前block处前面有一段内容 //第一种情况一定是序章 第二种情况可能是上一个章节的内容 - if (seekPos == 0 && chapterStart != 0 && toc.isEmpty()) { //获取当前章节的内容 - val chapter = BookChapter() - chapter.title = "前言" - chapter.start = 0 - chapter.end = chapterContent.toByteArray(charset).size.toLong() - toc.add(chapter) + if (seekPos == 0 && chapterStart != 0) { //获取当前章节的内容 + val contentSize = chapterContent.toByteArray(charset).size.toLong() + if (toc.isEmpty()) { + if (StringUtils.trim(chapterContent).isNotEmpty()) { + val chapter = BookChapter() + chapter.title = "前言" + chapter.start = 0 + chapter.end = contentSize + toc.add(chapter) + } + } else { + toc.last().let { + it.end = it.end!! + contentSize + } + } //创建当前章节 val curChapter = BookChapter() curChapter.title = matcher.group() - curChapter.start = chapter.end + curChapter.start = (toc.lastOrNull()?.end ?: 0) + contentSize toc.add(curChapter) } else { val lastChapter = toc.lastOrNull()