@SuppressWarnings("WeakerAccess")
    public void addWeakCallback(@Nullable List<T> previousSnapshot, @NonNull Callback callback) {
        if (previousSnapshot != null && previousSnapshot != this) {

            if (previousSnapshot.isEmpty()) {
                if (!mStorage.isEmpty()) {
                    // If snapshot is empty, diff is trivial - just notify number new items.
                    // Note: occurs in async init, when snapshot taken before init page arrives
                    callback.onInserted(0, mStorage.size());
                }
            } else {
                PagedList<T> storageSnapshot = (PagedList<T>) previousSnapshot;

                //noinspection unchecked
                dispatchUpdatesSinceSnapshot(storageSnapshot, callback);
            }
        }

        // first, clean up any empty weak refs
        for (int i = mCallbacks.size() - 1; i >= 0; i--) {
            Callback currentCallback = mCallbacks.get(i).get();
            if (currentCallback == null) {
                mCallbacks.remove(i);
            }
        }

        // then add the new one
        mCallbacks.add(new WeakReference<>(callback));
    }
@ SuppressWarnings ( "WeakerAccess" ) public void addWeakCallback ( @ Nullable List < T > previousSnapshot , @ NonNull Callback callback ) { if ( previousSnapshot != null && previousSnapshot != this ) { if ( previousSnapshot . isEmpty ( ) ) { if ( ! mStorage . isEmpty ( ) ) { callback . onInserted ( 0 , mStorage . size ( ) ) ; } } else { PagedList < T > storageSnapshot = ( PagedList < T > ) previousSnapshot ; dispatchUpdatesSinceSnapshot ( storageSnapshot , callback ) ; } } for ( int i = mCallbacks . size ( ) - 1 ; i >= 0 ; i -- ) { Callback currentCallback = mCallbacks . get ( i ) . get ( ) ; if ( currentCallback == null ) { mCallbacks . remove ( i ) ; } } mCallbacks . add ( new WeakReference < > ( callback ) ) ; }
Adds a callback, and issues updates since the previousSnapshot was created.
<p>
If previousSnapshot is passed, the callback will also immediately be dispatched any
differences between the previous snapshot, and the current state. For example, if the
previousSnapshot was of 5 nulls, 10 items, 5 nulls, and the current state was 5 nulls,
12 items, 3 nulls, the callback would immediately receive a call of
<code>onChanged(14, 2)</code>.
<p>
This allows an observer that's currently presenting a snapshot to catch up to the most recent
version, including any changes that may have been made.
<p>
The callback is internally held as weak reference, so PagedList doesn't hold a strong
reference to its observer, such as a {@link PagedListAdapter}. If an adapter were held with a
strong reference, it would be necessary to clear its PagedList observer before it could be
GC'd.

@param previousSnapshot Snapshot previously captured from this List, or null.
@param callback Callback to dispatch to.

@see #removeWeakCallback(Callback)