package com.stolets.rxdiffutil;

import android.support.annotation.NonNull;
import android.support.v7.util.DiffUtil;

import java.util.List;

import static com.stolets.rxdiffutil.internal.Preconditions.checkNotNull;

/**
 * Default implementation of the methods required by {@link DiffUtil.Callback}.
 * Feel free to create our own subclass overriding only the required method.
 *
 * @param <I> Type of the data id.
 * @param <D> Comparable data type.
 */
@SuppressWarnings({"WeakerAccess", "unused"})
public class DefaultDiffCallback<I, D extends Identifiable<I>> extends DiffUtil.Callback {
    @NonNull
    private final List<? extends D> mOldData;
    @NonNull
    private final List<? extends D> mNewData;

    /**
     * Constructs an instance of {@link DefaultDiffCallback}.
     *
     * @param oldData The current list with the data.
     * @param newData The updated list with the data which is compared with the oldData.
     */
    public DefaultDiffCallback(@NonNull final List<? extends D> oldData, @NonNull final List<? extends D> newData) {
        checkNotNull(oldData, "oldData must not be null!");
        checkNotNull(newData, "newData must not be null!");

        this.mOldData = oldData;
        this.mNewData = newData;
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        return mNewData.get(newItemPosition).equals(mOldData.get(oldItemPosition));
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        return mNewData.get(newItemPosition).getId().equals(mOldData.get(oldItemPosition).getId());
    }

    @Override
    public int getNewListSize() {
        return mNewData.size();
    }

    @Override
    public int getOldListSize() {
        return mOldData.size();
    }
}

@@ -106,24 +106,107 @@
 l.DiffUtil;%0A
+import android.support.v7.widget.RecyclerView;%0A%0Aimport java.lang.ref.WeakReference;
 %0Aimport java
@@ -643,37 +643,143 @@
 e%3CI%3E
-%3E extends DiffUtil.Callback %7B
+, A extends RecyclerView.Adapter & Updatable%3CD%3E%3E extends DiffUtil.Callback %7B%0A    @NonNull%0A    private WeakReference%3CA%3E mAdapterWeakRef;
 %0A   
@@ -1110,24 +1110,215 @@
 he oldData.%0A
+     * @param adapter %7B@link RecyclerView.Adapter%7D that will be automatically updated and notified about the data changes. Note: the given adapter must implement %7B@link Updatable%7D interface.%0A
      */%0A    
@@ -1385,16 +1385,47 @@
 oldData,
+%0A                              
  @NonNul
@@ -1457,16 +1457,73 @@
  newData
+,%0A                               @NonNull final A adapter
 ) %7B%0A    
@@ -1637,16 +1637,76 @@
 null!%22);
+%0A        checkNotNull(newData, %22adapter must not be null!%22);
 %0A%0A      
@@ -1761,24 +1761,85 @@
  = newData;%0A
+        this.mAdapterWeakRef = new WeakReference%3C%3E(adapter);%0A
     %7D%0A%0A    @

Add recycler adapter weak reference