diff --git a/app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt b/app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt index fed906c6b..7f45b52c2 100644 --- a/app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt @@ -6,6 +6,7 @@ import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookSource +import io.legado.app.model.WebBook class ReadViewModel(application: Application) : BaseViewModel(application) { @@ -19,8 +20,14 @@ class ReadViewModel(application: Application) : BaseViewModel(application) { book = App.db.bookDao().getBook(bookUrl) book?.let { book -> if (App.db.bookChapterDao().getChapterCount(bookUrl) == 0) { - bookSource = App.db.bookSourceDao().getBookSource(book.origin) - if (bookSource == null) { + App.db.bookSourceDao().getBookSource(book.origin)?.let { + WebBook(it).getChapterList(book) + .onSuccess { cList -> + cList?.let { + App.db.bookChapterDao().insert(*cList.toTypedArray()) + } + } + } ?: let { } }