lisawray / groupie

Groupie helps you display and manage complex RecyclerView layouts.
MIT License
3.67k stars 293 forks source link

DiffUtils breaks ExpandableGroup clickability #271

Open mukovozov opened 5 years ago

mukovozov commented 5 years ago

I don't want to redraw all ExpandableGroups, so i override equals in my Item as follows:

override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is HeaderItem) return false

        if (identifier != other.identifier) return false
        if (expandableGroup.itemCount != other.expandableGroup.itemCount) return false
        return true
    }

But if I change ChildrenItem and don't redraw HeaderItems I can't click on other HeaderItems.

ValCanBuild commented 5 years ago

@mukovozov can you provide an example of the composition you're trying to build. As well as what you expect to happen. Not able to infer much from you code - it'd help if you could expand

mukovozov commented 5 years ago

@ValCanBuild i have created dummy project to show that behavior. Link: https://github.com/mukovozov/GroupieExpandableGroupsTest

  1. Click on the ExpandableGroup
  2. Click on the ChildItem
  3. Click on another ExpandableGroup.

OnClickListener was not called.

ValCanBuild commented 5 years ago

I checked out your project. I think the problem was the if (expandableGroup.itemCount != other.expandableGroup.itemCount). It's not the correct thing to check for.

You create a brand new ExpandableGroup when you call your update() function, so the correct equals should be

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as HeaderItem

        if (identifier != other.identifier) return false
        if (expandableGroup != other.expandableGroup) return false

        return true
    }

Does that help?

mukovozov commented 5 years ago

expandableGroup != other.expandableGroup always true, because, as you said, when I call update() I create new ExpandableGroup. And every ExpadandableGroup redraw after that. I think that this is strange behavior.

ValCanBuild commented 5 years ago

Hmm, perhaps. I need to have a think about this and play with it before making a decision.