This commit is contained in:
Horis 2024-03-29 17:29:48 +08:00
parent 0eeedb44b7
commit 2b90015125
5 changed files with 30 additions and 14 deletions

View File

@ -1,6 +1,10 @@
package io.legado.app.data.dao
import androidx.room.*
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import io.legado.app.data.entities.BookChapter
@Dao
@ -28,7 +32,7 @@ interface BookChapterDao {
fun insert(vararg bookChapter: BookChapter)
@Update
fun upDate(vararg bookChapter: BookChapter)
fun update(vararg bookChapter: BookChapter)
@Query("delete from chapters where bookUrl = :bookUrl")
fun delByBook(bookUrl: String)

View File

@ -1,5 +1,6 @@
package io.legado.app.data.entities
import android.annotation.SuppressLint
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.ForeignKey
@ -64,11 +65,9 @@ data class BookChapter(
GSON.fromJsonObject<HashMap<String, String>>(variable).getOrNull() ?: hashMapOf()
}
@delegate:Ignore
@Ignore
@IgnoredOnParcel
private val titleMD5: String by lazy {
MD5Utils.md5Encode16(title)
}
var titleMD5: String? = null
override fun putVariable(key: String, value: String?): Boolean {
if (super.putVariable(key, value)) {
@ -158,12 +157,24 @@ data class BookChapter(
}
}
@Suppress("unused")
fun getFileName(suffix: String = "nb"): String =
String.format("%05d-%s.%s", index, titleMD5, suffix)
private fun ensureTitleMD5Init() {
if (titleMD5 == null) {
titleMD5 = MD5Utils.md5Encode16(title)
}
}
@SuppressLint("DefaultLocale")
@Suppress("unused")
fun getFontName(): String = String.format("%05d-%s.ttf", index, titleMD5)
fun getFileName(suffix: String = "nb"): String {
ensureTitleMD5Init()
return String.format("%05d-%s.%s", index, titleMD5, suffix)
}
@SuppressLint("DefaultLocale")
@Suppress("unused")
fun getFontName(): String {
ensureTitleMD5Init()
return String.format("%05d-%s.ttf", index, titleMD5)
}
}

View File

@ -183,7 +183,7 @@ object AudioPlay {
Coroutine.async {
durChapter?.let {
it.end = audioSize
appDb.bookChapterDao.upDate(it)
appDb.bookChapterDao.update(it)
}
}
}

View File

@ -69,7 +69,8 @@ object BookContent {
}.getOrNull()
if (!title.isNullOrBlank()) {
bookChapter.title = title
appDb.bookChapterDao.upDate(bookChapter)
bookChapter.titleMD5 = null
appDb.bookChapterDao.update(bookChapter)
}
}
var contentData = analyzeContent(

View File

@ -106,7 +106,7 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) {
chapter.title = alertBinding.editView.text.toString()
lifecycleScope.launch {
withContext(IO) {
appDb.bookChapterDao.upDate(chapter)
appDb.bookChapterDao.update(chapter)
}
binding.toolBar.title = chapter.getDisplayTitle()
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)