mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
6f9e970fb4
commit
c6aef445e9
@ -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
|
||||
}
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user