ShamylZakariya / StickyHeaders

Adapter and LayoutManager for Android RecyclerView which enables sticky header positioning.
MIT License
1.4k stars 185 forks source link

Calling notifyAllSectionsDataSetChanged does not work as expected #43

Open ricknout opened 7 years ago

ricknout commented 7 years ago

When refreshing a data set, the suggested method call is notifyAllSectionsDataSetChanged().

I would imagine this to clear all collapsed states, ensuring that each section is no longer collapsed. This is not the case, as can be seen in the example app's 'Collapsing Headers' demo. Try collapsing a section, then hit 'Reload' from the menu. The header view's state is restored to appear not collapsed, but the items remain hidden.

I believe this is due to the ordering of method calls:

public void notifyAllSectionsDataSetChanged() {
    buildSectionIndex();
    notifyDataSetChanged();
    collapsedSections.clear();
    selectionStateBySection.clear();
}

should rather be:

public void notifyAllSectionsDataSetChanged() {
    collapsedSections.clear();
    selectionStateBySection.clear();
    buildSectionIndex();
    notifyDataSetChanged();
}

because buildSectionIndex() uses isSectionCollapsed(s) (which checks the collapsedSections map) to determine section length and numberOfItems.

I'm happy to make a PR, but thought I would just check to see if this is the intended behavior?