Skip to content

Commit

Permalink
Added methods to cancel and remove pending items
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaarman committed Feb 10, 2014
1 parent 32a2715 commit 3b9ef99
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ public class ContextualUndoAdapter extends BaseAdapterDecorator implements Conte
private ContextualUndoView mCurrentRemovedView;
private long mCurrentRemovedId;

private Handler mHandler;
private final Handler mHandler;
private final CountDownRunnable mCountDownRunnable;

private CountDownRunnable mCountDownRunnable;

private DeleteItemCallback mDeleteItemCallback;
private CountDownFormatter mCountDownFormatter;
private final DeleteItemCallback mDeleteItemCallback;
private final CountDownFormatter mCountDownFormatter;

private ContextualUndoListViewTouchListener mContextualUndoListViewTouchListener;

Expand Down Expand Up @@ -360,16 +359,41 @@ public void setTouchChild(int childResId) {
* Removes any item that was swiped away.
* @param animate If true, animates the removal (collapsing the item).
* If false, removes item immediately without animation.
* @deprecated use {@link #removePendingItem()} or {@link #animateRemovePendingItem()} instead.
*/
@Deprecated
public void removePendingItem(boolean animate) {
if (animate) {
removePreviousContextualUndoIfPresent();
} else if ((mCurrentRemovedView != null) || (mCurrentRemovedId >= 0)) {
animateRemovePendingItem();
} else {
removePendingItem();
}
}

/**
* Cancels the count down, and removes any item that was swiped away, without animating. Will cause {@link DeleteItemCallback#deleteItem(int)} to be called.
*/
public void removePendingItem() {
if ((mCurrentRemovedView != null) || (mCurrentRemovedId >= 0)) {
new RemoveViewAnimatorListenerAdapter(mCurrentRemovedView, mCurrentRemovedId).onAnimationEnd(null);
clearCurrentRemovedView();
}
}

/**
* Removes any item that was swiped away, animating the removal (collapsing the item). {@link DeleteItemCallback#deleteItem(int)} to be called.
*/
public void animateRemovePendingItem() {
removePreviousContextualUndoIfPresent();
}

/**
* Cancel the count down. This will not cause the {@link DeleteItemCallback#deleteItem(int)} to be called. Use {@link #removePendingItem()} for that instead.
*/
private void cancelCountDown() {
mHandler.removeCallbacks(mCountDownRunnable);
}

/**
* A callback interface which is used to notify when items should be removed from the collection.
*/
Expand Down

0 comments on commit 3b9ef99

Please sign in to comment.