This commit is contained in:
Horis
2025-03-07 14:36:19 +08:00
parent 570c01785c
commit d6ecfb6fea
6 changed files with 26 additions and 51 deletions
@@ -44,7 +44,6 @@ import kotlin.math.min
object ReadManga : CoroutineScope by MainScope() { object ReadManga : CoroutineScope by MainScope() {
var inBookshelf = false var inBookshelf = false
var tocChanged = false var tocChanged = false
var chapterChanged = false
var book: Book? = null var book: Book? = null
val executor = globalExecutor val executor = globalExecutor
var durChapterIndex = 0 //章节位置 var durChapterIndex = 0 //章节位置
@@ -213,9 +212,6 @@ object ReadManga : CoroutineScope by MainScope() {
} }
fun loadContent(index: Int) { fun loadContent(index: Int) {
if (chapterChanged) {
removeLoading(index)
}
if (addLoading(index)) { if (addLoading(index)) {
Coroutine.async { Coroutine.async {
val book = book!! val book = book!!
@@ -501,10 +497,10 @@ object ReadManga : CoroutineScope by MainScope() {
(durChapterIndex != progress.durChapterIndex (durChapterIndex != progress.durChapterIndex
|| durChapterPos != progress.durChapterPos) || durChapterPos != progress.durChapterPos)
) { ) {
chapterChanged = true mCallback?.showLoading()
if (progress.durChapterIndex == durChapterIndex) { if (progress.durChapterIndex == durChapterIndex) {
durChapterPos = progress.durChapterPos durChapterPos = progress.durChapterPos
mCallback?.adjustProgress() mCallback?.upContent(true)
} else { } else {
durChapterIndex = progress.durChapterIndex durChapterIndex = progress.durChapterIndex
durChapterPos = progress.durChapterPos durChapterPos = progress.durChapterPos
@@ -514,6 +510,10 @@ object ReadManga : CoroutineScope by MainScope() {
} }
} }
fun showLoading() {
mCallback?.showLoading()
}
/** /**
* 注册回调 * 注册回调
*/ */
@@ -544,11 +544,10 @@ object ReadManga : CoroutineScope by MainScope() {
} }
}.distinctUntilChanged().mapIndexed { index, src -> }.distinctUntilChanged().mapIndexed { index, src ->
MangaContent( MangaContent(
chapterSize = chapterSize,
mChapterIndex = chapter.index, mChapterIndex = chapter.index,
nextChapterIndex = chapter.index.plus(1), chapterSize = chapterSize,
mImageUrl = src, mImageUrl = src,
mDurChapterPos = index, index = index,
mChapterName = chapter.title mChapterName = chapter.title
) )
}.toList() }.toList()
@@ -556,25 +555,13 @@ object ReadManga : CoroutineScope by MainScope() {
val imageCount = list.size val imageCount = list.size
list.forEach { list.forEach {
it.mDurChapterImageCount = imageCount it.imageCount = imageCount
} }
val contentList = mutableListOf<Any>() val contentList = mutableListOf<Any>()
contentList.add( contentList.add(ReaderLoading(chapter.index, "阅读 ${chapter.title}"))
ReaderLoading(
chapter.index,
"阅读 ${chapter.title}",
mNextChapterIndex = chapter.index.plus(1)
)
)
contentList.addAll(list) contentList.addAll(list)
contentList.add( contentList.add(ReaderLoading(chapter.index, "已读完 ${chapter.title}"))
ReaderLoading(
chapter.index,
"已读完 ${chapter.title}",
mNextChapterIndex = chapter.index.plus(1)
)
)
return MangaChapter(chapter, contentList, imageCount) return MangaChapter(chapter, contentList, imageCount)
} }
@@ -582,7 +569,7 @@ object ReadManga : CoroutineScope by MainScope() {
interface Callback { interface Callback {
fun upContent(finish: Boolean = false) fun upContent(finish: Boolean = false)
fun loadFail(msg: String) fun loadFail(msg: String)
fun adjustProgress()
fun sureNewProgress(progress: BookProgress) fun sureNewProgress(progress: BookProgress)
fun showLoading()
} }
} }
@@ -130,7 +130,6 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
//打开目录返回选择章节返回结果 //打开目录返回选择章节返回结果
private val tocActivity = registerForActivityResult(TocActivityResult()) { private val tocActivity = registerForActivityResult(TocActivityResult()) {
it?.let { it?.let {
binding.flLoading.isVisible = true
viewModel.openChapter(it.first, it.second) viewModel.openChapter(it.first, it.second)
} }
} }
@@ -214,14 +213,14 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
} else if (ReadManga.durChapterIndex > content.mChapterIndex) { } else if (ReadManga.durChapterIndex > content.mChapterIndex) {
ReadManga.moveToPrevChapter() ReadManga.moveToPrevChapter()
} else { } else {
ReadManga.durChapterPos = content.mDurChapterPos ReadManga.durChapterPos = content.index
ReadManga.curPageChanged() ReadManga.curPageChanged()
} }
upInfoBar( upInfoBar(
content.mChapterIndex, content.mChapterIndex,
content.chapterSize, content.chapterSize,
content.mDurChapterPos, content.index,
content.mDurChapterImageCount, content.imageCount,
content.mChapterName content.mChapterName
) )
} }
@@ -281,12 +280,6 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
loadMoreView.noMore("暂无章节了!") loadMoreView.noMore("暂无章节了!")
} }
} }
if (ReadManga.chapterChanged) {
binding.mRecyclerManga.scrollToPosition(pos)
}
ReadManga.chapterChanged = false
} }
} }
} }
@@ -388,13 +381,6 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
} }
} }
override fun adjustProgress() {
if (ReadManga.chapterChanged) {
binding.mRecyclerManga.scrollToPosition(ReadManga.durChapterPos)
binding.flLoading.isGone = true
}
}
override fun onDestroy() { override fun onDestroy() {
ReadManga.unregister(this) ReadManga.unregister(this)
super.onDestroy() super.onDestroy()
@@ -410,20 +396,24 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
syncDialog = alert(R.string.get_book_progress) { syncDialog = alert(R.string.get_book_progress) {
setMessage(R.string.cloud_progress_exceeds_current) setMessage(R.string.cloud_progress_exceeds_current)
okButton { okButton {
binding.flLoading.isVisible = true
ReadManga.setProgress(progress) ReadManga.setProgress(progress)
} }
noButton() noButton()
} }
} }
override fun showLoading() {
lifecycleScope.launch {
binding.flLoading.isVisible = true
}
}
override val oldBook: Book? override val oldBook: Book?
get() = ReadManga.book get() = ReadManga.book
override fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) { override fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
if (book.isImage) { if (book.isImage) {
binding.flLoading.isVisible = true binding.flLoading.isVisible = true
ReadManga.chapterChanged = true
viewModel.changeTo(book, toc) viewModel.changeTo(book, toc)
} else { } else {
toastOnUi("所选择的源不是漫画源") toastOnUi("所选择的源不是漫画源")
@@ -225,7 +225,7 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
fun openChapter(index: Int, durChapterPos: Int = 0) { fun openChapter(index: Int, durChapterPos: Int = 0) {
if (index < ReadManga.chapterSize) { if (index < ReadManga.chapterSize) {
ReadManga.chapterChanged = true ReadManga.showLoading()
ReadManga.durChapterIndex = index ReadManga.durChapterIndex = index
ReadManga.durChapterPos = durChapterPos ReadManga.durChapterPos = durChapterPos
ReadManga.saveRead() ReadManga.saveRead()
@@ -3,9 +3,8 @@ package io.legado.app.ui.book.manga.entities
data class MangaContent( data class MangaContent(
var mChapterIndex: Int = 0,//总章节位置 var mChapterIndex: Int = 0,//总章节位置
var chapterSize: Int,//总章节数量 var chapterSize: Int,//总章节数量
var nextChapterIndex: Int = 0,//下一章
val mImageUrl: String = "",//当前URL val mImageUrl: String = "",//当前URL
var mDurChapterPos: Int = 0,//当前章节位置 var index: Int = 0,//当前章节位置
var mDurChapterImageCount: Int = 0,//当前章节内容总数 var imageCount: Int = 0,//当前章节内容总数
var mChapterName: String = "",//章节名称 var mChapterName: String = "",//章节名称
) )
@@ -3,6 +3,5 @@ package io.legado.app.ui.book.manga.entities
data class ReaderLoading( data class ReaderLoading(
val mChapterIndex: Int = 0, val mChapterIndex: Int = 0,
val mMessage: String? = null, val mMessage: String? = null,
val mNextChapterIndex: Int = 0,
var mLoading: Boolean = false, var mLoading: Boolean = false,
) )
@@ -88,14 +88,14 @@ class MangaAdapter(private val context: Context) :
val item = mDiffer.currentList[layoutPosition] val item = mDiffer.currentList[layoutPosition]
if (item is MangaContent) { if (item is MangaContent) {
loadImageWithRetry( loadImageWithRetry(
item.mImageUrl, isHorizontal, item.mDurChapterImageCount == 1 item.mImageUrl, isHorizontal, item.imageCount == 1
) )
} }
} }
} }
fun onBind(item: MangaContent) { fun onBind(item: MangaContent) {
loadImageWithRetry(item.mImageUrl, isHorizontal, item.mDurChapterImageCount == 1) loadImageWithRetry(item.mImageUrl, isHorizontal, item.imageCount == 1)
} }
} }