-
Notifications
You must be signed in to change notification settings - Fork 554
5.x | Update Data Set
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 rendering. 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
.
In order to update the content of existing items, it is possible to force the binding with the notification (notifyItemChanged()
) on those items by setting true
on this setting.
IFlexible.shouldNotifyChange()
is therefore invoked on the item interested by the change.
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!