Skip to content

v5.0.0-a06

Pre-release
Pre-release
Compare
Choose a tag to compare
@mikepenz mikepenz released this 15 Feb 12:26
· 236 commits to develop since this release
8207baf

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 the IItemVHFactory.
  • To complete this interface there is now a new BaseItem and ModelBaseItem to allow splitting item logic, and ViewHolder creation logic.
  • The old AbstractItem and ModelAbstractItem are now deprecated in favor of the newer approach
  • The IItem interface no longer contains the Factory logic
  • It is still possible to implement items "the old way" by using the AbstractItem or by providing the IItemVHFactory beside the IItem interface, and also the IItemViewGenerator 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)
    }
}