From 7ede071d5c9bae562e6a7d80a6ac18ae5c37af23 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 21 Jul 2021 21:37:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=A7=A3=E5=86=B3ChapterProv?= =?UTF-8?q?ider=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ContentHelp.kt | 8 +-- .../io/legado/app/help/ContentProcessor.kt | 12 ++--- .../read/page/provider/ChapterProvider.kt | 49 ++++++++++++------- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ContentHelp.kt b/app/src/main/java/io/legado/app/help/ContentHelp.kt index 70b4cb634..b31580cbd 100644 --- a/app/src/main/java/io/legado/app/help/ContentHelp.kt +++ b/app/src/main/java/io/legado/app/help/ContentHelp.kt @@ -36,7 +36,7 @@ object ContentHelp { //如果原文存在分段错误,需要把段落重新黏合 for (i in 1 until p.size) { if (match(MARK_SENTENCES_END, buffer[buffer.length - 1])) buffer.append("\n") - // 段落开头以外的地方不应该有空格 + // 段落开头以外的地方不应该有空格 // 去除段落内空格。unicode 3000 象形字间隔(中日韩符号和标点),不包含在\s内 buffer.append(p[i].replace("[\u3000\\s]".toRegex(), "")) } @@ -51,7 +51,7 @@ object ContentHelp { .replace( "([问说喊唱叫骂道着答])[\\.。]".toRegex(), "$1。\n" - ) // .replaceAll("([\\.。\\!!??])([^\"”“]+)[::][\"”“]", "$1\n$2:“") + ) .split("\n".toRegex()).toTypedArray() buffer = StringBuffer((content1.length * 1.15).toInt()) for (s in p) { @@ -101,9 +101,9 @@ object ContentHelp { for (i in 0 until l) { string.append('\n') string.append(p[i]) - // System.out.print(" "+b[i]); + //System.out.print(" "+b[i]); } - // System.out.println(" " + str); + //System.out.println(" " + str); return string } diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 5dbb39297..ac1521ea3 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -84,15 +84,15 @@ class ContentProcessor private constructor( } } val contents = arrayListOf() - content1.split("\n").forEach { - val str = it.replace("^[\\n\\r]+".toRegex(), "").trim() + content1.split("\n").forEach { str -> + val paragraph = str.replace("^[\\n\\r]+".toRegex(), "").trim() if (contents.isEmpty()) { contents.add(title) - if (str != title && str.isNotEmpty()) { - contents.add("${ReadBookConfig.paragraphIndent}$str") + if (paragraph != title && paragraph.isNotEmpty()) { + contents.add("${ReadBookConfig.paragraphIndent}$paragraph") } - } else if (str.isNotEmpty()) { - contents.add("${ReadBookConfig.paragraphIndent}$str") + } else if (paragraph.isNotEmpty()) { + contents.add("${ReadBookConfig.paragraphIndent}$paragraph") } } return contents diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 740f36c6f..9f3b17088 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -111,26 +111,39 @@ object ChapterProvider { ) } } else if (book.getImageStyle() != Book.imgStyleText) { - content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n").split("\n") - .forEach { text -> - if (text.isNotBlank()) { - if (!text.startsWith("