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 {
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)
}
}
}

Loading…
Cancel
Save