From ed3038b6d11092abbd0598b32a4090c9a6857dee Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Feb 2022 17:54:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/toc/ChapterListAdapter.kt | 32 +++++++++++-------- .../app/ui/book/toc/ChapterListFragment.kt | 3 ++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt index 0532877e8..45e24303b 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt @@ -6,19 +6,23 @@ import androidx.recyclerview.widget.DiffUtil import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter +import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ItemChapterListBinding -import io.legado.app.lib.theme.accentColor -import io.legado.app.lib.theme.backgroundColor +import io.legado.app.help.ContentProcessor import io.legado.app.lib.theme.ThemeUtils -import io.legado.app.help.AppConfig +import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatColor -import io.legado.app.utils.visible import io.legado.app.utils.gone +import io.legado.app.utils.visible class ChapterListAdapter(context: Context, val callback: Callback) : RecyclerAdapter(context) { + val replaceRules + get() = callback.book?.let { + ContentProcessor.get(it.name, it.origin).getReplaceRules() + } val cacheFileNames = hashSetOf() val diffCallBack = object : DiffUtil.ItemCallback() { @@ -28,12 +32,12 @@ class ChapterListAdapter(context: Context, val callback: Callback) : override fun areContentsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean { return oldItem.bookUrl == newItem.bookUrl - && oldItem.url == newItem.url - && oldItem.isVip == newItem.isVip - && oldItem.isPay == newItem.isPay - && oldItem.title == newItem.title - && oldItem.tag == newItem.tag - && oldItem.isVolume == newItem.isVolume + && oldItem.url == newItem.url + && oldItem.isVip == newItem.isVip + && oldItem.isPay == newItem.isPay + && oldItem.title == newItem.title + && oldItem.tag == newItem.tag + && oldItem.isVolume == newItem.isVolume } } @@ -57,16 +61,17 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } else { tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } - tvChapterName.text = item.getDisplayTitle() + tvChapterName.text = item.getDisplayTitle(replaceRules) if (item.isVolume) { //卷名,如第一卷 突出显示 tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) } else { //普通章节 保持不变 - tvChapterItem.setBackground(ThemeUtils.resolveDrawable(context, android.R.attr.selectableItemBackground)) + tvChapterItem.background = + ThemeUtils.resolveDrawable(context, android.R.attr.selectableItemBackground) } if (!item.tag.isNullOrEmpty() && !item.isVolume) { - //卷名不显示tag(更新时间规则) + //卷名不显示tag(更新时间规则) tvTag.text = item.tag tvTag.visible() } else { @@ -98,6 +103,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } interface Callback { + val book: Book? val isLocalBook: Boolean fun openChapter(bookChapter: BookChapter) fun durChapterIndex(): Int diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index af1bd83bd..d3154e64f 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -121,6 +121,9 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } } + override val book: Book? + get() = viewModel.bookData.value + override val isLocalBook: Boolean get() = viewModel.bookData.value?.isLocalBook() == true