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