eowise / recyclerview-stickyheaders

DEPRECATED. Android library that integrate sticky section headers in your RecyclerView
http://eowise.github.io/recyclerview-stickyheaders
MIT License
961 stars 148 forks source link

Add better data observer capabilities to HeaderStore #21

Closed is-devteam closed 9 years ago

is-devteam commented 9 years ago

Added methods to handle item moves and changes.

Fixes https://github.com/eowise/recyclerview-stickyheaders/issues/20

leruaa commented 9 years ago

Hi,

Thanks a lot for this pull request !

Could you provide some pointers to allow me to test these new features in the samples ?

is-devteam commented 9 years ago

There's basically two test scenarios.

headersViewByHeadersIds.clear() was added to the beginning of each observer method in HeaderStore because there might be contextual information displayed in a header (eg, a count of the items in that "section"). Since a remove, move, insert, or change can affect that, the headers should be rebound to account for the possible new data.

The other scenario is when a item is moved or changed in the adapter. For a change, all items in the range of changed items need to be checked to see if they are headers. Additionally, the item after the range needs to be checked. For a move it's pretty much the same, except the range is determined by the fromPosition and toPosition and it can extend backwards, forwards, or be only one item.

The way to test the first scenario could just be keeping a count of items under a header and displaying that number in the header (in onBindViewHolder for the StickyHeaderAdapter get the count for that section and display it). Then make sure that it updates correctly when removing, moving, inserting, or changing items.

The second scenario test is like the first, but make sure that animations are being used correctly. In both test scenarios, the appropriate Adapter calls should be made (notifyItemRemoved notifyItemInserted, etc...). I didn't get a chance to test with ranges yet, so you might want to include something separate for that.