From 228ae3666856a74cd30790f8963b9af45a42df8c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jun 2022 12:13:25 +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 --- .../java/io/legado/app/ui/main/MainViewModel.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 043c999de..45427b5e8 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -113,9 +113,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) { waitUpTocBooks.remove(book.bookUrl) return } - waitUpTocBooks.remove(book.bookUrl) - onUpTocBooks.add(book.bookUrl) - postEvent(EventBus.UP_BOOKSHELF, book.bookUrl) + waitUpTocBooks.remove(bookUrl) + onUpTocBooks.add(bookUrl) + postEvent(EventBus.UP_BOOKSHELF, bookUrl) execute(context = upTocPool) { val preUpdateJs = source.ruleToc?.preUpdateJs if (!preUpdateJs.isNullOrBlank()) { @@ -125,15 +125,22 @@ class MainViewModel(application: Application) : BaseViewModel(application) { WebBook.getBookInfoAwait(this, source, book) } val toc = WebBook.getChapterListAwait(this, source, book).getOrThrow() - appDb.bookDao.update(book) + if (book.bookUrl == bookUrl) { + appDb.bookDao.update(book) + } else { + onUpTocBooks.add(book.bookUrl) + appDb.bookDao.insert(book) + } appDb.bookChapterDao.delByBook(book.bookUrl) appDb.bookChapterDao.insert(*toc.toTypedArray()) addDownload(source, book) }.onError(upTocPool) { AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it) }.onCancel(upTocPool) { + upTocCancel(bookUrl) upTocCancel(book.bookUrl) }.onFinally(upTocPool) { + upTocFinally(bookUrl) upTocFinally(book.bookUrl) } }