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