Fixes
- to further migrate towards a better separation of responsibilities we have introduced a new interface which will describe the logic for creating the
ViewHolder
theIItemVHFactory
. - To complete this interface there is now a new
BaseItem
andModelBaseItem
to allow splitting item logic, and ViewHolder creation logic. - The old
AbstractItem
andModelAbstractItem
are now deprecated in favor of the newer approach - The
IItem
interface no longer contains theFactory
logic - It is still possible to implement items "the old way" by using the
AbstractItem
or by providing theIItemVHFactory
beside theIItem
interface, and also theIItemViewGenerator
if needed
Migration
OLD
If the Item
implementation looked like:
class SimpleImageItem : AbstractItem<SimpleImageItem.ViewHolder>() {
override val type: Int
get() = R.id.fastadapter_simple_image_item_id
override val layoutRes: Int
get() = R.layout.simple_image_item
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
...
}
override fun unbindView(holder: ViewHolder) {
}
override fun getViewHolder(v: View): ViewHolder {
return ViewHolder(v)
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
var view: FrameLayout
...
}
}
NEW
It should be refactored to look like:
class SimpleImageItem : BaseItem<SimpleImageItem.ViewHolder>() {
override val type: Int
get() = R.id.fastadapter_simple_image_item_id
override val factory: IItemVHFactory<ViewHolder> = SimpleImageItemFactory
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
...
}
override fun unbindView(holder: ViewHolder) {
...
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
var view: FrameLayout
}
}
object SimpleImageItemFactory : BaseItemFactory<SimpleImageItem.ViewHolder>() {
override val type: Int
get() = R.id.fastadapter_simple_image_item_id
override val layoutRes: Int
get() = R.layout.simple_image_item
override fun getViewHolder(v: View): SimpleImageItem.ViewHolder {
return SimpleImageItem.ViewHolder(v)
}
}