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