pull/32/head
kunfei 5 years ago
parent 811191e153
commit 9c7e2c7488
  1. 9
      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 { execute {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let { BookHelp.getContent(book, chapter)?.let {
success(it)
} ?: download(book, chapter) } ?: 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) webBook?.getContent(book, chapter)
?.onSuccess(IO) { content -> ?.onSuccess(IO) { content ->
content?.let { content?.let {
BookHelp.saveContent(book, chapter, it) BookHelp.saveContent(book, chapter, it)
success?.invoke(it)
} }
} }
} }

Loading…
Cancel
Save