[新增] 增加书籍备注功能 #425

This commit is contained in:
HapeLee
2025-12-19 01:56:08 +08:00
parent ca9f4966d6
commit e3d6a063e6
12 changed files with 2049 additions and 15 deletions
@@ -67,7 +67,7 @@ val appDb by lazy {
}
@Database(
version = 79,
version = 80,
exportSchema = true,
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
@@ -112,7 +112,8 @@ val appDb by lazy {
AutoMigration(from = 75, to = 76),
AutoMigration(from = 76, to = 77),
AutoMigration(from = 77, to = 78),
AutoMigration(from = 78, to = 79)
AutoMigration(from = 78, to = 79),
AutoMigration(from = 79, to = 80)
]
)
abstract class AppDatabase : RoomDatabase() {
@@ -67,6 +67,7 @@ data class Book(
var intro: String? = null,
// 简介内容(用户修改)
var customIntro: String? = null,
var remark: String? = null,
// 自定义字符集名称(仅适用于本地书籍)
var charset: String? = null,
// 类型,详见BookType
@@ -346,6 +346,7 @@ fun Book.getExportFileName(suffix: String): String {
inside.equals("author", ignoreCase = true) -> getRealAuthor()
inside.equals("group", ignoreCase = true) -> group
inside.equals("source", ignoreCase = true) -> originName
inside.equals("remark", ignoreCase = true) -> remark
else -> null
}
@@ -521,7 +521,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private fun alertExportFileName() {
alert(R.string.export_file_name) {
val message = """
支持变量:{name}(书名)、{author}(作者)、{group}(分组)、{source}(书源)。
支持变量:{name}(书名)、{author}(作者)、{group}(分组)、{source}(书源)、{remark}(备注)
可以在字段前后加任意字符。
示例:
@@ -45,6 +45,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ActivityBookInfoBinding
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.AppWebDav
import io.legado.app.help.book.addType
@@ -396,13 +397,13 @@ class BookInfoActivity :
book.removeType(BookType.notShelf)
book.save()
viewModel.inBookshelf = true
super.finish()
super.finishAfterTransition()
}
noButton { super.finish() }
noButton { super.finishAfterTransition() }
}
}
} else {
finish()
finishAfterTransition()
}
}
}
@@ -440,6 +441,11 @@ class BookInfoActivity :
showCover(book)
addColorScheme(binding.ivCover.drawable)
tvName.text = book.name
tvRemark.text = book.remark
if (book.remark == null)
cdRemark.gone()
else
cdRemark.visible()
tvAuthor.text = getString(R.string.author_show, book.getRealAuthor())
tvOrigin.text = getString(R.string.origin_show, book.originName)
tvLasted.text = getString(R.string.lasted_show, book.latestChapterTitle)
@@ -599,6 +605,7 @@ class BookInfoActivity :
val color = animation.animatedValue as Int
binding.lbKind.applyColorScheme(color, colorOnSurface)
binding.collTopBar.setContentScrimColor(color)
binding.cdRemark.strokeColor = color
}
}
@@ -618,6 +625,7 @@ class BookInfoActivity :
}
binding.div.setTextColor(color)
binding.tvChapterIndex.setTextColor(color)
binding.tvRemark.setTextColor(color)
}
}
@@ -844,7 +852,19 @@ class BookInfoActivity :
tvName.maxLines = if (tvName.maxLines == 3) 10 else 3
true
}
cdRemark.setOnClickListener {
alert(R.string.edit_remark) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editLayout.hint = "编辑备注"
editView.setText(book?.remark)
}
customView { alertBinding.root }
okButton {
viewModel.saveRemark(alertBinding.editView.text.toString())
}
cancelButton()
}
}
refreshLayout.setOnRefreshListener {
refreshLayout.isRefreshing = false
refreshBook()
@@ -378,6 +378,17 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}
}
fun saveRemark(remark: String, success: (() -> Unit)? = null) {
execute {
bookData.value?.let {
it.remark = remark
it.save()
}
}.onSuccess {
success?.invoke()
}
}
fun saveBook(book: Book?, success: (() -> Unit)? = null) {
book ?: return
execute {