优化
Some checks are pending
Test Build / prepare (push) Waiting to run
Test Build / build (app, release) (push) Blocked by required conditions
Test Build / build (app, releaseA) (push) Blocked by required conditions
Test Build / prerelease (push) Blocked by required conditions
Test Build / lanzou (push) Blocked by required conditions
Test Build / test_Branch (push) Blocked by required conditions
Test Build / telegram (push) Blocked by required conditions

This commit is contained in:
Horis
2025-03-07 14:36:19 +08:00
parent 58694b05ef
commit 1a7a3ae3ea
6 changed files with 26 additions and 51 deletions

View File

@@ -44,7 +44,6 @@ import kotlin.math.min
object ReadManga : CoroutineScope by MainScope() {
var inBookshelf = false
var tocChanged = false
var chapterChanged = false
var book: Book? = null
val executor = globalExecutor
var durChapterIndex = 0 //章节位置
@@ -213,9 +212,6 @@ object ReadManga : CoroutineScope by MainScope() {
}
fun loadContent(index: Int) {
if (chapterChanged) {
removeLoading(index)
}
if (addLoading(index)) {
Coroutine.async {
val book = book!!
@@ -501,10 +497,10 @@ object ReadManga : CoroutineScope by MainScope() {
(durChapterIndex != progress.durChapterIndex
|| durChapterPos != progress.durChapterPos)
) {
chapterChanged = true
mCallback?.showLoading()
if (progress.durChapterIndex == durChapterIndex) {
durChapterPos = progress.durChapterPos
mCallback?.adjustProgress()
mCallback?.upContent(true)
} else {
durChapterIndex = progress.durChapterIndex
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 ->
MangaContent(
chapterSize = chapterSize,
mChapterIndex = chapter.index,
nextChapterIndex = chapter.index.plus(1),
chapterSize = chapterSize,
mImageUrl = src,
mDurChapterPos = index,
index = index,
mChapterName = chapter.title
)
}.toList()
@@ -556,25 +555,13 @@ object ReadManga : CoroutineScope by MainScope() {
val imageCount = list.size
list.forEach {
it.mDurChapterImageCount = imageCount
it.imageCount = imageCount
}
val contentList = mutableListOf<Any>()
contentList.add(
ReaderLoading(
chapter.index,
"阅读 ${chapter.title}",
mNextChapterIndex = chapter.index.plus(1)
)
)
contentList.add(ReaderLoading(chapter.index, "阅读 ${chapter.title}"))
contentList.addAll(list)
contentList.add(
ReaderLoading(
chapter.index,
"已读完 ${chapter.title}",
mNextChapterIndex = chapter.index.plus(1)
)
)
contentList.add(ReaderLoading(chapter.index, "已读完 ${chapter.title}"))
return MangaChapter(chapter, contentList, imageCount)
}
@@ -582,7 +569,7 @@ object ReadManga : CoroutineScope by MainScope() {
interface Callback {
fun upContent(finish: Boolean = false)
fun loadFail(msg: String)
fun adjustProgress()
fun sureNewProgress(progress: BookProgress)
fun showLoading()
}
}

View File

@@ -130,7 +130,6 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
//打开目录返回选择章节返回结果
private val tocActivity = registerForActivityResult(TocActivityResult()) {
it?.let {
binding.flLoading.isVisible = true
viewModel.openChapter(it.first, it.second)
}
}
@@ -214,14 +213,14 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
} else if (ReadManga.durChapterIndex > content.mChapterIndex) {
ReadManga.moveToPrevChapter()
} else {
ReadManga.durChapterPos = content.mDurChapterPos
ReadManga.durChapterPos = content.index
ReadManga.curPageChanged()
}
upInfoBar(
content.mChapterIndex,
content.chapterSize,
content.mDurChapterPos,
content.mDurChapterImageCount,
content.index,
content.imageCount,
content.mChapterName
)
}
@@ -281,12 +280,6 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
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() {
ReadManga.unregister(this)
super.onDestroy()
@@ -410,20 +396,24 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
syncDialog = alert(R.string.get_book_progress) {
setMessage(R.string.cloud_progress_exceeds_current)
okButton {
binding.flLoading.isVisible = true
ReadManga.setProgress(progress)
}
noButton()
}
}
override fun showLoading() {
lifecycleScope.launch {
binding.flLoading.isVisible = true
}
}
override val oldBook: Book?
get() = ReadManga.book
override fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
if (book.isImage) {
binding.flLoading.isVisible = true
ReadManga.chapterChanged = true
viewModel.changeTo(book, toc)
} else {
toastOnUi("所选择的源不是漫画源")

View File

@@ -225,7 +225,7 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
fun openChapter(index: Int, durChapterPos: Int = 0) {
if (index < ReadManga.chapterSize) {
ReadManga.chapterChanged = true
ReadManga.showLoading()
ReadManga.durChapterIndex = index
ReadManga.durChapterPos = durChapterPos
ReadManga.saveRead()

View File

@@ -3,9 +3,8 @@ package io.legado.app.ui.book.manga.entities
data class MangaContent(
var mChapterIndex: Int = 0,//总章节位置
var chapterSize: Int,//总章节数量
var nextChapterIndex: Int = 0,//下一章
val mImageUrl: String = "",//当前URL
var mDurChapterPos: Int = 0,//当前章节位置
var mDurChapterImageCount: Int = 0,//当前章节内容总数
var index: Int = 0,//当前章节位置
var imageCount: Int = 0,//当前章节内容总数
var mChapterName: String = "",//章节名称
)

View File

@@ -3,6 +3,5 @@ package io.legado.app.ui.book.manga.entities
data class ReaderLoading(
val mChapterIndex: Int = 0,
val mMessage: String? = null,
val mNextChapterIndex: Int = 0,
var mLoading: Boolean = false,
)

View File

@@ -88,14 +88,14 @@ class MangaAdapter(private val context: Context) :
val item = mDiffer.currentList[layoutPosition]
if (item is MangaContent) {
loadImageWithRetry(
item.mImageUrl, isHorizontal, item.mDurChapterImageCount == 1
item.mImageUrl, isHorizontal, item.imageCount == 1
)
}
}
}
fun onBind(item: MangaContent) {
loadImageWithRetry(item.mImageUrl, isHorizontal, item.mDurChapterImageCount == 1)
loadImageWithRetry(item.mImageUrl, isHorizontal, item.imageCount == 1)
}
}