From 9457f38d1bad7342c483f48d3482462dae28f658 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 27 Jul 2022 22:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/model/CacheBook.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index 02b977df2..6a286faf8 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -15,8 +15,11 @@ import io.legado.app.service.CacheBookService import io.legado.app.utils.postEvent import io.legado.app.utils.startService +import io.legado.app.utils.toastOnUi import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import splitties.init.appCtx import java.util.concurrent.ConcurrentHashMap import kotlin.coroutines.CoroutineContext @@ -173,6 +176,18 @@ object CacheBook { } } postEvent(EventBus.UP_DOWNLOAD, book.bookUrl) + val chapterCount = appDb.bookChapterDao.getChapterCount(book.bookUrl) + if (chapterCount == 0) { + runBlocking { + WebBook.getChapterListAwait(this, bookSource, book) + .onFailure { + AppLog.put("缓存书籍没有目录且加载目录失败\n${it.localizedMessage}", it) + appCtx.toastOnUi("缓存书籍没有目录且加载目录失败\n${it.localizedMessage}") + }.getOrNull() + }?.let { toc -> + appDb.bookChapterDao.insert(*toc.toTypedArray()) + } + } } @Synchronized