feat: 优化代码

pull/198/head
kunfei 5 years ago
parent fcc7761320
commit 15c87eb6fa
  1. 25
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt

@ -82,26 +82,17 @@ object AnalyzeTxtFile {
val curChapter = BookChapter() val curChapter = BookChapter()
curChapter.title = matcher.group() curChapter.title = matcher.group()
curChapter.start = chapter.end curChapter.start = chapter.end
curChapter.end = chapter.end
toc.add(curChapter) toc.add(curChapter)
} else { } else {
if (toc.size != 0) { val lastChapter = toc.lastOrNull()
//获取上一章节 lastChapter?.let {
val lastChapter = toc.last() //上一章节结束等于这一章节开始
lastChapter.end = it.end = it.start!! + chapterContent.toByteArray(charset).size
lastChapter.start!! + chapterContent.toByteArray(charset).size
//创建当前章节
val curChapter = BookChapter()
curChapter.title = matcher.group()
curChapter.start = lastChapter.end
toc.add(curChapter)
} else { //如果章节不存在则创建章节
val curChapter = BookChapter()
curChapter.title = matcher.group()
curChapter.start = 0L
curChapter.end = 0L
toc.add(curChapter)
} }
//创建当前章节
val curChapter = BookChapter()
curChapter.title = matcher.group()
curChapter.start = lastChapter?.end ?: 0
} }
//设置指针偏移 //设置指针偏移
seekPos += chapterContent.length seekPos += chapterContent.length

Loading…
Cancel
Save