优化
This commit is contained in:
@@ -21,7 +21,7 @@ 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.MangaChapter
|
import io.legado.app.ui.book.manga.entities.MangaChapter
|
||||||
import io.legado.app.ui.book.manga.entities.MangaContentData
|
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
|
||||||
import io.legado.app.ui.book.manga.entities.ReaderLoading
|
import io.legado.app.ui.book.manga.entities.ReaderLoading
|
||||||
import io.legado.app.utils.mapIndexed
|
import io.legado.app.utils.mapIndexed
|
||||||
@@ -48,7 +48,6 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
val executor = globalExecutor
|
val executor = globalExecutor
|
||||||
var durChapterIndex = 0 //章节位置
|
var durChapterIndex = 0 //章节位置
|
||||||
var chapterSize = 0//总章节
|
var chapterSize = 0//总章节
|
||||||
var durChapterImageCount = 0
|
|
||||||
var durChapterPos = 0
|
var durChapterPos = 0
|
||||||
var prevMangaChapter: MangaChapter? = null
|
var prevMangaChapter: MangaChapter? = null
|
||||||
var curMangaChapter: MangaChapter? = null
|
var curMangaChapter: MangaChapter? = null
|
||||||
@@ -65,7 +64,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
||||||
val preDownloadSemaphore = Semaphore(2)
|
val preDownloadSemaphore = Semaphore(2)
|
||||||
var rateLimiter = ConcurrentRateLimiter(null)
|
var rateLimiter = ConcurrentRateLimiter(null)
|
||||||
val mangaContents get() = buildContentList()
|
val mangaContents get() = buildMangaContent()
|
||||||
val hasNextChapter get() = durChapterIndex < simulatedChapterSize - 1
|
val hasNextChapter get() = durChapterIndex < simulatedChapterSize - 1
|
||||||
|
|
||||||
fun resetData(book: Book) {
|
fun resetData(book: Book) {
|
||||||
@@ -216,7 +215,6 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
mCallback?.loadFail("正文没有图片")
|
mCallback?.loadFail("正文没有图片")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
durChapterImageCount = mangaChapter.imageCount
|
|
||||||
curMangaChapter = mangaChapter
|
curMangaChapter = mangaChapter
|
||||||
mCallback?.upContent()
|
mCallback?.upContent()
|
||||||
}
|
}
|
||||||
@@ -240,20 +238,24 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildContentList(): MangaContentData {
|
private fun buildMangaContent(): MangaContent {
|
||||||
val list = arrayListOf<Any>()
|
val list = arrayListOf<Any>()
|
||||||
var pos = durChapterPos + 1
|
var pos = durChapterPos + 1
|
||||||
|
var curFinish = false
|
||||||
|
var nextFinish = false
|
||||||
prevMangaChapter?.let {
|
prevMangaChapter?.let {
|
||||||
pos += it.contents.size
|
pos += it.contents.size
|
||||||
list.addAll(it.contents)
|
list.addAll(it.contents)
|
||||||
}
|
}
|
||||||
curMangaChapter?.let {
|
curMangaChapter?.let {
|
||||||
|
curFinish = true
|
||||||
list.addAll(it.contents)
|
list.addAll(it.contents)
|
||||||
}
|
}
|
||||||
nextMangaChapter?.let {
|
nextMangaChapter?.let {
|
||||||
|
nextFinish = true
|
||||||
list.addAll(it.contents)
|
list.addAll(it.contents)
|
||||||
}
|
}
|
||||||
return MangaContentData(pos, list, curMangaChapter != null, nextMangaChapter != null)
|
return MangaContent(pos, list, curFinish, nextFinish)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -268,13 +268,15 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
|||||||
val curFinish = data.curFinish
|
val curFinish = data.curFinish
|
||||||
val nextFinish = data.nextFinish
|
val nextFinish = data.nextFinish
|
||||||
mAdapter.submitList(list) {
|
mAdapter.submitList(list) {
|
||||||
binding.mangaMenu.upSeekBar(ReadManga.durChapterPos, ReadManga.durChapterImageCount)
|
|
||||||
if (loadingViewVisible && curFinish) {
|
if (loadingViewVisible && curFinish) {
|
||||||
binding.infobar.isVisible = true
|
binding.infobar.isVisible = true
|
||||||
upInfoBar(list[pos])
|
upInfoBar(list[pos])
|
||||||
binding.mRecyclerManga.scrollToPosition(pos)
|
mLayoutManager.scrollToPositionWithOffset(pos, 0)
|
||||||
binding.flLoading.isGone = true
|
binding.flLoading.isGone = true
|
||||||
loadMoreView.visible()
|
loadMoreView.visible()
|
||||||
|
binding.mangaMenu.upSeekBar(
|
||||||
|
ReadManga.durChapterPos, ReadManga.curMangaChapter!!.imageCount
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curFinish) {
|
if (curFinish) {
|
||||||
@@ -757,7 +759,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos > -1) {
|
if (pos > -1) {
|
||||||
binding.mRecyclerManga.scrollToPosition(pos)
|
mLayoutManager.scrollToPositionWithOffset(pos, 0)
|
||||||
upInfoBar(mAdapter.getItem(pos))
|
upInfoBar(mAdapter.getItem(pos))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package io.legado.app.ui.book.manga.entities
|
package io.legado.app.ui.book.manga.entities
|
||||||
|
|
||||||
data class MangaContentData(
|
data class MangaContent(
|
||||||
val pos: Int,
|
val pos: Int,
|
||||||
val contents: List<Any>,
|
val contents: List<Any>,
|
||||||
val curFinish: Boolean,
|
val curFinish: Boolean,
|
||||||
@@ -243,8 +243,10 @@ class MangaMenu @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener {
|
seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener {
|
||||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||||
callBack.skipToPage(seekBar.progress)
|
if (fromUser) {
|
||||||
|
callBack.skipToPage(seekBar.progress)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user