Search in sources :

Example 1 with UndoCard

use of it.gmariotti.cardslib.library.view.listener.UndoCard in project cardslib by gabrielemariotti.

the class CardArrayAdapter method onUndo.

// -------------------------------------------------------------
//  Undo Default Listener
// -------------------------------------------------------------
@Override
public void onUndo(Parcelable token) {
    //Restore items in lists (use reverseSortedOrder)
    if (token != null) {
        UndoCard item = (UndoCard) token;
        int[] itemPositions = item.itemPosition;
        String[] itemIds = item.itemId;
        if (itemPositions != null) {
            int end = itemPositions.length;
            for (int i = end - 1; i >= 0; i--) {
                int itemPosition = itemPositions[i];
                String id = itemIds[i];
                if (id == null) {
                    Log.w(TAG, "You have to set a id value to use the undo action");
                } else {
                    Card card = mInternalObjects.get(id);
                    if (card != null) {
                        insert(card, itemPosition);
                        notifyDataSetChanged();
                        if (card.getOnUndoSwipeListListener() != null)
                            card.getOnUndoSwipeListListener().onUndoSwipe(card);
                    }
                }
            }
        }
    }
}
Also used : UndoCard(it.gmariotti.cardslib.library.view.listener.UndoCard) UndoCard(it.gmariotti.cardslib.library.view.listener.UndoCard)

Aggregations

UndoCard (it.gmariotti.cardslib.library.view.listener.UndoCard)1