This commit is contained in:
Horis
2025-03-26 22:01:26 +08:00
parent ac2128e763
commit 4b23cc04f3
4 changed files with 76 additions and 65 deletions
@@ -253,29 +253,28 @@ object ReadBook : CoroutineScope by MainScope() {
syncSuccessAction: (() -> Unit)? = null
) {
if (!AppConfig.syncBookProgress) return
book?.let {
Coroutine.async {
AppWebDav.getBookProgress(it)
}.onError {
AppLog.put("拉取阅读进度失败", it)
}.onSuccess { progress ->
if (progress == null || progress.durChapterIndex < it.durChapterIndex ||
(progress.durChapterIndex == it.durChapterIndex
&& progress.durChapterPos < it.durChapterPos)
) {
// 服务器没有进度或者进度比服务器快,上传现有进度
Coroutine.async {
AppWebDav.uploadBookProgress(BookProgress(it), uploadSuccessAction)
it.update()
}
} else if (progress.durChapterIndex > it.durChapterIndex ||
progress.durChapterPos > it.durChapterPos
) {
// 进度比服务器慢,执行传入动作
newProgressAction?.invoke(progress)
} else {
syncSuccessAction?.invoke()
val book = book ?: return
Coroutine.async {
AppWebDav.getBookProgress(book)
}.onError {
AppLog.put("拉取阅读进度失败", it)
}.onSuccess { progress ->
if (progress == null || progress.durChapterIndex < book.durChapterIndex ||
(progress.durChapterIndex == book.durChapterIndex
&& progress.durChapterPos < book.durChapterPos)
) {
// 服务器没有进度或者进度比服务器快,上传现有进度
Coroutine.async {
AppWebDav.uploadBookProgress(BookProgress(book), uploadSuccessAction)
book.update()
}
} else if (progress.durChapterIndex > book.durChapterIndex ||
progress.durChapterPos > book.durChapterPos
) {
// 进度比服务器慢,执行传入动作
newProgressAction?.invoke(progress)
} else {
syncSuccessAction?.invoke()
}
}
}
@@ -211,7 +211,7 @@ object ReadManga : CoroutineScope by MainScope() {
return
}
val mangaChapter = getManageChapter(chapter, content)
if (mangaChapter.imageCount == 0) {
if (mangaChapter.imageCount == 0 && !chapter.isVolume) {
mCallback?.loadFail("正文没有图片")
return
}
@@ -224,7 +224,7 @@ object ReadManga : CoroutineScope by MainScope() {
return
}
val mangaChapter = getManageChapter(chapter, content)
if (mangaChapter.imageCount == 0) {
if (mangaChapter.imageCount == 0 && !chapter.isVolume) {
return
}
@@ -488,29 +488,28 @@ object ReadManga : CoroutineScope by MainScope() {
syncSuccessAction: (() -> Unit)? = null,
) {
if (!AppConfig.syncBookProgress) return
book?.let {
Coroutine.async {
AppWebDav.getBookProgress(it)
}.onError {
AppLog.put("拉取阅读进度失败", it)
}.onSuccess { progress ->
if (progress == null || progress.durChapterIndex < it.durChapterIndex ||
(progress.durChapterIndex == it.durChapterIndex
&& progress.durChapterPos < it.durChapterPos)
) {
// 服务器没有进度或者进度比服务器快,上传现有进度
Coroutine.async {
AppWebDav.uploadBookProgress(BookProgress(it), uploadSuccessAction)
it.update()
}
} else if (progress.durChapterIndex > it.durChapterIndex ||
progress.durChapterPos > it.durChapterPos
) {
// 进度比服务器慢,执行传入动作
newProgressAction?.invoke(progress)
} else {
syncSuccessAction?.invoke()
val book = book ?: return
Coroutine.async {
AppWebDav.getBookProgress(book)
}.onError {
AppLog.put("拉取阅读进度失败", it)
}.onSuccess { progress ->
if (progress == null || progress.durChapterIndex < book.durChapterIndex ||
(progress.durChapterIndex == book.durChapterIndex
&& progress.durChapterPos < book.durChapterPos)
) {
// 服务器没有进度或者进度比服务器快,上传现有进度
Coroutine.async {
AppWebDav.uploadBookProgress(BookProgress(book), uploadSuccessAction)
book.update()
}
} else if (progress.durChapterIndex > book.durChapterIndex ||
progress.durChapterPos > book.durChapterPos
) {
// 进度比服务器慢,执行传入动作
newProgressAction?.invoke(progress)
} else {
syncSuccessAction?.invoke()
}
}
}
@@ -591,12 +590,21 @@ object ReadManga : CoroutineScope by MainScope() {
it.imageCount = imageCount
}
val contentList = mutableListOf<BaseMangaPage>()
contentList.add(ReaderLoading(chapter.index, -1, "阅读 ${chapter.title}"))
contentList.addAll(list)
contentList.add(ReaderLoading(chapter.index, imageCount, "已读完 ${chapter.title}"))
if (AppConfig.hideMangaTitle) {
return MangaChapter(chapter, list, imageCount)
}
return MangaChapter(chapter, contentList, imageCount)
val pages = mutableListOf<BaseMangaPage>()
if (imageCount == 0 && chapter.isVolume) {
pages.add(ReaderLoading(chapter.index, -1, chapter.title))
} else {
pages.add(ReaderLoading(chapter.index, -1, "阅读 ${chapter.title}"))
pages.addAll(list)
pages.add(ReaderLoading(chapter.index, imageCount, "已读完 ${chapter.title}"))
}
return MangaChapter(chapter, pages, imageCount)
}
interface Callback {
@@ -17,6 +17,8 @@ import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
import com.bumptech.glide.Glide
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader
import com.bumptech.glide.request.target.Target.SIZE_ORIGINAL
@@ -191,7 +193,6 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
?: MangaColorFilterConfig()
mAdapter.run {
setMangaImageColorFilter(mangaColorFilter)
setHideTitle(AppConfig.hideMangaTitle)
}
setHorizontalScroll(AppConfig.enableMangaHorizontalScroll)
binding.recyclerView.run {
@@ -219,10 +220,24 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
}
}
}
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(
recyclerView: RecyclerView,
newState: Int
) {
if (newState == SCROLL_STATE_IDLE &&
!canScroll(1) &&
ReadManga.hasNextChapter && !loadMoreView.isLoading
) {
loadMoreView.startLoad()
ReadManga.moveToNextChapter()
}
}
})
}
binding.webtoonFrame.run {
onTouchMiddle {
if (!binding.mangaMenu.isVisible) {
if (!binding.mangaMenu.isVisible && !loadingViewVisible) {
binding.mangaMenu.runMenuIn()
}
}
@@ -567,7 +582,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
R.id.menu_hide_manga_title -> {
item.isChecked = !item.isChecked
AppConfig.hideMangaTitle = item.isChecked
mAdapter.setHideTitle(item.isChecked)
ReadManga.loadContent()
}
}
return super.onCompatOptionsItemSelected(item)
@@ -1,6 +1,5 @@
package io.legado.app.ui.book.manga.recyclerview
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
@@ -28,7 +27,6 @@ import io.legado.app.model.ReadManga
import io.legado.app.ui.book.manga.config.MangaColorFilterConfig
import io.legado.app.ui.book.manga.entities.MangaPage
import io.legado.app.ui.book.manga.entities.ReaderLoading
import io.legado.app.ui.widget.anima.explosion_field.Utils
class MangaAdapter(private val context: Context) :
@@ -43,7 +41,6 @@ class MangaAdapter(private val context: Context) :
}
var isHorizontal = false
private var hideTitle = false
private val mDiffCallback: DiffUtil.ItemCallback<Any> = object : DiffUtil.ItemCallback<Any>() {
override fun areItemsTheSame(oldItem: Any, newItem: Any): Boolean {
@@ -128,9 +125,6 @@ class MangaAdapter(private val context: Context) :
fun onBind(item: ReaderLoading) {
val message = item.mMessage
binding.text.text = message
binding.root.updateLayoutParams<ViewGroup.LayoutParams> {
height = if (hideTitle) 0 else Utils.dp2Px(96)
}
}
}
@@ -238,14 +232,9 @@ class MangaAdapter(private val context: Context) :
return null
}
@SuppressLint("NotifyDataSetChanged")
fun setMangaImageColorFilter(config: MangaColorFilterConfig) {
mConfig = config
notifyItemRangeChanged(0, itemCount)
}
fun setHideTitle(hide: Boolean) {
this.hideTitle=hide
notifyItemRangeChanged(0, itemCount)
}
}