mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
0eeedb44b7
commit
2b90015125
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ object AudioPlay {
|
|||
Coroutine.async {
|
||||
durChapter?.let {
|
||||
it.end = audioSize
|
||||
appDb.bookChapterDao.upDate(it)
|
||||
appDb.bookChapterDao.update(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user