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 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 import io.legado.app.data.entities.BookChapter
@Dao @Dao
@ -28,7 +32,7 @@ interface BookChapterDao {
fun insert(vararg bookChapter: BookChapter) fun insert(vararg bookChapter: BookChapter)
@Update @Update
fun upDate(vararg bookChapter: BookChapter) fun update(vararg bookChapter: BookChapter)
@Query("delete from chapters where bookUrl = :bookUrl") @Query("delete from chapters where bookUrl = :bookUrl")
fun delByBook(bookUrl: String) fun delByBook(bookUrl: String)

View File

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

View File

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

View File

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