Skip to content

This is a dynamic lib that utilizes DiffUtils to manage recycler view adapters with ease. By eliminating the need for `notifyDataSetChanged`, DiffEase offers superior performance and responsiveness. With support for multiple views, selectable items, and e.t.s. simplifies the process of handling dynamic data

License

Nuclominus/DiffEase

Repository files navigation

DiffEase

License Maven Central Detekt scaning

A simple implementation of adapter for recycleview that implement DiffUtils and diffCallback by default.

The main idea of the library is to completely abandon the old implementation of updating the list via notifyDataChanged() and simplify the process of creating a generic and multi-type list with multiple view types.

Also in a library implemented variation of selectable helper for adapter.

How to start:

Gradle Groovy DSL:

implementation 'io.github.nuclominus:diffease:$diffeaseVersion'

Gradle Kotlin DSL:

implementation("io.github.nuclominus:diffease:$diffeaseVersion")

Usage:

Using of this adapter is simple and almost does not differ from using a regular adapter. Using in three steps:

First

/**
 * Implement adapter with specifying the data type and the supported data type. 
 * To support multiple cell types, we specify not an explicit viewholder type, but a generic one. 
 */
class SimpleDiffAdapter() : DiffEaseAdapter<MultiMock, BaseViewHolder<MultiMock>>() {
    ...
}

Second

In the adapter you can/should change the default implementation of the diff callback

// override default implementation
override fun <TInput : MultiMock> getDiffCallback(
        oldItems: List<MultiMock>,
        newItems: List<TInput>
    ): DiffResultCallback<MultiMock, TInput> = baseDiffCallback(oldItems, newItems)

Third

Update adapter

vm.data.observe(viewLifecycleOwner) { data ->
     adapter.update(data, true) // with detecting moves in list
}

You can find out about wider use in the Wiki

Future features

  • Support several selectable adapters in concatadapter

About

This is a dynamic lib that utilizes DiffUtils to manage recycler view adapters with ease. By eliminating the need for `notifyDataSetChanged`, DiffEase offers superior performance and responsiveness. With support for multiple views, selectable items, and e.t.s. simplifies the process of handling dynamic data

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages