ibrahimyilmaz / kiel

(Published to MavenCentral) Kotlin way of building RecyclerView Adapter 🧩. You do not have to write RecyclerView Adapters again and again and suffer from handling of different view types. Kiel will help you.
Apache License 2.0
370 stars 30 forks source link

Composable Diff improvements #43

Open terekhovyes opened 4 years ago

terekhovyes commented 4 years ago

https://github.com/ibrahimyilmaz/kiel/pull/40 added syntax to define Diff callback for whole adapter. But you still have no ability to define diff callback for register blocks separately.

There is example of how it may look like:

adapterOf<Animal> {
    register(
        layoutResource = R.layout.item_cat,
        viewHolder = ::CatHolder,
        diff = diff(
            areItemsTheSame = { cat1, cat2 -> cat1.name == cat2.name }
        )
    )

    register(
        layoutResource = R.layout.item_dog,
        viewHolder = ::DogHolder,
        diff = diff(
            areItemsTheSame = { dog1, dog2 -> dog1.bark == dog2.bark }
        )
    )
}

This builder under the hood should create single DiffUtil.Callback with multiple "delegates": one for Cat, one for Dog. Then, when DiffUtil.Callback methods are called, that Callback must pick appropriate "delegate" and call it

JonibekXolmonov commented 6 months ago

Hi sir, is this optimisation still active. May I try it