package com.wsl.library.widget;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Created by wsl on 17/4/15.
 */

public abstract class DdNineGridArrayAdapter<T> extends DdNineGridBaseAdapter {

    private final Object mLock = new Object();

    private List<T> mObjects;

    private boolean mNotifyOnChange = true;

    public DdNineGridArrayAdapter(List<T> objects) {
        this.mObjects = objects;
    }

    public void add(@Nullable T object) {
        synchronized (mLock) {
            mObjects.add(object);
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void addAll(@NonNull Collection<? extends T> collection) {
        synchronized (mLock) {
            mObjects.addAll(collection);
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void addAll(T... items) {
        synchronized (mLock) {
            Collections.addAll(mObjects, items);
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void insert(@Nullable T object, int index) {
        synchronized (mLock) {
            mObjects.add(index, object);
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    public void remove(@Nullable T object) {
        synchronized (mLock) {
            mObjects.remove(object);
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

    /**
     * Remove all elements from the list.
     */
    public void clear() {
        synchronized (mLock) {
            mObjects.clear();
        }
        if (mNotifyOnChange) notifyDataSetChanged();
    }

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

    @Override
    public T getItem(int position) {
        return mObjects != null ? mObjects.get(position) : null;
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
        mNotifyOnChange = true;
    }

    public void setNotifyOnChange(boolean notifyOnChange) {
        mNotifyOnChange = notifyOnChange;
    }
}

@@ -2172,11 +2172,115 @@
 e;%0A    %7D
+%0A%0A    /**%0A     * @return %E8%BF%94%E5%9B%9E%E6%89%80%E6%9C%89%E7%9A%84%E6%95%B0%E6%8D%AE%0A     */%0A    protected List%3CT%3E getAll() %7B%0A        return mObjects;%0A    %7D
 %0A%7D%0A

Add method getAll data