|
|
@@ -14,33 +14,31 @@ import io.legado.app.utils.getCompatColor
|
|
|
import io.legado.app.utils.gone
|
|
|
import io.legado.app.utils.visible
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
-import kotlinx.coroutines.Deferred
|
|
|
-import kotlinx.coroutines.launch
|
|
|
|
|
|
class ChapterListAdapter(context: Context, val callback: Callback) :
|
|
|
- RecyclerAdapter<Pair<BookChapter, Deferred<String>>, ItemChapterListBinding>(context) {
|
|
|
+ RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
|
|
|
|
|
|
val cacheFileNames = hashSetOf<String>()
|
|
|
- val diffCallBack = object : DiffUtil.ItemCallback<Pair<BookChapter, Deferred<String>>>() {
|
|
|
+ val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() {
|
|
|
|
|
|
override fun areItemsTheSame(
|
|
|
- oldItem: Pair<BookChapter, Deferred<String>>,
|
|
|
- newItem: Pair<BookChapter, Deferred<String>>
|
|
|
+ oldItem: BookChapter,
|
|
|
+ newItem: BookChapter
|
|
|
): Boolean {
|
|
|
- return oldItem.first.index == newItem.first.index
|
|
|
+ return oldItem.index == newItem.index
|
|
|
}
|
|
|
|
|
|
override fun areContentsTheSame(
|
|
|
- oldItem: Pair<BookChapter, Deferred<String>>,
|
|
|
- newItem: Pair<BookChapter, Deferred<String>>
|
|
|
+ oldItem: BookChapter,
|
|
|
+ newItem: BookChapter
|
|
|
): Boolean {
|
|
|
- return oldItem.first.bookUrl == newItem.first.bookUrl
|
|
|
- && oldItem.first.url == newItem.first.url
|
|
|
- && oldItem.first.isVip == newItem.first.isVip
|
|
|
- && oldItem.first.isPay == newItem.first.isPay
|
|
|
- && oldItem.first.title == newItem.first.title
|
|
|
- && oldItem.first.tag == newItem.first.tag
|
|
|
- && oldItem.first.isVolume == newItem.first.isVolume
|
|
|
+ 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
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -52,22 +50,20 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
|
|
override fun convert(
|
|
|
holder: ItemViewHolder,
|
|
|
binding: ItemChapterListBinding,
|
|
|
- item: Pair<BookChapter, Deferred<String>>,
|
|
|
+ item: BookChapter,
|
|
|
payloads: MutableList<Any>
|
|
|
) {
|
|
|
binding.run {
|
|
|
- val isDur = callback.durChapterIndex() == item.first.index
|
|
|
- val cached = callback.isLocalBook || cacheFileNames.contains(item.first.getFileName())
|
|
|
+ val isDur = callback.durChapterIndex() == item.index
|
|
|
+ val cached = callback.isLocalBook || cacheFileNames.contains(item.getFileName())
|
|
|
if (payloads.isEmpty()) {
|
|
|
if (isDur) {
|
|
|
tvChapterName.setTextColor(context.accentColor)
|
|
|
} else {
|
|
|
tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText))
|
|
|
}
|
|
|
- callback.scope.launch {
|
|
|
- tvChapterName.text = item.second.await()
|
|
|
- }
|
|
|
- if (item.first.isVolume) {
|
|
|
+ tvChapterName.text = item.getDisplayTitle()
|
|
|
+ if (item.isVolume) {
|
|
|
//卷名,如第一卷 突出显示
|
|
|
tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press))
|
|
|
} else {
|
|
|
@@ -75,9 +71,9 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
|
|
tvChapterItem.background =
|
|
|
ThemeUtils.resolveDrawable(context, android.R.attr.selectableItemBackground)
|
|
|
}
|
|
|
- if (!item.first.tag.isNullOrEmpty() && !item.first.isVolume) {
|
|
|
+ if (!item.tag.isNullOrEmpty() && !item.isVolume) {
|
|
|
//卷名不显示tag(更新时间规则)
|
|
|
- tvTag.text = item.first.tag
|
|
|
+ tvTag.text = item.tag
|
|
|
tvTag.visible()
|
|
|
} else {
|
|
|
tvTag.gone()
|
|
|
@@ -92,7 +88,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
|
|
override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) {
|
|
|
holder.itemView.setOnClickListener {
|
|
|
getItem(holder.layoutPosition)?.let {
|
|
|
- callback.openChapter(it.first)
|
|
|
+ callback.openChapter(it)
|
|
|
}
|
|
|
}
|
|
|
}
|