diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index a56f48168..5a75b9f43 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -196,7 +196,7 @@ object BookHelp { origin: String?, content: String, enableReplace: Boolean - ): String { + ): List { var c = content if (enableReplace) { synchronized(this) { @@ -228,9 +228,6 @@ object BookHelp { } } } - if (!c.substringBefore("\n").contains(title)) { - c = "$title\n$c" - } try { when (AppConfig.chineseConverterType) { 1 -> c = HanLP.convertToSimplifiedChinese(c) @@ -241,8 +238,13 @@ object BookHelp { App.INSTANCE.toast("简繁转换出错") } } - return c - .replace("\\s*\\n+\\s*".toRegex(), "\n${ReadBookConfig.bodyIndent}") - .replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行 + val contents = arrayListOf() + c.split("\n").forEach { + val str = it.replace("^\\s+".toRegex(), "") + if (str.isNotEmpty()) { + contents.add("${ReadBookConfig.bodyIndent}str") + } + } + return contents } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 89f730ae5..a731a1c1c 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -293,7 +293,7 @@ object ReadBook { ) { Coroutine.async { if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { - val c = BookHelp.disposeContent( + val contents = BookHelp.disposeContent( chapter.title, book!!.name, webBook?.bookSource?.bookSourceUrl, @@ -302,18 +302,21 @@ object ReadBook { ) when (chapter.index) { durChapterIndex -> { - curTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize) + curTextChapter = + ChapterProvider.getTextChapter(chapter, contents, chapterSize) if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset) callBack?.upView() curPageChanged() callBack?.contentLoadFinish() } durChapterIndex - 1 -> { - prevTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize) + prevTextChapter = + ChapterProvider.getTextChapter(chapter, contents, chapterSize) if (upContent) callBack?.upContent(-1, resetPageOffset) } durChapterIndex + 1 -> { - nextTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize) + nextTextChapter = + ChapterProvider.getTextChapter(chapter, contents, chapterSize) if (upContent) callBack?.upContent(1, resetPageOffset) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index ea0a1bd37..61d5a438f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -44,14 +44,13 @@ object ChapterProvider { */ fun getTextChapter( bookChapter: BookChapter, - content: String, + contents: List, chapterSize: Int ): TextChapter { val textPages = arrayListOf() val pageLines = arrayListOf() val pageLengths = arrayListOf() val stringBuilder = StringBuilder() - val contents = content.split("\n") var durY = 0f textPages.add(TextPage()) for ((index, text) in contents.withIndex()) {