pull/32/head
kunfei 5 years ago
parent 7395f84e0d
commit 03ec05297a
  1. 6
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt

@ -27,6 +27,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
val chapterList = App.db.bookChapterDao().getChapterList(it) val chapterList = App.db.bookChapterDao().getChapterList(it)
if (chapterList.isNotEmpty()) { if (chapterList.isNotEmpty()) {
chapterListData.postValue(chapterList) chapterListData.postValue(chapterList)
isLoadingData.postValue(false)
} else { } else {
loadChapter(book) loadChapter(book)
} }
@ -45,7 +46,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} }
fun loadBookInfo(book: Book) { fun loadBookInfo(book: Book) {
isLoadingData.postValue(false) isLoadingData.postValue(true)
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getBookInfo(book) WebBook(bookSource).getBookInfo(book)
.onSuccess { .onSuccess {
@ -57,7 +58,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} }
fun loadChapter(book: Book) { fun loadChapter(book: Book) {
isLoadingData.postValue(false) isLoadingData.postValue(true)
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getChapterList(book) WebBook(bookSource).getChapterList(book)
.onSuccess(IO) { .onSuccess(IO) {
@ -67,6 +68,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao().insert(*it.toTypedArray())
} }
chapterListData.postValue(it) chapterListData.postValue(it)
isLoadingData.postValue(false)
} }
} }
}.onError { }.onError {

Loading…
Cancel
Save