优化
This commit is contained in:
@@ -19,6 +19,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
|||||||
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
|
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
|
||||||
|
|
||||||
val cacheFileNames = hashSetOf<String>()
|
val cacheFileNames = hashSetOf<String>()
|
||||||
|
val displayTileMap = hashMapOf<Int, String>()
|
||||||
val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() {
|
val diffCallBack = object : DiffUtil.ItemCallback<BookChapter>() {
|
||||||
|
|
||||||
override fun areItemsTheSame(
|
override fun areItemsTheSame(
|
||||||
@@ -47,6 +48,16 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
|
|||||||
return ItemChapterListBinding.inflate(inflater, parent, false)
|
return ItemChapterListBinding.inflate(inflater, parent, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getDisplayTile(chapter: BookChapter): String {
|
||||||
|
var displayTile = displayTileMap[chapter.index]
|
||||||
|
if (displayTile != null) {
|
||||||
|
return displayTile
|
||||||
|
}
|
||||||
|
displayTile = chapter.getDisplayTitle()
|
||||||
|
displayTileMap[chapter.index] = displayTile
|
||||||
|
return displayTile
|
||||||
|
}
|
||||||
|
|
||||||
override fun convert(
|
override fun convert(
|
||||||
holder: ItemViewHolder,
|
holder: ItemViewHolder,
|
||||||
binding: ItemChapterListBinding,
|
binding: ItemChapterListBinding,
|
||||||
@@ -62,7 +73,7 @@ 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 = getDisplayTile(item)
|
||||||
if (item.isVolume) {
|
if (item.isVolume) {
|
||||||
//卷名,如第一卷 突出显示
|
//卷名,如第一卷 突出显示
|
||||||
tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press))
|
tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press))
|
||||||
|
|||||||
Reference in New Issue
Block a user