优化
This commit is contained in:
@@ -20,6 +20,7 @@ import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.help.globalExecutor
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.ui.book.manga.entities.BaseMangaPage
|
||||
import io.legado.app.ui.book.manga.entities.MangaChapter
|
||||
import io.legado.app.ui.book.manga.entities.MangaContent
|
||||
import io.legado.app.ui.book.manga.entities.MangaPage
|
||||
@@ -239,24 +240,25 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
}
|
||||
|
||||
private fun buildMangaContent(): MangaContent {
|
||||
val list = arrayListOf<Any>()
|
||||
var pos = durChapterPos + 1
|
||||
val items = arrayListOf<BaseMangaPage>()
|
||||
var pos = 0
|
||||
var curFinish = false
|
||||
var nextFinish = false
|
||||
prevMangaChapter?.let {
|
||||
pos += it.contents.size
|
||||
list.addAll(it.contents)
|
||||
pos += it.pages.size
|
||||
items.addAll(it.pages)
|
||||
}
|
||||
curMangaChapter?.let {
|
||||
curFinish = true
|
||||
list.addAll(it.contents)
|
||||
items.addAll(it.pages)
|
||||
durChapterPos = durChapterPos.coerceIn(0, it.imageCount - 1)
|
||||
pos += durChapterPos + 1
|
||||
}
|
||||
nextMangaChapter?.let {
|
||||
nextFinish = true
|
||||
list.addAll(it.contents)
|
||||
items.addAll(it.pages)
|
||||
}
|
||||
pos = pos.coerceIn(0, list.lastIndex)
|
||||
return MangaContent(pos, list, curFinish, nextFinish)
|
||||
return MangaContent(pos, items, curFinish, nextFinish)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -586,7 +588,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
it.imageCount = imageCount
|
||||
}
|
||||
|
||||
val contentList = mutableListOf<Any>()
|
||||
val contentList = mutableListOf<BaseMangaPage>()
|
||||
contentList.add(ReaderLoading(chapter.index, -1, "阅读 ${chapter.title}"))
|
||||
contentList.addAll(list)
|
||||
contentList.add(ReaderLoading(chapter.index, imageCount, "已读完 ${chapter.title}"))
|
||||
|
||||
@@ -261,7 +261,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
||||
setTitle(ReadManga.book?.name)
|
||||
val data = withContext(IO) { ReadManga.mangaContents }
|
||||
val pos = data.pos
|
||||
val list = data.contents
|
||||
val list = data.items
|
||||
val curFinish = data.curFinish
|
||||
val nextFinish = data.nextFinish
|
||||
mAdapter.submitList(list) {
|
||||
@@ -737,9 +737,9 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
||||
window.decorView.postInvalidate()
|
||||
}
|
||||
|
||||
override fun skipToPage(pos: Int) {
|
||||
override fun skipToPage(index: Int) {
|
||||
val durChapterIndex = ReadManga.durChapterIndex
|
||||
val pos = mAdapter.getItems().fastBinarySearch {
|
||||
val itemPos = mAdapter.getItems().fastBinarySearch {
|
||||
val chapterIndex: Int
|
||||
val pageIndex: Int
|
||||
if (it is BaseMangaPage) {
|
||||
@@ -752,12 +752,13 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
||||
if (delta != 0) {
|
||||
delta
|
||||
} else {
|
||||
pageIndex - pos
|
||||
pageIndex - index
|
||||
}
|
||||
}
|
||||
if (pos > -1) {
|
||||
mLayoutManager.scrollToPositionWithOffset(pos, 0)
|
||||
upInfoBar(mAdapter.getItem(pos))
|
||||
if (itemPos > -1) {
|
||||
mLayoutManager.scrollToPositionWithOffset(itemPos, 0)
|
||||
upInfoBar(mAdapter.getItem(itemPos))
|
||||
ReadManga.durChapterPos = index
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import io.legado.app.data.entities.BookChapter
|
||||
|
||||
data class MangaChapter(
|
||||
val chapter: BookChapter,
|
||||
val contents: List<Any>,
|
||||
val pages: List<BaseMangaPage>,
|
||||
val imageCount: Int
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.legado.app.ui.book.manga.entities
|
||||
|
||||
data class MangaContent(
|
||||
val pos: Int,
|
||||
val contents: List<Any>,
|
||||
val items: List<Any>,
|
||||
val curFinish: Boolean,
|
||||
val nextFinish: Boolean
|
||||
)
|
||||
|
||||
@@ -804,7 +804,11 @@ class TextChapterLayout(
|
||||
while (i < length) {
|
||||
val clusterBaseIndex = i++
|
||||
widths.add(widthsArray[start + clusterBaseIndex])
|
||||
while (i < length && widthsArray[start + i] == 0f && !isZeroWidthChar(text[i])) {
|
||||
while (i < length) {
|
||||
val c = text[i]
|
||||
if ((widthsArray[start + i] > 0 && !c.isLowSurrogate()) || isZeroWidthChar(c)) {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
stringList.add(text.substring(clusterBaseIndex, i))
|
||||
@@ -814,7 +818,7 @@ class TextChapterLayout(
|
||||
|
||||
private fun isZeroWidthChar(char: Char): Boolean {
|
||||
val code = char.code
|
||||
return code == 8203 || code == 8204 || code == 8288
|
||||
return code == 8203 || code == 8204 || code == 8205 || code == 8288
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user