|
|
@ -6,6 +6,7 @@ import io.legado.app.App |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
|
|
|
|
import io.legado.app.model.WebBook |
|
|
|
|
|
|
|
|
|
|
|
class ReadViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class ReadViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
|
@ -19,8 +20,14 @@ class ReadViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
book = App.db.bookDao().getBook(bookUrl) |
|
|
|
book = App.db.bookDao().getBook(bookUrl) |
|
|
|
book?.let { book -> |
|
|
|
book?.let { book -> |
|
|
|
if (App.db.bookChapterDao().getChapterCount(bookUrl) == 0) { |
|
|
|
if (App.db.bookChapterDao().getChapterCount(bookUrl) == 0) { |
|
|
|
bookSource = App.db.bookSourceDao().getBookSource(book.origin) |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { |
|
|
|
if (bookSource == null) { |
|
|
|
WebBook(it).getChapterList(book) |
|
|
|
|
|
|
|
.onSuccess { cList -> |
|
|
|
|
|
|
|
cList?.let { |
|
|
|
|
|
|
|
App.db.bookChapterDao().insert(*cList.toTypedArray()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} ?: let { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|