This commit is contained in:
kunfei committed 2022-07-27 22:35:33 +08:00
1 parent a7e9cfec57
commit 6142ab0481
1 file changed
+15
@@ -15,8 +15,11 @@ import io.legado.app.service.CacheBookService
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.startService import io.legado.app.utils.startService
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import splitties.init.appCtx
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@@ -173,6 +176,18 @@ object CacheBook {
} }
} }
postEvent(EventBus.UP_DOWNLOAD, book.bookUrl) 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 @Synchronized