优化
This commit is contained in:
@@ -253,29 +253,28 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
syncSuccessAction: (() -> Unit)? = null
|
syncSuccessAction: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
if (!AppConfig.syncBookProgress) return
|
if (!AppConfig.syncBookProgress) return
|
||||||
book?.let {
|
val book = book ?: return
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
AppWebDav.getBookProgress(it)
|
AppWebDav.getBookProgress(book)
|
||||||
}.onError {
|
}.onError {
|
||||||
AppLog.put("拉取阅读进度失败", it)
|
AppLog.put("拉取阅读进度失败", it)
|
||||||
}.onSuccess { progress ->
|
}.onSuccess { progress ->
|
||||||
if (progress == null || progress.durChapterIndex < it.durChapterIndex ||
|
if (progress == null || progress.durChapterIndex < book.durChapterIndex ||
|
||||||
(progress.durChapterIndex == it.durChapterIndex
|
(progress.durChapterIndex == book.durChapterIndex
|
||||||
&& progress.durChapterPos < it.durChapterPos)
|
&& progress.durChapterPos < book.durChapterPos)
|
||||||
) {
|
) {
|
||||||
// 服务器没有进度或者进度比服务器快,上传现有进度
|
// 服务器没有进度或者进度比服务器快,上传现有进度
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
AppWebDav.uploadBookProgress(BookProgress(it), uploadSuccessAction)
|
AppWebDav.uploadBookProgress(BookProgress(book), uploadSuccessAction)
|
||||||
it.update()
|
book.update()
|
||||||
}
|
|
||||||
} else if (progress.durChapterIndex > it.durChapterIndex ||
|
|
||||||
progress.durChapterPos > it.durChapterPos
|
|
||||||
) {
|
|
||||||
// 进度比服务器慢,执行传入动作
|
|
||||||
newProgressAction?.invoke(progress)
|
|
||||||
} else {
|
|
||||||
syncSuccessAction?.invoke()
|
|
||||||
}
|
}
|
||||||
|
} 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
|
return
|
||||||
}
|
}
|
||||||
val mangaChapter = getManageChapter(chapter, content)
|
val mangaChapter = getManageChapter(chapter, content)
|
||||||
if (mangaChapter.imageCount == 0) {
|
if (mangaChapter.imageCount == 0 && !chapter.isVolume) {
|
||||||
mCallback?.loadFail("正文没有图片")
|
mCallback?.loadFail("正文没有图片")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -224,7 +224,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val mangaChapter = getManageChapter(chapter, content)
|
val mangaChapter = getManageChapter(chapter, content)
|
||||||
if (mangaChapter.imageCount == 0) {
|
if (mangaChapter.imageCount == 0 && !chapter.isVolume) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,29 +488,28 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
syncSuccessAction: (() -> Unit)? = null,
|
syncSuccessAction: (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (!AppConfig.syncBookProgress) return
|
if (!AppConfig.syncBookProgress) return
|
||||||
book?.let {
|
val book = book ?: return
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
AppWebDav.getBookProgress(it)
|
AppWebDav.getBookProgress(book)
|
||||||
}.onError {
|
}.onError {
|
||||||
AppLog.put("拉取阅读进度失败", it)
|
AppLog.put("拉取阅读进度失败", it)
|
||||||
}.onSuccess { progress ->
|
}.onSuccess { progress ->
|
||||||
if (progress == null || progress.durChapterIndex < it.durChapterIndex ||
|
if (progress == null || progress.durChapterIndex < book.durChapterIndex ||
|
||||||
(progress.durChapterIndex == it.durChapterIndex
|
(progress.durChapterIndex == book.durChapterIndex
|
||||||
&& progress.durChapterPos < it.durChapterPos)
|
&& progress.durChapterPos < book.durChapterPos)
|
||||||
) {
|
) {
|
||||||
// 服务器没有进度或者进度比服务器快,上传现有进度
|
// 服务器没有进度或者进度比服务器快,上传现有进度
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
AppWebDav.uploadBookProgress(BookProgress(it), uploadSuccessAction)
|
AppWebDav.uploadBookProgress(BookProgress(book), uploadSuccessAction)
|
||||||
it.update()
|
book.update()
|
||||||
}
|
|
||||||
} else if (progress.durChapterIndex > it.durChapterIndex ||
|
|
||||||
progress.durChapterPos > it.durChapterPos
|
|
||||||
) {
|
|
||||||
// 进度比服务器慢,执行传入动作
|
|
||||||
newProgressAction?.invoke(progress)
|
|
||||||
} else {
|
|
||||||
syncSuccessAction?.invoke()
|
|
||||||
}
|
}
|
||||||
|
} 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
|
it.imageCount = imageCount
|
||||||
}
|
}
|
||||||
|
|
||||||
val contentList = mutableListOf<BaseMangaPage>()
|
if (AppConfig.hideMangaTitle) {
|
||||||
contentList.add(ReaderLoading(chapter.index, -1, "阅读 ${chapter.title}"))
|
return MangaChapter(chapter, list, imageCount)
|
||||||
contentList.addAll(list)
|
}
|
||||||
contentList.add(ReaderLoading(chapter.index, imageCount, "已读完 ${chapter.title}"))
|
|
||||||
|
|
||||||
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 {
|
interface Callback {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import androidx.core.view.isVisible
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.PagerSnapHelper
|
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.Glide
|
||||||
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader
|
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader
|
||||||
import com.bumptech.glide.request.target.Target.SIZE_ORIGINAL
|
import com.bumptech.glide.request.target.Target.SIZE_ORIGINAL
|
||||||
@@ -191,7 +193,6 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
|||||||
?: MangaColorFilterConfig()
|
?: MangaColorFilterConfig()
|
||||||
mAdapter.run {
|
mAdapter.run {
|
||||||
setMangaImageColorFilter(mangaColorFilter)
|
setMangaImageColorFilter(mangaColorFilter)
|
||||||
setHideTitle(AppConfig.hideMangaTitle)
|
|
||||||
}
|
}
|
||||||
setHorizontalScroll(AppConfig.enableMangaHorizontalScroll)
|
setHorizontalScroll(AppConfig.enableMangaHorizontalScroll)
|
||||||
binding.recyclerView.run {
|
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 {
|
binding.webtoonFrame.run {
|
||||||
onTouchMiddle {
|
onTouchMiddle {
|
||||||
if (!binding.mangaMenu.isVisible) {
|
if (!binding.mangaMenu.isVisible && !loadingViewVisible) {
|
||||||
binding.mangaMenu.runMenuIn()
|
binding.mangaMenu.runMenuIn()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -567,7 +582,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
|
|||||||
R.id.menu_hide_manga_title -> {
|
R.id.menu_hide_manga_title -> {
|
||||||
item.isChecked = !item.isChecked
|
item.isChecked = !item.isChecked
|
||||||
AppConfig.hideMangaTitle = item.isChecked
|
AppConfig.hideMangaTitle = item.isChecked
|
||||||
mAdapter.setHideTitle(item.isChecked)
|
ReadManga.loadContent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onCompatOptionsItemSelected(item)
|
return super.onCompatOptionsItemSelected(item)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package io.legado.app.ui.book.manga.recyclerview
|
package io.legado.app.ui.book.manga.recyclerview
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.ColorMatrix
|
import android.graphics.ColorMatrix
|
||||||
import android.graphics.ColorMatrixColorFilter
|
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.config.MangaColorFilterConfig
|
||||||
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.ui.widget.anima.explosion_field.Utils
|
|
||||||
|
|
||||||
|
|
||||||
class MangaAdapter(private val context: Context) :
|
class MangaAdapter(private val context: Context) :
|
||||||
@@ -43,7 +41,6 @@ class MangaAdapter(private val context: Context) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
var isHorizontal = false
|
var isHorizontal = false
|
||||||
private var hideTitle = false
|
|
||||||
|
|
||||||
private val mDiffCallback: DiffUtil.ItemCallback<Any> = object : DiffUtil.ItemCallback<Any>() {
|
private val mDiffCallback: DiffUtil.ItemCallback<Any> = object : DiffUtil.ItemCallback<Any>() {
|
||||||
override fun areItemsTheSame(oldItem: Any, newItem: Any): Boolean {
|
override fun areItemsTheSame(oldItem: Any, newItem: Any): Boolean {
|
||||||
@@ -128,9 +125,6 @@ class MangaAdapter(private val context: Context) :
|
|||||||
fun onBind(item: ReaderLoading) {
|
fun onBind(item: ReaderLoading) {
|
||||||
val message = item.mMessage
|
val message = item.mMessage
|
||||||
binding.text.text = message
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
|
||||||
fun setMangaImageColorFilter(config: MangaColorFilterConfig) {
|
fun setMangaImageColorFilter(config: MangaColorFilterConfig) {
|
||||||
mConfig = config
|
mConfig = config
|
||||||
notifyItemRangeChanged(0, itemCount)
|
notifyItemRangeChanged(0, itemCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setHideTitle(hide: Boolean) {
|
|
||||||
this.hideTitle=hide
|
|
||||||
notifyItemRangeChanged(0, itemCount)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user