mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
1a99668a75
commit
768c79e7fa
@ -14,6 +14,7 @@ import io.legado.app.help.config.AppConfig
|
|||||||
import io.legado.app.utils.invisible
|
import io.legado.app.utils.invisible
|
||||||
import splitties.views.onLongClick
|
import splitties.views.onLongClick
|
||||||
|
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
class BooksAdapterGrid(context: Context, callBack: CallBack) :
|
class BooksAdapterGrid(context: Context, callBack: CallBack) :
|
||||||
BaseBooksAdapter<RecyclerView.ViewHolder>(context, callBack) {
|
BaseBooksAdapter<RecyclerView.ViewHolder>(context, callBack) {
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
|
|||||||
holder.onBind(it, bundle)
|
holder.onBind(it, bundle)
|
||||||
}
|
}
|
||||||
holder is GroupViewHolder -> (callBack.getItem(position) as? BookGroup)?.let {
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,6 +16,7 @@ import io.legado.app.utils.invisible
|
|||||||
import io.legado.app.utils.visible
|
import io.legado.app.utils.visible
|
||||||
import splitties.views.onLongClick
|
import splitties.views.onLongClick
|
||||||
|
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
class BooksAdapterList(context: Context, callBack: CallBack) :
|
class BooksAdapterList(context: Context, callBack: CallBack) :
|
||||||
BaseBooksAdapter<RecyclerView.ViewHolder>(context, callBack) {
|
BaseBooksAdapter<RecyclerView.ViewHolder>(context, callBack) {
|
||||||
|
|
||||||
@ -38,26 +39,49 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
|
|||||||
val bundle = payloads.getOrNull(0) as? Bundle
|
val bundle = payloads.getOrNull(0) as? Bundle
|
||||||
when {
|
when {
|
||||||
bundle == null -> super.onBindViewHolder(holder, position, payloads)
|
bundle == null -> super.onBindViewHolder(holder, position, payloads)
|
||||||
holder is BookViewHolder -> onBindBook(holder.binding, position, bundle)
|
holder is BookViewHolder -> (callBack.getItem(position) as? Book)?.let {
|
||||||
holder is GroupViewHolder -> onBindGroup(holder.binding, position, bundle)
|
holder.onBind(it, bundle)
|
||||||
|
}
|
||||||
|
holder is GroupViewHolder -> (callBack.getItem(position) as? BookGroup)?.let {
|
||||||
|
holder.onBind(it, bundle)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onBindGroup(
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
binding: ItemBookshelfListGroupBinding,
|
when (holder) {
|
||||||
position: Int,
|
is BookViewHolder -> (callBack.getItem(position) as? Book)?.let {
|
||||||
@Suppress("UNUSED_PARAMETER") bundle: Bundle
|
holder.onBind(it, position)
|
||||||
) {
|
}
|
||||||
binding.run {
|
is GroupViewHolder -> (callBack.getItem(position) as? BookGroup)?.let {
|
||||||
val item = callBack.getItem(position) as BookGroup
|
holder.onBind(it, position)
|
||||||
tvName.text = item.groupName
|
}
|
||||||
ivCover.load(item.cover)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onBindBook(binding: ItemBookshelfListBinding, position: Int, bundle: Bundle) {
|
inner class BookViewHolder(val binding: ItemBookshelfListBinding) :
|
||||||
binding.run {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
val item = callBack.getItem(position) as? Book ?: return
|
|
||||||
|
fun onBind(item: Book, position: Int) = binding.run{
|
||||||
|
tvName.text = item.name
|
||||||
|
tvAuthor.text = item.author
|
||||||
|
tvRead.text = item.durChapterTitle
|
||||||
|
tvLast.text = item.latestChapterTitle
|
||||||
|
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
|
||||||
|
flHasNew.visible()
|
||||||
|
ivAuthor.visible()
|
||||||
|
ivLast.visible()
|
||||||
|
ivRead.visible()
|
||||||
|
upRefresh(this, item)
|
||||||
|
root.setOnClickListener {
|
||||||
|
callBack.onItemClick(position)
|
||||||
|
}
|
||||||
|
root.onLongClick {
|
||||||
|
callBack.onItemLongClick(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onBind(item: Book, bundle: Bundle) = binding.run {
|
||||||
tvRead.text = item.durChapterTitle
|
tvRead.text = item.durChapterTitle
|
||||||
tvLast.text = item.latestChapterTitle
|
tvLast.text = item.latestChapterTitle
|
||||||
bundle.keySet().forEach {
|
bundle.keySet().forEach {
|
||||||
@ -69,81 +93,50 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
|
||||||
when (holder) {
|
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
|
||||||
is BookViewHolder -> onBindBook(holder.binding, position)
|
|
||||||
is GroupViewHolder -> onBindGroup(holder.binding, 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onBindBook(binding: ItemBookshelfListBinding, position: Int) {
|
|
||||||
binding.run {
|
|
||||||
val item = callBack.getItem(position)
|
|
||||||
if (item is Book) {
|
|
||||||
tvName.text = item.name
|
|
||||||
tvAuthor.text = item.author
|
|
||||||
tvRead.text = item.durChapterTitle
|
|
||||||
tvLast.text = item.latestChapterTitle
|
|
||||||
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
|
|
||||||
flHasNew.visible()
|
|
||||||
ivAuthor.visible()
|
|
||||||
ivLast.visible()
|
|
||||||
ivRead.visible()
|
|
||||||
upRefresh(this, item)
|
|
||||||
}
|
|
||||||
root.setOnClickListener {
|
|
||||||
callBack.onItemClick(position)
|
|
||||||
}
|
|
||||||
root.onLongClick {
|
|
||||||
callBack.onItemLongClick(position)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
|
|
||||||
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
|
|
||||||
binding.bvUnread.invisible()
|
|
||||||
binding.rlLoading.visible()
|
|
||||||
} else {
|
|
||||||
binding.rlLoading.gone()
|
|
||||||
if (AppConfig.showUnread) {
|
|
||||||
binding.bvUnread.setHighlight(item.lastCheckCount > 0)
|
|
||||||
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
|
|
||||||
} else {
|
|
||||||
binding.bvUnread.invisible()
|
binding.bvUnread.invisible()
|
||||||
|
binding.rlLoading.visible()
|
||||||
|
} else {
|
||||||
|
binding.rlLoading.gone()
|
||||||
|
if (AppConfig.showUnread) {
|
||||||
|
binding.bvUnread.setHighlight(item.lastCheckCount > 0)
|
||||||
|
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
|
||||||
|
} else {
|
||||||
|
binding.bvUnread.invisible()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class BookViewHolder(val binding: ItemBookshelfListBinding) :
|
inner class GroupViewHolder(val binding: ItemBookshelfListGroupBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root)
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
class GroupViewHolder(val binding: ItemBookshelfListGroupBinding) :
|
fun onBind(item: BookGroup, position: Int) = binding.run{
|
||||||
RecyclerView.ViewHolder(binding.root)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user