Skip to content
This repository was archived by the owner on Jan 16, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions library/src/main/java/com/jensdriller/libs/undobar/UndoBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public interface Listener {
/**
* Will be fired when the undo bar disappears without being actioned.
*/
void onHide();
void onHide(Parcelable token);

/**
* Will be fired when the undo button is pressed.
Expand Down Expand Up @@ -392,8 +392,10 @@ public void onAnimationEnd() {
* Hides the undo bar and notifies potential listener.
*/
protected void onHide() {
// hide(true) will set mUndoToken to null, so we grab a reference and pass it to safelyNotifyOnHide()
Parcelable token = mUndoToken;
hide(true);
safelyNotifyOnHide();
safelyNotifyOnHide(token);
mUndoListener = null;
}

Expand All @@ -402,25 +404,27 @@ protected void onHide() {
* Hides the undo bar and notifies potential listener.
*/
protected void onUndo() {
// hide(true) will set mUndoToken to null, so we grab a reference and pass it to safelyNotifyOnHide()
Parcelable token = mUndoToken;
hide(true);
safelyNotifyOnUndo();
safelyNotifyOnUndo(token);
}

/**
* Notifies listener if available.
*/
protected void safelyNotifyOnHide() {
protected void safelyNotifyOnHide(Parcelable token) {
if (mUndoListener != null) {
mUndoListener.onHide();
mUndoListener.onHide(token);
}
}

/**
* Notifies listener if available.
*/
protected void safelyNotifyOnUndo() {
protected void safelyNotifyOnUndo(Parcelable token) {
if (mUndoListener != null) {
mUndoListener.onUndo(mUndoToken);
mUndoListener.onUndo(token);
}
}

Expand Down