pull/416/head
gedoor 4 years ago
parent 3ff960bd39
commit 8992d5b027
  1. 10
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -102,7 +102,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
book: Book, book: Book,
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null, changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null,
) { ) {
execute {
if (book.isLocalBook()) { if (book.isLocalBook()) {
loadChapterList(book, changeDruChapterIndex) loadChapterList(book, changeDruChapterIndex)
} else { } else {
@ -112,14 +111,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} }
} }
}
fun loadChapterList( fun loadChapterList(
book: Book, book: Book,
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null, changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null,
) { ) {
execute {
if (book.isLocalBook()) { if (book.isLocalBook()) {
execute {
LocalBook.getChapterList(book).let { LocalBook.getChapterList(book).let {
App.db.bookChapterDao().delByBook(book.bookUrl) App.db.bookChapterDao().delByBook(book.bookUrl)
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao().insert(*it.toTypedArray())
@ -132,6 +130,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
} }
} }
}.onError {
ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
}
} else { } else {
ReadBook.webBook?.getChapterList(book, this) ReadBook.webBook?.getChapterList(book, this)
?.onSuccess(IO) { cList -> ?.onSuccess(IO) { cList ->
@ -152,9 +153,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.upMsg(context.getString(R.string.error_load_toc)) ReadBook.upMsg(context.getString(R.string.error_load_toc))
} }
} }
}.onError {
ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
}
} }
fun changeTo(newBook: Book) { fun changeTo(newBook: Book) {

Loading…
Cancel
Save