// Path: gmlrva-lib/src/main/java/pt/simdea/gmlrva/lib/threading/BackgroundDiffUtilWorker.java
// @AllArgsConstructor
// public final class BackgroundDiffUtilWorker implements Runnable {
// 
//     private final List<? extends IGenericRecyclerViewLayout> mOldDataSet;
//     private final List<? extends IGenericRecyclerViewLayout> mNewDataSet;
//     private final Context mContext;
//     private final GenericMultipleLayoutAdapter mAdapter;
// 
//     /** {@inheritDoc} */
//     @WorkerThread
//     @Override
//     public void run() {
//         final DiffUtil.DiffResult diffResult
//                 = DiffUtil.calculateDiff(new GmlrvaDiffCallback(this.mOldDataSet, this.mNewDataSet));
//         if (mContext != null) {
//             ((Activity) mContext).runOnUiThread(new UpdateUiDiffUtilResult(this.mNewDataSet, diffResult, mAdapter));
//         }
//     }
// 
// }
// 
// Path: gmlrva-lib/src/main/java/pt/simdea/gmlrva/lib/diff/GenericPayload.java
// public static final String UPDATE_ITEM = "UPDATE_ITEM";


import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.ViewGroup;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import pt.simdea.gmlrva.lib.threading.BackgroundDiffUtilWorker;
import static pt.simdea.gmlrva.lib.diff.GenericPayload.UPDATE_ITEM;
                           @IntRange(from = 0) final int holderInfoAction) {
        final List<IGenericRecyclerViewLayout> newList
                = new ArrayList<>(mPendingUpdates.isEmpty() ? mDataSet : mPendingUpdates.peekLast());
        if (!newList.isEmpty() && newList.contains(item)) {
            notifyItemChanged(newList.indexOf(item), holderInfoAction);
        }
    }

    /**
     * Procedure meant to prepare an update this adapter's entire data set.
     * This procedure checks for the changes made to this adapter's data set and applies these changes exclusively,
     * meaning there are no wasted operations.
     * Allows for update queueing and recursion.
     * @param items the list of Generic Layout Implementation items for the data set.
     */
    @UiThread
    public void updateList(@NonNull final List<? extends IGenericRecyclerViewLayout> items) {
        mPendingUpdates.add(items);
        if (mPendingUpdates.size() == 1) {
            innerUpdateList(items); // no pending update, so execute the update
        }
    }

    /**
     * Procedure meant to update this adapter's entire data set.
     * Makes use of a background thread to execute the update operation and off load work from the UIThread.
     * @param items the list of Generic Layout Implementation items for the data set.
     */
    @UiThread
    private void innerUpdateList(@NonNull final List<? extends IGenericRecyclerViewLayout> items) {
// Path: gmlrva-lib/src/main/java/pt/simdea/gmlrva/lib/threading/BackgroundDiffUtilWorker.java
// @AllArgsConstructor
// public final class BackgroundDiffUtilWorker implements Runnable {
// 
//     private final List<? extends IGenericRecyclerViewLayout> mOldDataSet;
//     private final List<? extends IGenericRecyclerViewLayout> mNewDataSet;
//     private final Context mContext;
//     private final GenericMultipleLayoutAdapter mAdapter;
// 
//     /** {@inheritDoc} */
//     @WorkerThread
//     @Override
//     public void run() {
//         final DiffUtil.DiffResult diffResult
//                 = DiffUtil.calculateDiff(new GmlrvaDiffCallback(this.mOldDataSet, this.mNewDataSet));
//         if (mContext != null) {
//             ((Activity) mContext).runOnUiThread(new UpdateUiDiffUtilResult(this.mNewDataSet, diffResult, mAdapter));
//         }
//     }
// 
// }
// 
// Path: gmlrva-lib/src/main/java/pt/simdea/gmlrva/lib/diff/GenericPayload.java
// public static final String UPDATE_ITEM = "UPDATE_ITEM";


// Path: gmlrva-lib/src/main/java/pt/simdea/gmlrva/lib/GenericMultipleLayoutAdapter.java
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.ViewGroup;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import pt.simdea.gmlrva.lib.threading.BackgroundDiffUtilWorker;
import static pt.simdea.gmlrva.lib.diff.GenericPayload.UPDATE_ITEM;

                           @IntRange(from = 0) final int holderInfoAction) {
        final List<IGenericRecyclerViewLayout> newList
                = new ArrayList<>(mPendingUpdates.isEmpty() ? mDataSet : mPendingUpdates.peekLast());
        if (!newList.isEmpty() && newList.contains(item)) {
            notifyItemChanged(newList.indexOf(item), holderInfoAction);
        }
    }

    /**
     * Procedure meant to prepare an update this adapter's entire data set.
     * This procedure checks for the changes made to this adapter's data set and applies these changes exclusively,
     * meaning there are no wasted operations.
     * Allows for update queueing and recursion.
     * @param items the list of Generic Layout Implementation items for the data set.
     */
    @UiThread
    public void updateList(@NonNull final List<? extends IGenericRecyclerViewLayout> items) {
        mPendingUpdates.add(items);
        if (mPendingUpdates.size() == 1) {
            innerUpdateList(items); // no pending update, so execute the update
        }
    }

    /**
     * Procedure meant to update this adapter's entire data set.
     * Makes use of a background thread to execute the update operation and off load work from the UIThread.
     * @param items the list of Generic Layout Implementation items for the data set.
     */
    @UiThread
    private void innerUpdateList(@NonNull final List<? extends IGenericRecyclerViewLayout> items) {
        mHandler.post(new BackgroundDiffUtilWorker(mDataSet, items, mContext, this));