"Favor composition over inheritance" for RecyclerView Adapters
Addition: get notified when list was committed to RecyclerView #104
adapterDelegateViewBinding()
.Minor improvements:
internal
no (with @PublishedApi
)Added some shortcuts / convenience functions (and properties) for kotlin DSL. Instead of calling itemView.context
you now have direct access to the following fields and functions:
Overall this minor release just reduces a bit more typing for you as you now can do something like this:
fun catDelegate() = adatperDelegate<Cat, Animal>(R.layout.cat) {
...
bind {
icon.drawable = getDrawable(R.drawable.cat) // instead of itemView.context.getDrawable()
}
}
Added a Kotlin DSL to create AdapterDelegates through a fluend DSL. There are actually 2 DSL artifacts:
fun catAdapterDelegate(itemClickedListener : (Cat) -> Unit) = adapterDelegate<Cat, Animal>(R.layout.item_cat) {
val name : TextView = findViewById(R.id.name)
name.setClickListener { itemClickedListener(item) }
bind {
name.text = item.name
}
}
adapterDelegate
but uses kotlin android extension's LayoutContainer
and the generated synthetic properties. Thus, you dont have to write any findViewById()
.fun catAdapterDelegate(itemClickedListener : (Cat) -> Unit) = adapterDelegateLayoutContainer<Cat, Animal>(R.layout.item_cat) {
name.setClickListener { itemClickedListener(item) } // name is imported from kotlinx.android.synthetic.main.item_cat.name
bind {
name.text = item.name
}
}
Read the README for more details how to use it.
RecyclerView
from AndroidX: androidx.recyclerview:recyclerview:1.0.0
adapterdelegates3
to adapterdelegates4
Added AsyncListDifferDelegationAdapter
that uses DiffUtils under the hood to animate dataset changes.
adapterDelegate.onBindViewHoler()
is never null (empty list if payload not used) #30AdapterDelegate
is now an abstract class (was a interface formerly)onBindViewHolder(@NonNull T items, int position, @NonNull RecyclerView.ViewHolder holder, @NonNull List<Object> payloads);
: This method will be called for both adapter.notifyItemChanged()
with or without payload. In Version 2.x of this library there was only one method onBindViewHolder(@NonNull T items, int position, @NonNull RecyclerView.ViewHolder holder)
. This one (with additional payload parameter) replaces the old one.onViewRecycled(ViewHolder holder)
: Called when ViewHolder has been recycledonFailedToRecycleView(ViewHolder holder)
: Called when ViewHolder couldn't be recycledonViewAttachedToWindow(ViewHolder holder)
: Called when View (of ViewHolder) has been attached to windowonViewDetachedFromWindow(ViewHolder holder)
: Called when View (of ViewHolder) has been detached from windowAdapterDelegate
to protected
(formerly public
before because of interface)