This commit is contained in:
Horis
2025-04-09 19:27:48 +08:00
parent 70f40fd90e
commit fda149811b
3 changed files with 40 additions and 25 deletions
@@ -95,7 +95,6 @@ abstract class BaseBooksAdapter<VH : RecyclerView.ViewHolder>(
if (bundle.isEmpty) return null if (bundle.isEmpty) return null
return bundle return bundle
} }
} }
private val asyncListDiffer by lazy { private val asyncListDiffer by lazy {
@@ -34,10 +34,12 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
) { ) {
when (holder) { when (holder) {
is BookViewHolder -> (getItem(position) as? Book)?.let { is BookViewHolder -> (getItem(position) as? Book)?.let {
holder.registerListener(position)
holder.onBind(it, position, payloads) holder.onBind(it, position, payloads)
} }
is GroupViewHolder -> (getItem(position) as? BookGroup)?.let { is GroupViewHolder -> (getItem(position) as? BookGroup)?.let {
holder.registerListener(position)
holder.onBind(it, position, payloads) holder.onBind(it, position, payloads)
} }
} }
@@ -50,12 +52,6 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
tvName.text = item.name tvName.text = item.name
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin) ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
upRefresh(this, item) upRefresh(this, item)
root.setOnClickListener {
callBack.onItemClick(position)
}
root.onLongClick {
callBack.onItemLongClick(position)
}
} }
fun onBind(item: Book, position: Int, payloads: MutableList<Any>) = binding.run { fun onBind(item: Book, position: Int, payloads: MutableList<Any>) = binding.run {
@@ -82,6 +78,15 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
} }
} }
fun registerListener(position: Int) {
binding.root.setOnClickListener {
callBack.onItemClick(position)
}
binding.root.onLongClick {
callBack.onItemLongClick(position)
}
}
private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) { private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) { if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
binding.bvUnread.invisible() binding.bvUnread.invisible()
@@ -105,12 +110,6 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
fun onBind(item: BookGroup, position: Int) = binding.run { fun onBind(item: BookGroup, position: Int) = binding.run {
tvName.text = item.groupName tvName.text = item.groupName
ivCover.load(item.cover) ivCover.load(item.cover)
root.setOnClickListener {
callBack.onItemClick(position)
}
root.onLongClick {
callBack.onItemLongClick(position)
}
} }
fun onBind(item: BookGroup, position: Int, payloads: MutableList<Any>) = binding.run { fun onBind(item: BookGroup, position: Int, payloads: MutableList<Any>) = binding.run {
@@ -129,6 +128,15 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
} }
} }
fun registerListener(position: Int) {
binding.root.setOnClickListener {
callBack.onItemClick(position)
}
binding.root.onLongClick {
callBack.onItemLongClick(position)
}
}
} }
} }
@@ -33,10 +33,12 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
) { ) {
when (holder) { when (holder) {
is BookViewHolder -> (getItem(position) as? Book)?.let { is BookViewHolder -> (getItem(position) as? Book)?.let {
holder.registerListener(position)
holder.onBind(it, position, payloads) holder.onBind(it, position, payloads)
} }
is GroupViewHolder -> (getItem(position) as? BookGroup)?.let { is GroupViewHolder -> (getItem(position) as? BookGroup)?.let {
holder.registerListener(position)
holder.onBind(it, position, payloads) holder.onBind(it, position, payloads)
} }
} }
@@ -56,12 +58,6 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
ivLast.visible() ivLast.visible()
ivRead.visible() ivRead.visible()
upRefresh(this, item) upRefresh(this, item)
root.setOnClickListener {
callBack.onItemClick(position)
}
root.onLongClick {
callBack.onItemLongClick(position)
}
} }
fun onBind(item: Book, position: Int, payloads: MutableList<Any>) = binding.run { fun onBind(item: Book, position: Int, payloads: MutableList<Any>) = binding.run {
@@ -91,6 +87,15 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
} }
} }
fun registerListener(position: Int) {
binding.root.setOnClickListener {
callBack.onItemClick(position)
}
binding.root.onLongClick {
callBack.onItemLongClick(position)
}
}
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) { private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) { if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
binding.bvUnread.invisible() binding.bvUnread.invisible()
@@ -121,12 +126,6 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
tvAuthor.gone() tvAuthor.gone()
tvLast.gone() tvLast.gone()
tvRead.gone() tvRead.gone()
root.setOnClickListener {
callBack.onItemClick(position)
}
root.onLongClick {
callBack.onItemLongClick(position)
}
} }
fun onBind(item: BookGroup, position: Int, payloads: MutableList<Any>) = binding.run { fun onBind(item: BookGroup, position: Int, payloads: MutableList<Any>) = binding.run {
@@ -145,6 +144,15 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
} }
} }
fun registerListener(position: Int) {
binding.root.setOnClickListener {
callBack.onItemClick(position)
}
binding.root.onLongClick {
callBack.onItemLongClick(position)
}
}
} }
} }