From c6aef445e920ed1ce607326cf94045ce8c17c465 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 12 Nov 2022 23:26:35 +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 --- .../main/java/io/legado/app/help/book/BookExtensions.kt | 8 ++++++++ .../java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 9 +++++---- app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 5 +++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/book/BookExtensions.kt b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt index de23f1897..148c63b67 100644 --- a/app/src/main/java/io/legado/app/help/book/BookExtensions.kt +++ b/app/src/main/java/io/legado/app/help/book/BookExtensions.kt @@ -6,6 +6,7 @@ import android.net.Uri import io.legado.app.constant.BookSourceType import io.legado.app.constant.BookType import io.legado.app.data.appDb +import io.legado.app.data.entities.BaseBook import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException @@ -198,3 +199,10 @@ fun Book.sync(oldBook: Book) { durChapterTitle = curBook.durChapterTitle canUpdate = curBook.canUpdate } + +fun Book.isSameNameAuthor(other: Any?): Boolean { + if (other is BaseBook) { + return name == other.name && author == other.author + } + return false +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 534afef54..982fa6645 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -15,10 +15,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException -import io.legado.app.help.book.BookHelp -import io.legado.app.help.book.getRemoteUrl -import io.legado.app.help.book.isLocal -import io.legado.app.help.book.removeType +import io.legado.app.help.book.* import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.webdav.ObjectNotFoundException import io.legado.app.model.BookCover @@ -201,6 +198,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } appDb.bookChapterDao.delByBook(oldBook.bookUrl) appDb.bookChapterDao.insert(*it.toTypedArray()) + if (book.isSameNameAuthor(ReadBook.book)) { + ReadBook.book = book + ReadBook.chapterSize = book.totalChapterNum + } } chapterListData.postValue(it) }.onError { 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 1f2d753d0..b04240084 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 @@ -16,6 +16,7 @@ import io.legado.app.help.book.* import io.legado.app.help.config.AppConfig import io.legado.app.help.config.LocalConfig import io.legado.app.model.CacheBook +import io.legado.app.model.ReadBook import io.legado.app.model.webBook.WebBook import io.legado.app.service.CacheBookService import io.legado.app.utils.postEvent @@ -138,6 +139,10 @@ class MainViewModel(application: Application) : BaseViewModel(application) { } appDb.bookChapterDao.delByBook(bookUrl) appDb.bookChapterDao.insert(*toc.toTypedArray()) + if (book.isSameNameAuthor(ReadBook)) { + ReadBook.book = book + ReadBook.chapterSize = book.totalChapterNum + } addDownload(source, book) }.onFailure { AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it)