mikepenz / FastAdapter

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
https://mikepenz.dev
Apache License 2.0
3.84k stars 494 forks source link

How can I judge the item is the last one in AbstractBindingItem #1032

Closed gudao20080 closed 2 years ago

gudao20080 commented 2 years ago

I want to do something in the last item, how to find which is the last item? please!!!

class PreviewPhotoItem(val item: Uri) : AbstractBindingItem<PhotoPreviewThumbItemBinding>() {
    override val type: Int
        get() = 0

    override fun createBinding(
        inflater: LayoutInflater,
        parent: ViewGroup?
    ): PhotoPreviewThumbItemBinding {
        return PhotoPreviewThumbItemBinding.inflate(inflater, parent, false)
    }

    override fun bindView(
        holder: BindingViewHolder<PhotoPreviewThumbItemBinding>,
        payloads: List<Any>
    ) {
        super.bindView(holder, payloads)
        if (holder.layoutPosition == 0) {
            holder.itemView.apply {
                val lp = this.layoutParams as ViewGroup.MarginLayoutParams
                lp.leftMargin = context.resources.getDimensionPixelSize(
                    R.dimen.dp_16
                )

                this.layoutParams = lp
            }
        }

        // if is the last item, 

    }

    override fun bindView(binding: PhotoPreviewThumbItemBinding, payloads: List<Any>) {
        binding.ivPreviewThumb.setImageURI(item)
        binding.ivPreviewThumb?.alpha = if (isSelected) 1f else 0.5f
    }

}
mikepenz commented 2 years ago

@gudao20080 this is unrelated to the FastAdapter library. It's should not be the responsibility of the item to act on its position. Items are re-used, which is a core functionality of the RecyclerView.

If you want a footer, consider using a different item at the end, or use another adapter second adapter as footer.

See samples like this in the sample app.

Otherwise please consolidate Google's RV documentation for RV related matters.