This commit is contained in:
Horis
2025-02-18 20:10:35 +08:00
parent 7ff29d7724
commit ba692e9037
7 changed files with 24 additions and 35 deletions

View File

@@ -1,7 +1,6 @@
package io.legado.app.help.glide.progress
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.runOnUI
import java.util.concurrent.ConcurrentHashMap
/**
@@ -20,9 +19,7 @@ object ProgressManager {
percentage = 0
isComplete = true
}
runOnUI {
it.invoke(isComplete, percentage, bytesRead, totalBytes)
}
it.invoke(isComplete, percentage, bytesRead, totalBytes)
if (isComplete) {
removeListener(url)
}

View File

@@ -31,11 +31,10 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.distinctUntilChangedBy
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
@@ -261,7 +260,6 @@ object ReadManga : CoroutineScope by MainScope() {
downloadedChapters.clear()
downloadFailChapters.clear()
downloadLoadingChapters.clear()
executor.asCoroutineDispatcher().cancelChildren()
downloadScope.coroutineContext.cancelChildren()
coroutineContext.cancelChildren()
}
@@ -274,10 +272,8 @@ object ReadManga : CoroutineScope by MainScope() {
content: String,
book: Book,
) {
if (mTopChapter != null && mTopChapter!!.title != chapterTitle && BookHelp.hasContent(
book,
mTopChapter!!
)
if (mTopChapter != null && mTopChapter!!.title != chapterTitle
&& BookHelp.hasContent(book, mTopChapter!!)
) {
BookHelp.delContent(book, chapter)
}
@@ -294,9 +290,7 @@ object ReadManga : CoroutineScope by MainScope() {
val mSrc = NetworkUtils.getAbsoluteURL(chapter.url, src)
emit(mSrc)
}
}.distinctUntilChangedBy {
it
}.mapIndexed { index, src ->
}.distinctUntilChanged().mapIndexed { index, src ->
MangeContent(
mChapterPageCount = durChapterPageCount,
mChapterPagePos = durChapterPagePos.plus(1),
@@ -395,9 +389,7 @@ object ReadManga : CoroutineScope by MainScope() {
}
}
}.onError {
runOnUI {
mCallback?.noData()
}
mCallback?.noData()
}
}

View File

@@ -66,7 +66,7 @@ open class MangaVH<VB : ViewBinding>(val binding: VB, private val context: Conte
bytesRead: Long,
totalBytes: Long,
) {
mProgress.text = "${percentage}%"
mProgress.text = "$percentage%"
}
})
try {

View File

@@ -150,8 +150,8 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
}
}
setNestedPreScrollListener { _, _, _, position ->
if (mAdapter.getCurrentList()
.isNotEmpty() && position <= mAdapter.getCurrentList().lastIndex
if (mAdapter.getCurrentList().isNotEmpty()
&& position <= mAdapter.getCurrentList().lastIndex
) {
try {
val content = mAdapter.getCurrentList()[position]

View File

@@ -63,18 +63,16 @@ class MangaAdapter(private val context: Context) :
//全部替换数据
fun submitList(contents: MutableList<Any>, runnable: Runnable) {
val currentList = mDiffer.currentList.toMutableList()
currentList.addAll(contents)
if (ReadManga.chapterChanged) {
mDiffer.submitList(contents) {
runnable.run()
}
val list = if (ReadManga.chapterChanged) {
contents
} else {
mDiffer.submitList(currentList) {
runnable.run()
}
val currentList = mDiffer.currentList.toMutableList()
currentList.addAll(contents)
currentList
}
mDiffer.submitList(list) {
runnable.run()
}
}
inner class PageViewHolder(binding: BookComicRvBinding) :

View File

@@ -13,6 +13,7 @@ import androidx.activity.viewModels
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst.charsets
@@ -84,8 +85,8 @@ abstract class BaseReadBookActivity :
super.onCreate(savedInstanceState)
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
binding.navigationBar.run {
layoutParams = layoutParams.apply { height = insets.bottom }
binding.navigationBar.updateLayoutParams {
height = insets.bottom
}
windowInsets
}

View File

@@ -34,6 +34,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.get
import androidx.core.view.marginBottom
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import io.legado.app.help.config.AppConfig
@@ -283,9 +284,9 @@ fun View.applyNavigationBarPadding(withInitialPadding: Boolean = false) {
fun View.applyNavigationBarMargin(withInitialMargin: Boolean = false) {
val initialMargin = if (withInitialMargin) marginBottom else 0
ViewCompat.setOnApplyWindowInsetsListener(this) { _, windowInsets ->
val lp = layoutParams as ViewGroup.MarginLayoutParams
lp.bottomMargin = initialMargin + windowInsets.navigationBarHeight
layoutParams = lp
updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = initialMargin + windowInsets.navigationBarHeight
}
windowInsets
}
}