@Override protected void onPostExecute(@Nullable DiffUtil.DiffResult diffResult) { if (backgroundException != null) { throw new RuntimeException(backgroundException); } AsyncDiffUtil async = asyncListDiffer.get(); if (shouldDispatchResult(diffResult, async)) { async.getAsyncDiffUtilCallback().onDispatchResult(async.getGroups()); diffResult.dispatchUpdatesTo(async.getAsyncDiffUtilCallback()); } }
private boolean shouldDispatchResult(@Nullable DiffUtil.DiffResult diffResult, AsyncDiffUtil async) { return diffResult != null && async != null && runGeneration == async.getMaxScheduledGeneration(); } }
/** * Updates the adapter with a new list that will be diffed on a background thread * and displayed once diff results are calculated. * * NOTE: This update method is NOT compatible with partial updates (change notifications * driven by individual groups and items). If you update using this method, all partial * updates will no longer work and you must use this method to update exclusively. * * @param newGroups List of {@link Group} */ @SuppressWarnings("unused") public void updateAsync(@NonNull final List<? extends Group> newGroups) { final List<Group> oldGroups = new ArrayList<>(groups); final int oldBodyItemCount = getItemCount(oldGroups); final int newBodyItemCount = getItemCount(newGroups); asyncDiffUtil.calculateDiff(newGroups, new DiffCallback(oldBodyItemCount, newBodyItemCount, oldGroups, newGroups)); }