尝试解决ChapterProvider报错

pull/1155/head
gedoor 3 years ago
parent 55efc2e67a
commit 7ede071d5c
  1. 6
      app/src/main/java/io/legado/app/help/ContentHelp.kt
  2. 12
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  3. 23
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -51,7 +51,7 @@ object ContentHelp {
.replace( .replace(
"([问说喊唱叫骂道着答])[\\.。]".toRegex(), "([问说喊唱叫骂道着答])[\\.。]".toRegex(),
"$1。\n" "$1。\n"
) // .replaceAll("([\\.。\\!!??])([^\"”“]+)[::][\"”“]", "$1\n$2:“") )
.split("\n".toRegex()).toTypedArray() .split("\n".toRegex()).toTypedArray()
buffer = StringBuffer((content1.length * 1.15).toInt()) buffer = StringBuffer((content1.length * 1.15).toInt())
for (s in p) { for (s in p) {
@ -101,9 +101,9 @@ object ContentHelp {
for (i in 0 until l) { for (i in 0 until l) {
string.append('\n') string.append('\n')
string.append(p[i]) string.append(p[i])
// System.out.print(" "+b[i]); //System.out.print(" "+b[i]);
} }
// System.out.println(" " + str); //System.out.println(" " + str);
return string return string
} }

@ -84,15 +84,15 @@ class ContentProcessor private constructor(
} }
} }
val contents = arrayListOf<String>() val contents = arrayListOf<String>()
content1.split("\n").forEach { content1.split("\n").forEach { str ->
val str = it.replace("^[\\n\\r]+".toRegex(), "").trim() val paragraph = str.replace("^[\\n\\r]+".toRegex(), "").trim()
if (contents.isEmpty()) { if (contents.isEmpty()) {
contents.add(title) contents.add(title)
if (str != title && str.isNotEmpty()) { if (paragraph != title && paragraph.isNotEmpty()) {
contents.add("${ReadBookConfig.paragraphIndent}$str") contents.add("${ReadBookConfig.paragraphIndent}$paragraph")
} }
} else if (str.isNotEmpty()) { } else if (paragraph.isNotEmpty()) {
contents.add("${ReadBookConfig.paragraphIndent}$str") contents.add("${ReadBookConfig.paragraphIndent}$paragraph")
} }
} }
return contents return contents

@ -111,10 +111,11 @@ object ChapterProvider {
) )
} }
} else if (book.getImageStyle() != Book.imgStyleText) { } else if (book.getImageStyle() != Book.imgStyleText) {
content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n").split("\n") val matcher = AppPattern.imgPattern.matcher(content)
.forEach { text -> var start = 0
while (matcher.find()) {
val text = content.substring(start, matcher.start())
if (text.isNotBlank()) { if (text.isNotBlank()) {
if (!text.startsWith("<img src=\"")) { //非图片
val isTitle = index == 0 val isTitle = index == 0
val textPaint = if (isTitle) titlePaint else contentPaint val textPaint = if (isTitle) titlePaint else contentPaint
if (!(isTitle && ReadBookConfig.titleMode == 2)) { if (!(isTitle && ReadBookConfig.titleMode == 2)) {
@ -123,11 +124,23 @@ object ChapterProvider {
stringBuilder, isTitle, textPaint stringBuilder, isTitle, textPaint
) )
} }
} else { //图片 }
durY = setTypeImage( durY = setTypeImage(
book, bookChapter, text.substring(10, text.length - 2), book, bookChapter, matcher.group(1)!!,
durY, textPages, book.getImageStyle() durY, textPages, book.getImageStyle()
) )
start = matcher.end()
}
if (start < content.length) {
val text = content.substring(start, content.length)
if (text.isNotBlank()) {
val isTitle = index == 0
val textPaint = if (isTitle) titlePaint else contentPaint
if (!(isTitle && ReadBookConfig.titleMode == 2)) {
durY = setTypeText(
text, durY, textPages,
stringBuilder, isTitle, textPaint
)
} }
} }
} }

Loading…
Cancel
Save