tumblr/Bookends

Add support to diff utils

Opened this issue · 0 comments

Hi,
How to use diff utils with Bookends.
How have below in my mind but not sure how to implement need some guidance -

    val headerCount = bookends.headerCount
    val footerCount = bookends.footerCount

    dispatchUpdatesTo(object : ListUpdateCallback {

        private fun getItemCount(count: Int): Int {
            return count + headerCount + footerCount
        }

        private fun getPosition(position: Int): Int {
            return position + headerCount
        }

        override fun onInserted(position: Int, count: Int) {
            bookends.notifyItemRangeInserted(getPosition(position), getItemCount(count))
        }

        override fun onRemoved(position: Int, count: Int) {
            bookends.notifyItemRangeRemoved(getPosition(position), getItemCount(count))
        }

        override fun onMoved(fromPosition: Int, toPosition: Int) {
            bookends.notifyItemMoved(fromPosition, toPosition)
        }

        override fun onChanged(position: Int, count: Int, payload: Any) {
            bookends.notifyItemRangeChanged(getPosition(position), getItemCount(count), payload)
        }
    })