Skip to content

Commit

Permalink
fix: Dispatch order of Diff updates to the Adapter
Browse files Browse the repository at this point in the history
Dispatch the Diff updates to the Adapter first, and then clear the Adapter's old data to load the new list.
  • Loading branch information
kaushiknsanji committed Oct 20, 2019
1 parent 4ca2979 commit 46ef6ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ public void swapItemData(@NonNull List<BookInfo> newBookInfos) {
*/
private void doSwapItemData(DiffUtil.DiffResult diffResult, @NonNull List<BookInfo> newBookInfos) {
Log.d(LOG_TAG, "doSwapItemData: Started");
//Informing the adapter about the changes required, so that it triggers the notify accordingly
diffResult.dispatchUpdatesTo(this);

//Clearing the Adapter's data to load the new list of BookInfo objects
mBookInfoList.clear();
mBookInfoList.addAll(newBookInfos);

//Informing the adapter about the changes required, so that it triggers the notify accordingly
diffResult.dispatchUpdatesTo(this);

//Dispatching the Item Data Swap event to the listener
mItemDataSwapListener.onItemDataSwapped();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ public void swapItemData(@NonNull List<BookInfo> newBookInfos) {
*/
private void doSwapItemData(DiffUtil.DiffResult diffResult, @NonNull List<BookInfo> newBookInfos) {
Log.d(LOG_TAG, "doSwapItemData: Started");
//Informing the adapter about the changes required, so that it triggers the notify accordingly
diffResult.dispatchUpdatesTo(this);

//Clearing the Adapter's data to load the new list of BookInfo objects
mBookInfoList.clear();
mBookInfoList.addAll(newBookInfos);

//Informing the adapter about the changes required, so that it triggers the notify accordingly
diffResult.dispatchUpdatesTo(this);

//Dispatching the Item Data Swap event to the listener
mItemDataSwapListener.onItemDataSwapped();
}
Expand Down

0 comments on commit 46ef6ab

Please sign in to comment.