lateinit var c: Context
var clickListener: IRecyclerViewClickListener? = null
lateinit var rv: RecyclerView
private var lastPos : Int = -1
override fun onBindViewHolder(holder: T, position: Int) {
holder.flush()
super.bindViewHolder(holder, position)
animate(holder.itemView, position)
}
private fun animate(root: View, position: Int) {
if (position > lastPos) {
val a = AnimationUtils.loadAnimation(c, android.R.anim.fade_in)
root.startAnimation(a)
lastPos = position
}
}
override fun onViewDetachedFromWindow(holder: T) {
holder.itemView.clearAnimation()
}
override fun onAttachedToRecyclerView(recyclerView: RecyclerView?) {
super.onAttachedToRecyclerView(recyclerView)
this.c = recyclerView!!.context
this.rv = recyclerView
}
fun inflate(@LayoutRes layoutId: Int, parent: ViewGroup? = null) : View {
return LayoutInflater.from(c).inflate(layoutId, parent, false)
}
fun attachItemClickListener(listener: IRecyclerViewClickListener) {
this.clickListener = listener
}
}
А где твой холдер созадется?
Обсуждают сегодня