pull/1581/head
kunfei 3 years ago
parent 35dfa58f9d
commit ed3038b6d1
  1. 18
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt

@ -6,19 +6,23 @@ import androidx.recyclerview.widget.DiffUtil
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter 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.data.entities.BookChapter
import io.legado.app.databinding.ItemChapterListBinding import io.legado.app.databinding.ItemChapterListBinding
import io.legado.app.lib.theme.accentColor import io.legado.app.help.ContentProcessor
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.ThemeUtils 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.getCompatColor
import io.legado.app.utils.visible
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible
class ChapterListAdapter(context: Context, val callback: Callback) : class ChapterListAdapter(context: Context, val callback: Callback) :
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) { RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
val replaceRules
get() = callback.book?.let {
ContentProcessor.get(it.name, it.origin).getReplaceRules()
}
val cacheFileNames = hashSetOf<String>() val cacheFileNames = hashSetOf<String>()
val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() { val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() {
@ -57,13 +61,14 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
} else { } else {
tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText))
} }
tvChapterName.text = item.getDisplayTitle() tvChapterName.text = item.getDisplayTitle(replaceRules)
if (item.isVolume) { if (item.isVolume) {
//卷名,如第一卷 突出显示 //卷名,如第一卷 突出显示
tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press))
} else { } 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) { if (!item.tag.isNullOrEmpty() && !item.isVolume) {
//卷名不显示tag(更新时间规则) //卷名不显示tag(更新时间规则)
@ -98,6 +103,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
} }
interface Callback { interface Callback {
val book: Book?
val isLocalBook: Boolean val isLocalBook: Boolean
fun openChapter(bookChapter: BookChapter) fun openChapter(bookChapter: BookChapter)
fun durChapterIndex(): Int fun durChapterIndex(): Int

@ -121,6 +121,9 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(R.layout.fragment_chapt
} }
} }
override val book: Book?
get() = viewModel.bookData.value
override val isLocalBook: Boolean override val isLocalBook: Boolean
get() = viewModel.bookData.value?.isLocalBook() == true get() = viewModel.bookData.value?.isLocalBook() == true

Loading…
Cancel
Save