[新增] 增加书籍备注功能 #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
File diff suppressed because it is too large Load Diff
@@ -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 {
@@ -340,6 +340,33 @@
app:layout_constraintStart_toEndOf="@id/div"
tools:text="@string/read_chapter_index" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/cd_remark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
app:cardBackgroundColor="@android:color/transparent"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/tv_chapter">
<TextView
android:id="@+id/tv_remark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:layout_margin="12dp"
android:lineSpacingExtra="4dp"
android:text="@string/book_intro"
android:textIsSelectable="true"
android:textSize="12sp"
tools:text="@string/book_intro" />
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="@+id/tv_detail"
android:layout_width="0dp"
@@ -356,7 +383,7 @@
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_chapter"
app:layout_constraintTop_toBottomOf="@id/cd_remark"
tools:text="@string/book_intro" />
</androidx.constraintlayout.widget.ConstraintLayout>
+30 -7
View File
@@ -72,7 +72,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_gradient_mask"
android:paddingTop="8dp"
android:paddingBottom="4dp"
app:layout_constraintTop_toTopOf="parent">
@@ -235,7 +234,6 @@
app:iconPadding="4dp"
app:iconSize="20dp" />
<!-- 查看目录按钮 -->
<com.google.android.material.button.MaterialButton
android:id="@+id/tv_toc_view"
style="@style/Widget.Material3Expressive.Button.TextButton"
@@ -251,7 +249,6 @@
app:iconPadding="4dp"
app:iconSize="20dp" />
<!-- 更换分组按钮 -->
<com.google.android.material.button.MaterialButton
android:id="@+id/tv_change_group"
style="@style/Widget.Material3Expressive.Button.TextButton"
@@ -267,7 +264,6 @@
app:iconPadding="4dp"
app:iconSize="20dp" />
<!-- 更换来源按钮(保持原样) -->
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_change_source"
style="@style/Widget.Material3Expressive.Button.TextButton"
@@ -310,7 +306,6 @@
app:layout_constraintTop_toBottomOf="@id/tv_toc"
tools:text="@string/read_dur_progress" />
<TextView
android:id="@+id/tv_chapter"
android:layout_width="wrap_content"
@@ -349,12 +344,40 @@
app:layout_constraintStart_toEndOf="@id/div"
tools:text="@string/read_chapter_index" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/cd_remark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
app:cardBackgroundColor="@android:color/transparent"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/tv_chapter">
<TextView
android:id="@+id/tv_remark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:layout_margin="12dp"
android:lineSpacingExtra="4dp"
android:text="@string/book_intro"
android:textIsSelectable="true"
android:textSize="12sp"
tools:text="@string/book_intro" />
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="@+id/tv_detail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:layout_marginTop="8dp"
android:paddingBottom="120dp"
android:clickable="true"
android:focusable="true"
@@ -365,7 +388,7 @@
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_chapter"
app:layout_constraintTop_toBottomOf="@id/cd_remark"
tools:text="@string/book_intro" />
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -168,6 +168,22 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_remark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
style="@style/Widget.Material3.TextInputLayout.FilledBox.Dense"
android:hint="@string/book_remark"
app:layout_constraintTop_toBottomOf="@id/til_book_jj">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tie_remark"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
+2
View File
@@ -1360,4 +1360,6 @@
<string name="cover_show_stroke">显示字体描边</string>
<string name="default_color">使用默认字体颜色</string>
<string name="enable_slider_vibrator">滑动进度条时震动</string>
<string name="edit_remark">编辑备注</string>
<string name="book_remark">书籍备注</string>
</resources>
+2
View File
@@ -1363,4 +1363,6 @@
<string name="cover_show_stroke">显示字体描边</string>
<string name="default_color">使用默认字体颜色</string>
<string name="enable_slider_vibrator">滑动进度条时震动</string>
<string name="edit_remark">编辑备注</string>
<string name="book_remark">书籍备注</string>
</resources>