This commit is contained in:
kunfei 2023-02-27 22:19:18 +08:00
parent 1a99668a75
commit 768c79e7fa
2 changed files with 83 additions and 84 deletions

View File

@ -14,6 +14,7 @@ import io.legado.app.help.config.AppConfig
import io.legado.app.utils.invisible
import splitties.views.onLongClick
@Suppress("UNUSED_PARAMETER")
class BooksAdapterGrid(context: Context, callBack: CallBack) :
BaseBooksAdapter<RecyclerView.ViewHolder>(context, callBack) {
@ -43,7 +44,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
holder.onBind(it, bundle)
}
holder is GroupViewHolder -> (callBack.getItem(position) as? BookGroup)?.let {
holder.onBind(it, position)
holder.onBind(it, bundle)
}
}
}
@ -115,6 +116,11 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
}
}
fun onBind(item: BookGroup, bundle: Bundle) = binding.run {
tvName.text = item.groupName
ivCover.load(item.cover)
}
}
}

View File

@ -16,6 +16,7 @@ import io.legado.app.utils.invisible
import io.legado.app.utils.visible
import splitties.views.onLongClick
@Suppress("UNUSED_PARAMETER")
class BooksAdapterList(context: Context, callBack: CallBack) :
BaseBooksAdapter<RecyclerView.ViewHolder>(context, callBack) {
@ -38,73 +39,30 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
val bundle = payloads.getOrNull(0) as? Bundle
when {
bundle == null -> super.onBindViewHolder(holder, position, payloads)
holder is BookViewHolder -> onBindBook(holder.binding, position, bundle)
holder is GroupViewHolder -> onBindGroup(holder.binding, position, bundle)
}
}
private fun onBindGroup(
binding: ItemBookshelfListGroupBinding,
position: Int,
@Suppress("UNUSED_PARAMETER") bundle: Bundle
) {
binding.run {
val item = callBack.getItem(position) as BookGroup
tvName.text = item.groupName
ivCover.load(item.cover)
}
}
private fun onBindBook(binding: ItemBookshelfListBinding, position: Int, bundle: Bundle) {
binding.run {
val item = callBack.getItem(position) as? Book ?: return
tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle
bundle.keySet().forEach {
when (it) {
"name" -> tvName.text = item.name
"author" -> tvAuthor.text = item.author
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
"refresh" -> upRefresh(this, item)
holder is BookViewHolder -> (callBack.getItem(position) as? Book)?.let {
holder.onBind(it, bundle)
}
holder is GroupViewHolder -> (callBack.getItem(position) as? BookGroup)?.let {
holder.onBind(it, bundle)
}
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is BookViewHolder -> onBindBook(holder.binding, position)
is GroupViewHolder -> onBindGroup(holder.binding, position)
is BookViewHolder -> (callBack.getItem(position) as? Book)?.let {
holder.onBind(it, position)
}
}
private fun onBindGroup(binding: ItemBookshelfListGroupBinding, position: Int) {
binding.run {
val item = callBack.getItem(position)
if (item is BookGroup) {
tvName.text = item.groupName
ivCover.load(item.cover)
flHasNew.gone()
ivAuthor.gone()
ivLast.gone()
ivRead.gone()
tvAuthor.gone()
tvLast.gone()
tvRead.gone()
}
root.setOnClickListener {
callBack.onItemClick(position)
}
root.onLongClick {
callBack.onItemLongClick(position)
is GroupViewHolder -> (callBack.getItem(position) as? BookGroup)?.let {
holder.onBind(it, position)
}
}
}
private fun onBindBook(binding: ItemBookshelfListBinding, position: Int) {
binding.run {
val item = callBack.getItem(position)
if (item is Book) {
inner class BookViewHolder(val binding: ItemBookshelfListBinding) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(item: Book, position: Int) = binding.run{
tvName.text = item.name
tvAuthor.text = item.author
tvRead.text = item.durChapterTitle
@ -115,7 +73,6 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
ivLast.visible()
ivRead.visible()
upRefresh(this, item)
}
root.setOnClickListener {
callBack.onItemClick(position)
}
@ -123,6 +80,18 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
callBack.onItemLongClick(position)
}
}
fun onBind(item: Book, bundle: Bundle) = binding.run {
tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle
bundle.keySet().forEach {
when (it) {
"name" -> tvName.text = item.name
"author" -> tvAuthor.text = item.author
"cover" -> ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
"refresh" -> upRefresh(this, item)
}
}
}
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
@ -140,10 +109,34 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
}
}
class BookViewHolder(val binding: ItemBookshelfListBinding) :
RecyclerView.ViewHolder(binding.root)
}
class GroupViewHolder(val binding: ItemBookshelfListGroupBinding) :
RecyclerView.ViewHolder(binding.root)
inner class GroupViewHolder(val binding: ItemBookshelfListGroupBinding) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(item: BookGroup, position: Int) = binding.run{
tvName.text = item.groupName
ivCover.load(item.cover)
flHasNew.gone()
ivAuthor.gone()
ivLast.gone()
ivRead.gone()
tvAuthor.gone()
tvLast.gone()
tvRead.gone()
root.setOnClickListener {
callBack.onItemClick(position)
}
root.onLongClick {
callBack.onItemLongClick(position)
}
}
fun onBind(item: BookGroup, bundle: Bundle) = binding.run {
tvName.text = item.groupName
ivCover.load(item.cover)
}
}
}