From 9c7e2c74889b5df463e691ccb0b56775b24d5cfc Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 16 Aug 2019 20:35:38 +0800 Subject: [PATCH] up --- .../java/io/legado/app/ui/readbook/ReadBookViewModel.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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) } } }