From 8992d5b02707bad2d648045e4ff06bcc2fdf7b22 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 4 Oct 2020 16:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookViewModel.kt | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index e2ff19199..1bf00e95a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -102,15 +102,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { book: Book, changeDruChapterIndex: ((chapters: List) -> Unit)? = null, ) { - execute { - if (book.isLocalBook()) { - loadChapterList(book, changeDruChapterIndex) - } else { - ReadBook.webBook?.getBookInfo(book, this, canReName = false) - ?.onSuccess { - loadChapterList(book, changeDruChapterIndex) - } - } + if (book.isLocalBook()) { + loadChapterList(book, changeDruChapterIndex) + } else { + ReadBook.webBook?.getBookInfo(book, this, canReName = false) + ?.onSuccess { + loadChapterList(book, changeDruChapterIndex) + } } } @@ -118,8 +116,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { book: Book, changeDruChapterIndex: ((chapters: List) -> Unit)? = null, ) { - execute { - if (book.isLocalBook()) { + if (book.isLocalBook()) { + execute { LocalBook.getChapterList(book).let { App.db.bookChapterDao().delByBook(book.bookUrl) App.db.bookChapterDao().insert(*it.toTypedArray()) @@ -132,28 +130,28 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { ReadBook.loadContent(resetPageOffset = true) } } - } else { - ReadBook.webBook?.getChapterList(book, this) - ?.onSuccess(IO) { cList -> - if (cList.isNotEmpty()) { - if (changeDruChapterIndex == null) { - App.db.bookChapterDao().insert(*cList.toTypedArray()) - App.db.bookDao().update(book) - ReadBook.chapterSize = cList.size - ReadBook.upMsg(null) - ReadBook.loadContent(resetPageOffset = true) - } else { - changeDruChapterIndex(cList) - } + }.onError { + ReadBook.upMsg("LoadTocError:${it.localizedMessage}") + } + } else { + ReadBook.webBook?.getChapterList(book, this) + ?.onSuccess(IO) { cList -> + if (cList.isNotEmpty()) { + if (changeDruChapterIndex == null) { + App.db.bookChapterDao().insert(*cList.toTypedArray()) + App.db.bookDao().update(book) + ReadBook.chapterSize = cList.size + ReadBook.upMsg(null) + ReadBook.loadContent(resetPageOffset = true) } else { - ReadBook.upMsg(context.getString(R.string.error_load_toc)) + changeDruChapterIndex(cList) } - }?.onError { + } else { ReadBook.upMsg(context.getString(R.string.error_load_toc)) } - } - }.onError { - ReadBook.upMsg("LoadTocError:${it.localizedMessage}") + }?.onError { + ReadBook.upMsg(context.getString(R.string.error_load_toc)) + } } }