feat: 优化

pull/201/head
kunfei 5 years ago
parent bf27baccd1
commit 7a4fb24055
  1. 16
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 11
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt

@ -196,7 +196,7 @@ object BookHelp {
origin: String?,
content: String,
enableReplace: Boolean
): String {
): List<String> {
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<String>()
c.split("\n").forEach {
val str = it.replace("^\\s+".toRegex(), "")
if (str.isNotEmpty()) {
contents.add("${ReadBookConfig.bodyIndent}str")
}
}
return contents
}
}

@ -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)
}
}

@ -44,14 +44,13 @@ object ChapterProvider {
*/
fun getTextChapter(
bookChapter: BookChapter,
content: String,
contents: List<String>,
chapterSize: Int
): TextChapter {
val textPages = arrayListOf<TextPage>()
val pageLines = arrayListOf<Int>()
val pageLengths = arrayListOf<Int>()
val stringBuilder = StringBuilder()
val contents = content.split("\n")
var durY = 0f
textPages.add(TextPage())
for ((index, text) in contents.withIndex()) {

Loading…
Cancel
Save