Przeglądaj źródła

Fix book info variable update

Horis 1 rok temu
rodzic
commit
b6d26fd418

+ 2 - 2
app/src/main/java/io/legado/app/data/dao/BookDao.kt

@@ -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 

+ 0 - 15
app/src/main/java/io/legado/app/data/entities/Book.kt

@@ -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,

+ 21 - 0
app/src/main/java/io/legado/app/help/book/BookExtensions.kt

@@ -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)
 }

+ 2 - 2
app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@@ -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
                              */