Fix book info variable update

This commit is contained in:
Horis
2025-02-06 15:52:40 +08:00
parent 176796b257
commit 0fedecdbea
4 changed files with 25 additions and 19 deletions

View File

@@ -129,8 +129,8 @@ interface BookDao {
@get:Query("select max(`order`) from books")
val maxOrder: Int
@Query("select 1 from books where bookUrl = :bookUrl")
fun has(bookUrl: String): Boolean?
@Query("select exists(select 1 from books where bookUrl = :bookUrl)")
fun has(bookUrl: String): Boolean
@Query(
"""select exists(select 1 from books where type & ${BookType.local} > 0

View File

@@ -364,21 +364,6 @@ data class Book(
return newBook
}
fun updateTo(newBook: Book): Book {
newBook.durChapterIndex = durChapterIndex
newBook.durChapterTitle = durChapterTitle
newBook.durChapterPos = durChapterPos
newBook.durChapterTime = durChapterTime
newBook.group = group
newBook.order = order
newBook.customCoverUrl = customCoverUrl
newBook.customIntro = customIntro
newBook.customTag = customTag
newBook.canUpdate = canUpdate
newBook.readConfig = readConfig
return newBook
}
fun createBookMark(): Bookmark {
return Bookmark(
bookName = name,

View File

@@ -16,6 +16,7 @@ import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.config.AppConfig
import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.FileDoc
import io.legado.app.utils.GSON
import io.legado.app.utils.exists
import io.legado.app.utils.find
import io.legado.app.utils.inputStream
@@ -256,6 +257,26 @@ fun Book.update() {
appDb.bookDao.update(this)
}
fun Book.updateTo(newBook: Book): Book {
newBook.durChapterIndex = durChapterIndex
newBook.durChapterTitle = durChapterTitle
newBook.durChapterPos = durChapterPos
newBook.durChapterTime = durChapterTime
newBook.group = group
newBook.order = order
newBook.customCoverUrl = customCoverUrl
newBook.customIntro = customIntro
newBook.customTag = customTag
newBook.canUpdate = canUpdate
newBook.readConfig = readConfig
val variableMap = variableMap.toMutableMap()
variableMap.putAll(newBook.variableMap)
newBook.variableMap.clear()
newBook.variableMap.putAll(variableMap)
newBook.variable = GSON.toJson(variableMap)
return newBook
}
fun Book.getBookSource(): BookSource? {
return appDb.bookSourceDao.getBookSource(origin)
}

View File

@@ -27,6 +27,7 @@ import io.legado.app.help.book.isSameNameAuthor
import io.legado.app.help.book.isWebFile
import io.legado.app.help.book.removeType
import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.book.updateTo
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.webdav.ObjectNotFoundException
import io.legado.app.model.AudioPlay
@@ -191,8 +192,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}
bookData.postValue(it)
if (inBookshelf) {
val dbBook1 = appDb.bookDao.getBook(it.bookUrl)
if (dbBook1 == null) {
if (!appDb.bookDao.has(it.bookUrl)) {
/**
* 来自搜索,同一本书,不同 bookUrl
*/