package com.github.mrvilkaman.presentationlayer.fragments.core;


import android.support.v7.util.DiffUtil;

import java.util.List;

public abstract class BaseDiffCallback<Type> extends DiffUtil.Callback {

	private List<Type> mOldList;
	private List<Type> mNewList;

	public BaseDiffCallback(List<Type> mOldList, List<Type> mNewList) {
		this.mOldList = mOldList;
		this.mNewList = mNewList;
	}

	@Override
	public int getOldListSize() {
		return mOldList != null ? mOldList.size() : 0;
	}

	@Override
	public int getNewListSize() {
		return mNewList != null ? mNewList.size() : 0;
	}

	@Override
	public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
		Type oldItem = mOldList.get(oldItemPosition);
		Type newItem = mNewList.get(newItemPosition);
		return areItemsTheSame(oldItem, newItem);
	}

	protected abstract boolean areItemsTheSame(Type oldItem, Type newItem);

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

}

@@ -59,16 +59,60 @@
 core;%0A%0A%0A
+import android.support.annotation.Nullable;%0A
 import a
@@ -448,24 +448,30 @@
 ide%0A%09public 
+final 
 int getOldLi
@@ -553,16 +553,22 @@
 %09public 
+final 
 int getN
@@ -646,32 +646,38 @@
 verride%0A%09public 
+final 
 boolean areItems
@@ -745,28 +745,26 @@
 dItem = 
-mOldList.get
+getOldItem
 (oldItem
@@ -791,28 +791,26 @@
 wItem = 
-mNewList.get
+getNewItem
 (newItem
@@ -883,69 +883,375 @@
 ted 
-abstract boolean areItemsTheSame(Type oldItem, Type newItem);
+final Type getNewItem(int newItemPosition) %7B%0A%09%09return mNewList.get(newItemPosition);%0A%09%7D%0A%0A%09protected final Type getOldItem(int oldItemPosition) %7B%0A%09%09return mOldList.get(oldItemPosition);%0A%09%7D%0A%0A%09protected abstract boolean areItemsTheSame(Type oldItem, Type newItem);%0A%0A%09protected boolean areContentsTheSame(Type oldItem, Type newItem) %7B%0A%09%09return oldItem.equals(newItem);%0A%09%7D
 %0A%0A%09@
@@ -1267,16 +1267,22 @@
 %09public 
+final 
 boolean 
@@ -1350,86 +1350,475 @@
 %7B%0A%09%09
-return mNewList.get(newItemPosition).equals(mOldList.get(oldItemPosition));%0A%09%7D%0A
+Type newItem = getNewItem(newItemPosition);%0A%09%09Type oldItem = getOldItem(oldItemPosition);%0A%09%09return areContentsTheSame(newItem, oldItem);%0A%09%7D%0A%0A%09@Nullable%0A%09@Override%0A%09public final Object getChangePayload(int oldItemPosition, int newItemPosition) %7B%0A%09%09Type newItem = getNewItem(newItemPosition);%0A%09%09Type oldItem = getOldItem(oldItemPosition);%0A%09%09return getChangePayload(newItem, oldItem);%0A%09%7D%0A%0A%09protected Object getChangePayload(Type newItem, Type oldItem) %7B%0A%09%09return null;%0A%09%7D
 %0A%7D%0A

change base diffcallback