-
Notifications
You must be signed in to change notification settings - Fork 375
Upgrading to 3.x
SectionedRecyclerViewAdapter provides many helper methods to manipulate your sections in the RecyclerView.Adapter. As the number of these methods are growing, it was decided to move them to a separate class called SectionAdapter, in order to make it less confusing to manipulate items of a specific section.
This was the breaking compatibility changes of this version, but it also includes other enhancements and new features.
This guide assumes that you are using version 2.1.0. If you are upgrading from earlier versions and find compiling issues not covered by this guide, please refer to the CHANGELOG document to understand what was changed.
👣 Step: Change all calls to missing methods of SectionedRecyclerViewAdapter to call methods from SectionAdapter class.
For example, this is how it was done before in order to notify that the header was changed in the adapter:
sectionedRecyclerViewAdapter.notifyHeaderChangedInSection(mySection);
This is how is done after upgrading:
SectionAdapter sectionAdapter = sectionedRecyclerViewAdapter.getAdapterForSection(mySection);
sectionAdapter.notifyHeaderChanged();
💡 Tip: If you don't have much spare time to update your code, you can just change all your adapters to extend from SectionedRecyclerViewAdapterV2Compat. It has all the previous methods from version 2.1.0.
List of methods moved:
| Old method in SectionedRecyclerViewAdapter | New method in SectionAdapter | |
|---|---|---|
| getFooterPositionInAdapter | -> | getFooterPosition |
| getHeaderPositionInAdapter | -> | getHeaderPosition |
| getPositionInAdapter | -> | getPositionInAdapter |
| getSectionPosition | -> | getSectionPosition |
| notifyAllItemsChangedInSection | -> | notifyAllItemsChanged |
| notifyAllItemsInsertedInSection | -> | notifyAllItemsInserted |
| notifyFooterChangedInSection | -> | notifyFooterChanged |
| notifyFooterInsertedInSection | -> | notifyFooterInserted |
| notifyFooterRemovedFromSection | -> | notifyFooterRemoved |
| notifyHeaderChangedInSection | -> | notifyHeaderChanged |
| notifyHeaderInsertedInSection | -> | notifyHeaderInserted |
| notifyHeaderRemovedFromSection | -> | notifyHeaderRemoved |
| notifyItemChangedInSection | -> | notifyItemChanged |
| notifyItemInsertedInSection | -> | notifyItemInserted |
| notifyItemMovedInSection | -> | notifyItemMoved |
| notifyItemRangeChangedInSection | -> | notifyItemRangeChanged |
| notifyItemRangeInsertedInSection | -> | notifyItemRangeInserted |
| notifyItemRangeRemovedFromSection | -> | notifyItemRangeRemoved |
| notifyItemRemovedFromSection | -> | notifyItemRemoved |
| notifyNotLoadedStateChanged | -> | notifyNotLoadedStateChanged |
| notifySectionChangedToInvisible | -> | notifySectionChangedToInvisible |
| notifySectionChangedToVisible | -> | notifySectionChangedToVisible |
| notifyStateChangedFromLoaded | -> | notifyStateChangedFromLoaded |
| notifyStateChangedToLoaded | -> | notifyStateChangedToLoaded |
👣 Step: Change all your section classes to extend Section instead of StatelessSection
StatelessSection has become redundant since the introduction of SectionParameters so it was removed in this version.
👣 Step: Implement get*ViewHolder methods
If your Section has header, footer or a state, you should implement the respective getHeaderViewHolder, getFooterViewHolder, getLoadingViewHolder, getFailedViewHolder or getEmptyViewHolder methods. Otherwise the adapter will throw an UnsupportedOperationException exception at runtime.
The easiest way to implement them is just to provide an instance of EmptyViewHolder, which was what the previous version was doing by default.
👣 Step: Change the import of this class from .SectionedRecyclerViewAdapter.EmptyViewHolder to .utils.EmptyViewHolder