优化
This commit is contained in:
@@ -24,7 +24,6 @@ import io.legado.app.model.recyclerView.ReaderLoading
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
import io.legado.app.utils.mapIndexed
|
||||
import io.legado.app.utils.runOnUI
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.CoroutineStart
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
@@ -318,9 +317,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
mNextChapterIndex = durChapterIndex.plus(1)
|
||||
)
|
||||
)
|
||||
runOnUI {
|
||||
mCallback?.loadContentFinish(contentList)
|
||||
}
|
||||
mCallback?.loadContentFinish(contentList)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,9 +357,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
val book = book ?: return
|
||||
if (!book.canUpdate) return
|
||||
if (System.currentTimeMillis() - book.lastCheckTime < 600000) {
|
||||
runOnUI {
|
||||
mCallback?.noData()
|
||||
}
|
||||
mCallback?.noData()
|
||||
return
|
||||
}
|
||||
book.lastCheckTime = System.currentTimeMillis()
|
||||
@@ -382,9 +377,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
durChapterIndex = durChapterIndex.minus(1)
|
||||
saveRead()
|
||||
gameOver = true
|
||||
runOnUI {
|
||||
mCallback?.noData()
|
||||
}
|
||||
mCallback?.noData()
|
||||
}
|
||||
}.onError {
|
||||
mCallback?.noData()
|
||||
@@ -400,37 +393,25 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
if (BookHelp.hasContent(book, chapter)) {
|
||||
BookHelp.getContent(book, chapter)?.apply {
|
||||
contentLoadFinish(chapter, this, book)
|
||||
runOnUI {
|
||||
mCallback?.loadComplete()
|
||||
}
|
||||
mCallback?.loadComplete()
|
||||
if (durChapterIndex >= chapterSize.minus(1)) {
|
||||
gameOver = true
|
||||
runOnUI {
|
||||
mCallback?.noData()
|
||||
}
|
||||
mCallback?.noData()
|
||||
}
|
||||
} ?: downloadNetworkContent(bookSource, scope, chapter, book, success = {
|
||||
contentLoadFinish(chapter, it, book)
|
||||
runOnUI {
|
||||
mCallback?.loadComplete()
|
||||
}
|
||||
mCallback?.loadComplete()
|
||||
}, error = {
|
||||
removeLoading(chapter.index)
|
||||
runOnUI {
|
||||
mCallback?.loadFail("加载内容失败")
|
||||
}
|
||||
mCallback?.loadFail("加载内容失败")
|
||||
})
|
||||
} else {
|
||||
downloadNetworkContent(bookSource, scope, chapter, book, success = {
|
||||
contentLoadFinish(chapter, it, book)
|
||||
runOnUI {
|
||||
mCallback?.loadComplete()
|
||||
}
|
||||
mCallback?.loadComplete()
|
||||
}, error = {
|
||||
removeLoading(chapter.index)
|
||||
runOnUI {
|
||||
mCallback?.loadFail("加载内容失败")
|
||||
}
|
||||
mCallback?.loadFail("加载内容失败")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.PagerSnapHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -63,6 +64,7 @@ import io.legado.app.utils.toastOnUi
|
||||
import io.legado.app.utils.toggleStatusBar
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import io.legado.app.utils.visible
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>(),
|
||||
ReadManga.Callback, ChangeBookSourceDialog.CallBack, MangaMenu.CallBack {
|
||||
@@ -259,7 +261,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
}
|
||||
|
||||
override fun loadContentFinish(list: MutableList<Any>) {
|
||||
if (!this.isDestroyed) {
|
||||
lifecycleScope.launch {
|
||||
setTitle(ReadManga.book?.name)
|
||||
val isEmpty = mAdapter.isEmpty()
|
||||
mAdapter.submitList(list) {
|
||||
@@ -365,21 +367,27 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, MangaViewModel>()
|
||||
}
|
||||
|
||||
override fun loadComplete() {
|
||||
binding.flLoading.isGone = true
|
||||
lifecycleScope.launch {
|
||||
binding.flLoading.isGone = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadFail(msg: String) {
|
||||
if (mAdapter.isEmpty() || ReadManga.chapterChanged) {
|
||||
binding.llLoading.isGone = true
|
||||
binding.llRetry.isVisible = true
|
||||
binding.tvMsg.text = msg
|
||||
} else {
|
||||
loadMoreView.error(null, "加载失败,点击重试")
|
||||
lifecycleScope.launch {
|
||||
if (mAdapter.isEmpty() || ReadManga.chapterChanged) {
|
||||
binding.llLoading.isGone = true
|
||||
binding.llRetry.isVisible = true
|
||||
binding.tvMsg.text = msg
|
||||
} else {
|
||||
loadMoreView.error(null, "加载失败,点击重试")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun noData() {
|
||||
loadMoreView.noMore("暂无章节了!")
|
||||
lifecycleScope.launch {
|
||||
loadMoreView.noMore("暂无章节了!")
|
||||
}
|
||||
}
|
||||
|
||||
override fun adjustmentProgress() {
|
||||
|
||||
Reference in New Issue
Block a user