This commit is contained in:
Horis
2025-02-18 20:10:35 +08:00
parent 7f588cf1bb
commit 9b7ce8e0f6
7 changed files with 24 additions and 35 deletions
@@ -1,7 +1,6 @@
package io.legado.app.help.glide.progress package io.legado.app.help.glide.progress
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.runOnUI
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
/** /**
@@ -20,9 +19,7 @@ object ProgressManager {
percentage = 0 percentage = 0
isComplete = true isComplete = true
} }
runOnUI { it.invoke(isComplete, percentage, bytesRead, totalBytes)
it.invoke(isComplete, percentage, bytesRead, totalBytes)
}
if (isComplete) { if (isComplete) {
removeListener(url) removeListener(url)
} }
@@ -31,11 +31,10 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.cancelChildren import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.distinctUntilChangedBy import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -261,7 +260,6 @@ object ReadManga : CoroutineScope by MainScope() {
downloadedChapters.clear() downloadedChapters.clear()
downloadFailChapters.clear() downloadFailChapters.clear()
downloadLoadingChapters.clear() downloadLoadingChapters.clear()
executor.asCoroutineDispatcher().cancelChildren()
downloadScope.coroutineContext.cancelChildren() downloadScope.coroutineContext.cancelChildren()
coroutineContext.cancelChildren() coroutineContext.cancelChildren()
} }
@@ -274,10 +272,8 @@ object ReadManga : CoroutineScope by MainScope() {
content: String, content: String,
book: Book, book: Book,
) { ) {
if (mTopChapter != null && mTopChapter!!.title != chapterTitle && BookHelp.hasContent( if (mTopChapter != null && mTopChapter!!.title != chapterTitle
book, && BookHelp.hasContent(book, mTopChapter!!)
mTopChapter!!
)
) { ) {
BookHelp.delContent(book, chapter) BookHelp.delContent(book, chapter)
} }
@@ -294,9 +290,7 @@ object ReadManga : CoroutineScope by MainScope() {
val mSrc = NetworkUtils.getAbsoluteURL(chapter.url, src) val mSrc = NetworkUtils.getAbsoluteURL(chapter.url, src)
emit(mSrc) emit(mSrc)
} }
}.distinctUntilChangedBy { }.distinctUntilChanged().mapIndexed { index, src ->
it
}.mapIndexed { index, src ->
MangeContent( MangeContent(
mChapterPageCount = durChapterPageCount, mChapterPageCount = durChapterPageCount,
mChapterPagePos = durChapterPagePos.plus(1), mChapterPagePos = durChapterPagePos.plus(1),
@@ -395,9 +389,7 @@ object ReadManga : CoroutineScope by MainScope() {
} }
} }
}.onError { }.onError {
runOnUI { mCallback?.noData()
mCallback?.noData()
}
} }
} }
@@ -66,7 +66,7 @@ open class MangaVH<VB : ViewBinding>(val binding: VB, private val context: Conte
bytesRead: Long, bytesRead: Long,
totalBytes: Long, totalBytes: Long,
) { ) {
mProgress.text = "${percentage}%" mProgress.text = "$percentage%"
} }
}) })
try { try {
@@ -150,8 +150,8 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
} }
} }
setNestedPreScrollListener { _, _, _, position -> setNestedPreScrollListener { _, _, _, position ->
if (mAdapter.getCurrentList() if (mAdapter.getCurrentList().isNotEmpty()
.isNotEmpty() && position <= mAdapter.getCurrentList().lastIndex && position <= mAdapter.getCurrentList().lastIndex
) { ) {
try { try {
val content = mAdapter.getCurrentList()[position] val content = mAdapter.getCurrentList()[position]
@@ -63,18 +63,16 @@ class MangaAdapter(private val context: Context) :
//全部替换数据 //全部替换数据
fun submitList(contents: MutableList<Any>, runnable: Runnable) { fun submitList(contents: MutableList<Any>, runnable: Runnable) {
val currentList = mDiffer.currentList.toMutableList() val list = if (ReadManga.chapterChanged) {
currentList.addAll(contents) contents
if (ReadManga.chapterChanged) {
mDiffer.submitList(contents) {
runnable.run()
}
} else { } else {
mDiffer.submitList(currentList) { val currentList = mDiffer.currentList.toMutableList()
runnable.run() currentList.addAll(contents)
} currentList
}
mDiffer.submitList(list) {
runnable.run()
} }
} }
inner class PageViewHolder(binding: BookComicRvBinding) : inner class PageViewHolder(binding: BookComicRvBinding) :
@@ -13,6 +13,7 @@ import androidx.activity.viewModels
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst.charsets import io.legado.app.constant.AppConst.charsets
@@ -84,8 +85,8 @@ abstract class BaseReadBookActivity :
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets -> ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
binding.navigationBar.run { binding.navigationBar.updateLayoutParams {
layoutParams = layoutParams.apply { height = insets.bottom } height = insets.bottom
} }
windowInsets windowInsets
} }
@@ -34,6 +34,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.get import androidx.core.view.get
import androidx.core.view.marginBottom import androidx.core.view.marginBottom
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
@@ -283,9 +284,9 @@ fun View.applyNavigationBarPadding(withInitialPadding: Boolean = false) {
fun View.applyNavigationBarMargin(withInitialMargin: Boolean = false) { fun View.applyNavigationBarMargin(withInitialMargin: Boolean = false) {
val initialMargin = if (withInitialMargin) marginBottom else 0 val initialMargin = if (withInitialMargin) marginBottom else 0
ViewCompat.setOnApplyWindowInsetsListener(this) { _, windowInsets -> ViewCompat.setOnApplyWindowInsetsListener(this) { _, windowInsets ->
val lp = layoutParams as ViewGroup.MarginLayoutParams updateLayoutParams<ViewGroup.MarginLayoutParams> {
lp.bottomMargin = initialMargin + windowInsets.navigationBarHeight bottomMargin = initialMargin + windowInsets.navigationBarHeight
layoutParams = lp }
windowInsets windowInsets
} }
} }