This commit is contained in:
Horis 2024-03-17 16:15:53 +08:00
parent d70c2b3829
commit 15258abc09
5 changed files with 17 additions and 8 deletions

View File

@ -364,6 +364,10 @@ data class Book(
}
}
fun update() {
appDb.bookDao.update(this)
}
fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null

View File

@ -171,7 +171,7 @@ object AudioPlay {
book.getUseReplaceRule()
)
}
book.save()
book.update()
}
}
}

View File

@ -26,10 +26,12 @@ import io.legado.app.utils.stackTraceStr
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
@ -64,7 +66,7 @@ object ReadBook : CoroutineScope by MainScope() {
/* web端阅读进度记录 */
var webBookProgress: BookProgress? = null
var preDownloadTask: Coroutine<*>? = null
var preDownloadTask: Job? = null
val downloadedChapters = hashSetOf<Int>()
val downloadFailChapters = hashMapOf<Int, Int>()
var contentProcessor: ContentProcessor? = null
@ -169,9 +171,10 @@ object ReadBook : CoroutineScope by MainScope() {
fun uploadProgress() {
book?.let {
Coroutine.async {
launch(IO) {
AppWebDav.uploadBookProgress(it)
it.save()
ensureActive()
it.update()
}
}
}
@ -651,7 +654,7 @@ object ReadBook : CoroutineScope by MainScope() {
return@execute
}
preDownloadTask?.cancel()
preDownloadTask = Coroutine.async(executeContext = IO) {
preDownloadTask = launch(IO) {
//预下载
launch {
val maxChapterIndex =

View File

@ -119,7 +119,7 @@ class CacheBookService : BaseService() {
WebBook.getChapterListAwait(cacheBook.bookSource, book).onFailure {
if (book.totalChapterNum > 0) {
book.totalChapterNum = 0
book.save()
book.update()
}
val msg = "$name》目录为空且加载目录失败\n${it.localizedMessage}"
AppLog.put(msg, it, true)
@ -127,7 +127,7 @@ class CacheBookService : BaseService() {
}.getOrNull()?.let { toc ->
appDb.bookChapterDao.insert(*toc.toTypedArray())
}
book.save()
book.update()
}
}
val end2 = if (end < 0) {

View File

@ -122,6 +122,7 @@ import io.legado.app.utils.visible
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -1439,7 +1440,8 @@ class ReadBookActivity : BaseReadBookActivity(),
delay(300000)
ReadBook.book?.let {
AppWebDav.uploadBookProgress(it)
it.save()
ensureActive()
it.update()
Backup.autoBack(this@ReadBookActivity)
}
}