diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index 1288583a8..65af68269 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -48,21 +48,22 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } - fun loadContent(book: Book, index: Int) { + fun loadContent(book: Book, index: Int, success: ((content: String) -> Unit)) { execute { App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> BookHelp.getContent(book, chapter)?.let { - - } ?: download(book, chapter) + success(it) + } ?: download(book, chapter, success) } } } - private fun download(book: Book, chapter: BookChapter) { + fun download(book: Book, chapter: BookChapter, success: ((content: String) -> Unit)? = null) { webBook?.getContent(book, chapter) ?.onSuccess(IO) { content -> content?.let { BookHelp.saveContent(book, chapter, it) + success?.invoke(it) } } }