优化
This commit is contained in:
@@ -22,6 +22,7 @@ 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.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.MangaContentData
|
||||||
import io.legado.app.ui.book.manga.entities.ReaderLoading
|
import io.legado.app.ui.book.manga.entities.ReaderLoading
|
||||||
import io.legado.app.utils.NetworkUtils
|
import io.legado.app.utils.NetworkUtils
|
||||||
import io.legado.app.utils.mapIndexed
|
import io.legado.app.utils.mapIndexed
|
||||||
@@ -99,6 +100,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
if (durChapterIndex != book.durChapterIndex || tocChanged) {
|
if (durChapterIndex != book.durChapterIndex || tocChanged) {
|
||||||
durChapterIndex = book.durChapterIndex
|
durChapterIndex = book.durChapterIndex
|
||||||
durChapterPos = book.durChapterPos
|
durChapterPos = book.durChapterPos
|
||||||
|
clearMangaChapter()
|
||||||
}
|
}
|
||||||
upWebBook(book)
|
upWebBook(book)
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
@@ -201,7 +203,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
if (curMangaChapter == null) {
|
if (curMangaChapter == null) {
|
||||||
loadContent(durChapterIndex)
|
loadContent(durChapterIndex)
|
||||||
} else {
|
} else {
|
||||||
mCallback?.upContent(true)
|
mCallback?.upContent()
|
||||||
}
|
}
|
||||||
if (nextMangaChapter == null) {
|
if (nextMangaChapter == null) {
|
||||||
loadContent(durChapterIndex + 1)
|
loadContent(durChapterIndex + 1)
|
||||||
@@ -259,7 +261,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
}
|
}
|
||||||
durChapterImageCount = mangaChapter.imageCount
|
durChapterImageCount = mangaChapter.imageCount
|
||||||
curMangaChapter = mangaChapter
|
curMangaChapter = mangaChapter
|
||||||
mCallback?.upContent(true)
|
mCallback?.upContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
-1, 1 -> {
|
-1, 1 -> {
|
||||||
@@ -281,7 +283,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildContentList(): Pair<Int, List<Any>> {
|
private fun buildContentList(): MangaContentData {
|
||||||
val list = arrayListOf<Any>()
|
val list = arrayListOf<Any>()
|
||||||
var pos = durChapterPos + 1
|
var pos = durChapterPos + 1
|
||||||
prevMangaChapter?.let {
|
prevMangaChapter?.let {
|
||||||
@@ -294,7 +296,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
nextMangaChapter?.let {
|
nextMangaChapter?.let {
|
||||||
list.addAll(it.contents)
|
list.addAll(it.contents)
|
||||||
}
|
}
|
||||||
return pos to list
|
return MangaContentData(pos, list, curMangaChapter != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,7 +312,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
startLoad.invoke()
|
startLoad.invoke()
|
||||||
loadContent(durChapterIndex)
|
loadContent(durChapterIndex)
|
||||||
} else {
|
} else {
|
||||||
mCallback?.upContent(true)
|
mCallback?.upContent()
|
||||||
}
|
}
|
||||||
loadContent(durChapterIndex + 1)
|
loadContent(durChapterIndex + 1)
|
||||||
saveRead()
|
saveRead()
|
||||||
@@ -332,7 +334,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
if (curMangaChapter == null) {
|
if (curMangaChapter == null) {
|
||||||
loadContent(durChapterIndex)
|
loadContent(durChapterIndex)
|
||||||
} else {
|
} else {
|
||||||
mCallback?.upContent(true)
|
mCallback?.upContent()
|
||||||
}
|
}
|
||||||
loadContent(durChapterIndex - 1)
|
loadContent(durChapterIndex - 1)
|
||||||
saveRead()
|
saveRead()
|
||||||
@@ -500,7 +502,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
mCallback?.showLoading()
|
mCallback?.showLoading()
|
||||||
if (progress.durChapterIndex == durChapterIndex) {
|
if (progress.durChapterIndex == durChapterIndex) {
|
||||||
durChapterPos = progress.durChapterPos
|
durChapterPos = progress.durChapterPos
|
||||||
mCallback?.upContent(true)
|
mCallback?.upContent()
|
||||||
} else {
|
} else {
|
||||||
durChapterIndex = progress.durChapterIndex
|
durChapterIndex = progress.durChapterIndex
|
||||||
durChapterPos = progress.durChapterPos
|
durChapterPos = progress.durChapterPos
|
||||||
@@ -567,7 +569,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Callback {
|
interface Callback {
|
||||||
fun upContent(finish: Boolean = false)
|
fun upContent()
|
||||||
fun loadFail(msg: String)
|
fun loadFail(msg: String)
|
||||||
fun sureNewProgress(progress: BookProgress)
|
fun sureNewProgress(progress: BookProgress)
|
||||||
fun showLoading()
|
fun showLoading()
|
||||||
|
|||||||
@@ -255,10 +255,13 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
|||||||
justInitData = true
|
justInitData = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun upContent(finish: Boolean) {
|
override fun upContent() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
setTitle(ReadManga.book?.name)
|
setTitle(ReadManga.book?.name)
|
||||||
val (pos, list) = withContext(IO) { ReadManga.mangaContents }
|
val data = withContext(IO) { ReadManga.mangaContents }
|
||||||
|
val pos = data.pos
|
||||||
|
val list = data.contents
|
||||||
|
val finish = data.finish
|
||||||
mAdapter.submitList(list) {
|
mAdapter.submitList(list) {
|
||||||
if (loadingViewVisible && finish) {
|
if (loadingViewVisible && finish) {
|
||||||
binding.infobar.isVisible = true
|
binding.infobar.isVisible = true
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.legado.app.ui.book.manga.entities
|
||||||
|
|
||||||
|
data class MangaContentData(
|
||||||
|
val pos: Int,
|
||||||
|
val contents: List<Any>,
|
||||||
|
val finish: Boolean
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user