[优化] 阅读书籍未下载时白屏问题
This commit is contained in:
@@ -14,8 +14,6 @@ import io.legado.app.model.cache.CacheDownloadRequest
|
||||
import io.legado.app.model.cache.CacheDownloadSource
|
||||
import io.legado.app.model.cache.CacheDownloadStateStore
|
||||
import io.legado.app.model.cache.ChapterSelection
|
||||
import io.legado.app.model.cache.ReadingCacheEvent
|
||||
import io.legado.app.model.cache.ReadingCacheEvents
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.CoroutineStart
|
||||
@@ -616,14 +614,14 @@ class CacheBookModel(
|
||||
resetPageOffset: Boolean = false,
|
||||
canceled: Boolean = false
|
||||
) {
|
||||
ReadingCacheEvents.emit(
|
||||
ReadingCacheEvent.ContentReady(
|
||||
if (ReadBook.book?.bookUrl == book.bookUrl) {
|
||||
ReadBook.contentLoadFinish(
|
||||
book = book,
|
||||
chapter = chapter,
|
||||
content = content,
|
||||
resetPageOffset = resetPageOffset,
|
||||
canceled = canceled,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.help.globalExecutor
|
||||
import io.legado.app.model.localBook.TextFile
|
||||
import io.legado.app.model.cache.ReadingCacheEvent
|
||||
import io.legado.app.model.cache.ReadingCacheEvents
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.service.BaseReadAloudService
|
||||
import io.legado.app.service.CacheBookService
|
||||
@@ -90,26 +88,6 @@ object ReadBook : CoroutineScope by MainScope(), KoinComponent {
|
||||
private val nextChapterLoadingLock = Mutex()
|
||||
var readStartTime: Long = System.currentTimeMillis()
|
||||
|
||||
init {
|
||||
launch {
|
||||
ReadingCacheEvents.events.collect { event ->
|
||||
when (event) {
|
||||
is ReadingCacheEvent.ContentReady -> {
|
||||
if (book?.bookUrl == event.book.bookUrl) {
|
||||
contentLoadFinish(
|
||||
book = event.book,
|
||||
chapter = event.chapter,
|
||||
content = event.content,
|
||||
resetPageOffset = event.resetPageOffset,
|
||||
canceled = event.canceled,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 跳转进度前进度记录 */
|
||||
var lastBookProgress: BookProgress? = null
|
||||
|
||||
@@ -686,7 +664,12 @@ object ReadBook : CoroutineScope by MainScope(), KoinComponent {
|
||||
) {
|
||||
Coroutine.async {
|
||||
val book = book!!
|
||||
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, index) ?: return@async
|
||||
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, index) ?: run {
|
||||
if (index == durChapterIndex) {
|
||||
upMsg("章节不存在")
|
||||
}
|
||||
return@async
|
||||
}
|
||||
if (addLoading(index)) {
|
||||
BookHelp.getContent(book, chapter)?.let {
|
||||
contentLoadFinish(
|
||||
@@ -704,7 +687,11 @@ object ReadBook : CoroutineScope by MainScope(), KoinComponent {
|
||||
)
|
||||
}
|
||||
}.onError {
|
||||
AppLog.put("加载正文出错\n${it.localizedMessage}")
|
||||
removeLoading(index)
|
||||
if (index == durChapterIndex) {
|
||||
upMsg("加载正文出错\n${it.localizedMessage}")
|
||||
}
|
||||
AppLog.put("加载正文出错\n${it.localizedMessage}", it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.legado.app.model.cache
|
||||
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
|
||||
sealed interface ReadingCacheEvent {
|
||||
data class ContentReady(
|
||||
val book: Book,
|
||||
val chapter: BookChapter,
|
||||
val content: String,
|
||||
val resetPageOffset: Boolean,
|
||||
val canceled: Boolean,
|
||||
) : ReadingCacheEvent
|
||||
}
|
||||
|
||||
object ReadingCacheEvents {
|
||||
private val _events = MutableSharedFlow<ReadingCacheEvent>(extraBufferCapacity = 32)
|
||||
val events = _events.asSharedFlow()
|
||||
|
||||
fun emit(event: ReadingCacheEvent) {
|
||||
_events.tryEmit(event)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user