pull/2565/head
kunfei 2 years ago
parent 6f9e970fb4
commit c6aef445e9
  1. 8
      app/src/main/java/io/legado/app/help/book/BookExtensions.kt
  2. 9
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  3. 5
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -6,6 +6,7 @@ import android.net.Uri
import io.legado.app.constant.BookSourceType import io.legado.app.constant.BookSourceType
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.appDb 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.Book
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
@ -198,3 +199,10 @@ fun Book.sync(oldBook: Book) {
durChapterTitle = curBook.durChapterTitle durChapterTitle = curBook.durChapterTitle
canUpdate = curBook.canUpdate canUpdate = curBook.canUpdate
} }
fun Book.isSameNameAuthor(other: Any?): Boolean {
if (other is BaseBook) {
return name == other.name && author == other.author
}
return false
}

@ -15,10 +15,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.book.BookHelp import io.legado.app.help.book.*
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.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.webdav.ObjectNotFoundException import io.legado.app.lib.webdav.ObjectNotFoundException
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
@ -201,6 +198,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} }
appDb.bookChapterDao.delByBook(oldBook.bookUrl) appDb.bookChapterDao.delByBook(oldBook.bookUrl)
appDb.bookChapterDao.insert(*it.toTypedArray()) appDb.bookChapterDao.insert(*it.toTypedArray())
if (book.isSameNameAuthor(ReadBook.book)) {
ReadBook.book = book
ReadBook.chapterSize = book.totalChapterNum
}
} }
chapterListData.postValue(it) chapterListData.postValue(it)
}.onError { }.onError {

@ -16,6 +16,7 @@ import io.legado.app.help.book.*
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.LocalConfig
import io.legado.app.model.CacheBook import io.legado.app.model.CacheBook
import io.legado.app.model.ReadBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.CacheBookService import io.legado.app.service.CacheBookService
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
@ -138,6 +139,10 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} }
appDb.bookChapterDao.delByBook(bookUrl) appDb.bookChapterDao.delByBook(bookUrl)
appDb.bookChapterDao.insert(*toc.toTypedArray()) appDb.bookChapterDao.insert(*toc.toTypedArray())
if (book.isSameNameAuthor(ReadBook)) {
ReadBook.book = book
ReadBook.chapterSize = book.totalChapterNum
}
addDownload(source, book) addDownload(source, book)
}.onFailure { }.onFailure {
AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it) AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it)

Loading…
Cancel
Save