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() { fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) { if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null ReadBook.book = null

View File

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

View File

@ -119,7 +119,7 @@ class CacheBookService : BaseService() {
WebBook.getChapterListAwait(cacheBook.bookSource, book).onFailure { WebBook.getChapterListAwait(cacheBook.bookSource, book).onFailure {
if (book.totalChapterNum > 0) { if (book.totalChapterNum > 0) {
book.totalChapterNum = 0 book.totalChapterNum = 0
book.save() book.update()
} }
val msg = "$name》目录为空且加载目录失败\n${it.localizedMessage}" val msg = "$name》目录为空且加载目录失败\n${it.localizedMessage}"
AppLog.put(msg, it, true) AppLog.put(msg, it, true)
@ -127,7 +127,7 @@ class CacheBookService : BaseService() {
}.getOrNull()?.let { toc -> }.getOrNull()?.let { toc ->
appDb.bookChapterDao.insert(*toc.toTypedArray()) appDb.bookChapterDao.insert(*toc.toTypedArray())
} }
book.save() book.update()
} }
} }
val end2 = if (end < 0) { 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.Dispatchers.IO
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -1439,7 +1440,8 @@ class ReadBookActivity : BaseReadBookActivity(),
delay(300000) delay(300000)
ReadBook.book?.let { ReadBook.book?.let {
AppWebDav.uploadBookProgress(it) AppWebDav.uploadBookProgress(it)
it.save() ensureActive()
it.update()
Backup.autoBack(this@ReadBookActivity) Backup.autoBack(this@ReadBookActivity)
} }
} }