-
Notifications
You must be signed in to change notification settings - Fork 554
5.x | Update Data Set
- updateDataSet
- onPostUpdate
- shouldNotifyChange
- setNotifyChangeOfUnfilteredItems
- setNotifyMoveOfFilteredItems
To update the entire data set, the method updateDataSet()
has two modality:
1. Instant refresh, but no synchronization animations(1). It skips all notifyItemXXX()
calls and just before calling notifyDataSetChanged()
, the adapter list is integrated with expandables expanded and headers to be shown.
updateDataSet(new_items);
updateDataSet(new_items, false);
2. Asynchronous refresh, to animate the changes between the current list and the new one.
It synchronizes all new and existent items with fine-grained(2) notifyItemXXX()
calls. An AsyncTask
and LinkedHashSet
are used to optimize the scan on Big List without blocking the main thread.
From 5.0.0-RC2, a new strategy has been implemented to calculate the differences between the 2 lists: Expandables expanded and headers to be shown are now integrated before the calculation starts and always in background, this optimization, highly reduces the number of notifications to elaborate, resulting in faster calculation.
Notifications, instead, must be elaborated in the main thread after AsyncTask completes the background process.
updateDataSet(new_items/*(3)*/, true/*(4)*/);
1️⃣ = Having stable ids, when calling
notifyDataSetChanged()
will still run animation. Stable ids are more useful in big list and where pictures (loaded from network) are involved. However, in this library single notifications are the normality called elsewhere. More on stable ids? Check issue comment #230 or google it.2️⃣ =
FlexibleAdapter
doesn't make use of DiffUtil, because the new integrated process is far better than the utility class provided by Android. Therefore, DiffUtil has been already deprecated and will be removed in RC3 release.3️⃣ = Nullable.
4️⃣ = It is strongly recommended to implement
hashCode()
method coherent with your implementation ofequals()
method in yourIFlexible
items: FlexibleAdapter makes use of Hash when stableIds and animation are used.
In both modality, onPostUpdate()
is invoked as last operation for OnUpdateListener
implementation, so the emptyView can be updated as well. onPostUpdate()
must be overridden by extending the FlexibleAdapter
class.
@CallSuper
protected void onPostUpdate() {
// Call listener to update EmptyView, assuming the update always made a change
if (mUpdateListener != null)
mUpdateListener.onUpdateEmptyView(getMainItemCount());
}
This method resides in each IFlexible
item, so that FlexibleAdapter can optimize if notify change will be invoked on that item. To activate this check you must enable setNotifyChangeOfUnfilteredItems()
as well.
Default value is true
if item extends AbstractFlexibleItem
class.
Setting this property to false
, we skip the check of the implemented method IFlexible#shouldNotifyChange(IFlexible)
of all items, but also we skip part of the calculation when processing the differences between the old and the new list. It's ok to set false
, if your items won't change content when invoking updateDataSet()
. As benefit the update will result faster.
Default value is true
.
This method performs a further step to nicely animate the moved items, very useful in certain use cases, but keep in mind that the process is very slow only on big list of the order of ~3-5000 items and higher, due to the calculation of the correct position for each item to be shifted.
Default value is false
.
- Update Data Set
- Selection modes
- Headers and Sections
- Scrollable Headers and Footers
- Expandable items
- Drag&Drop and Swipe
- EndlessScroll / On Load More
- Search Filter
- FastScroller
- Adapter Animations
- Third party Layout Managers
- Payload
- Smooth Layout Managers
- Flexible Item Decoration
- Utils
- ActionModeHelper
- AnimatorHelper
- EmptyViewHelper
- UndoHelper
* = Under revision!