Search in sources :

Example 1 with AnimateAdditionAdapter

use of com.nhaarman.listviewanimations.itemmanipulation.animateaddition.AnimateAdditionAdapter in project ListViewAnimations by nhaarman.

the class DynamicListView method setAdapter.

/**
     * Sets the {@link ListAdapter} for this {@code DynamicListView}.
     * If the drag and drop functionality is or will be enabled, the adapter should have stable ids,
     * and should implement {@link com.nhaarman.listviewanimations.util.Swappable}.
     *
     * @param adapter the adapter.
     *
     * @throws java.lang.IllegalStateException    if the drag and drop functionality is enabled
     *                                            and the adapter does not have stable ids.
     * @throws java.lang.IllegalArgumentException if the drag and drop functionality is enabled
     *                                            and the adapter does not implement {@link com.nhaarman.listviewanimations.util.Swappable}.
     */
@Override
public void setAdapter(final ListAdapter adapter) {
    ListAdapter wrappedAdapter = adapter;
    mSwipeUndoAdapter = null;
    if (adapter instanceof BaseAdapter) {
        BaseAdapter rootAdapter = (BaseAdapter) wrappedAdapter;
        while (rootAdapter instanceof BaseAdapterDecorator) {
            if (rootAdapter instanceof SwipeUndoAdapter) {
                mSwipeUndoAdapter = (SwipeUndoAdapter) rootAdapter;
            }
            rootAdapter = ((BaseAdapterDecorator) rootAdapter).getDecoratedBaseAdapter();
        }
        if (rootAdapter instanceof Insertable) {
            mAnimateAdditionAdapter = new AnimateAdditionAdapter((BaseAdapter) wrappedAdapter);
            mAnimateAdditionAdapter.setListView(this);
            wrappedAdapter = mAnimateAdditionAdapter;
        }
    }
    super.setAdapter(wrappedAdapter);
    if (mDragAndDropHandler != null) {
        mDragAndDropHandler.setAdapter(adapter);
    }
}
Also used : BaseAdapterDecorator(com.nhaarman.listviewanimations.BaseAdapterDecorator) SwipeUndoAdapter(com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.undo.SwipeUndoAdapter) BaseAdapter(android.widget.BaseAdapter) Insertable(com.nhaarman.listviewanimations.util.Insertable) ListAdapter(android.widget.ListAdapter) AnimateAdditionAdapter(com.nhaarman.listviewanimations.itemmanipulation.animateaddition.AnimateAdditionAdapter)

Aggregations

BaseAdapter (android.widget.BaseAdapter)1 ListAdapter (android.widget.ListAdapter)1 BaseAdapterDecorator (com.nhaarman.listviewanimations.BaseAdapterDecorator)1 AnimateAdditionAdapter (com.nhaarman.listviewanimations.itemmanipulation.animateaddition.AnimateAdditionAdapter)1 SwipeUndoAdapter (com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.undo.SwipeUndoAdapter)1 Insertable (com.nhaarman.listviewanimations.util.Insertable)1