From b7798d8910f28824f874bf02b9d396a1a5521706 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 19 Aug 2019 16:50:17 +0800 Subject: [PATCH] up --- .../app/ui/bookinfo/BookInfoViewModel.kt | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index 43c409212..77af4ea0d 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt @@ -46,35 +46,39 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } fun loadBookInfo(book: Book) { - isLoadingData.postValue(true) - App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> - WebBook(bookSource).getBookInfo(book, this) - .onSuccess { - it?.let { loadChapter(it) } - }.onError { - toast(R.string.error_get_book_info) - } - } ?: toast(R.string.error_no_source) + execute { + isLoadingData.postValue(true) + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> + WebBook(bookSource).getBookInfo(book, this) + .onSuccess { + it?.let { loadChapter(it) } + }.onError { + toast(R.string.error_get_book_info) + } + } ?: toast(R.string.error_no_source) + } } fun loadChapter(book: Book) { - isLoadingData.postValue(true) - App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> - WebBook(bookSource).getChapterList(book, this) - .onSuccess(IO) { - it?.let { - if (it.isNotEmpty()) { - if (inBookshelf) { - App.db.bookChapterDao().insert(*it.toTypedArray()) + execute { + isLoadingData.postValue(true) + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> + WebBook(bookSource).getChapterList(book, this) + .onSuccess(IO) { + it?.let { + if (it.isNotEmpty()) { + if (inBookshelf) { + App.db.bookChapterDao().insert(*it.toTypedArray()) + } + chapterListData.postValue(it) + isLoadingData.postValue(false) } - chapterListData.postValue(it) - isLoadingData.postValue(false) } + }.onError { + toast(R.string.error_get_chapter_list) } - }.onError { - toast(R.string.error_get_chapter_list) - } - } ?: toast(R.string.error_no_source) + } ?: toast(R.string.error_no_source) + } } fun saveBook(success: (() -> Unit)?) {