Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

Commit

Permalink
Handle user-provided OnScrollListeners
Browse files Browse the repository at this point in the history
Otherwise, if a user passes one (for endless scrolling, for example),
our "pause" functionality breaks
  • Loading branch information
dhleong committed May 21, 2014
1 parent 92fb640 commit 2af4137
Showing 1 changed file with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ public void handleMessage(final Message msg) {
private long mAnimationTime;

private final Object[] mAnimationLock = new Object[0];

private OnScrollListener mUserScrollListener;

// Swipe-To-Dismiss
private boolean mSwipeEnabled;
Expand Down Expand Up @@ -355,6 +357,27 @@ public void handleMessage(final Message msg) {
private Button mUndoButton;
// END Swipe-To-Dismiss

private final OnScrollListener mScrollListener = new OnScrollListener() {

@Override
public void onScrollStateChanged(final AbsListView view, final int scrollState) {
mSwipePaused = scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL;

// call through to user's listener
final OnScrollListener userScrollListener = mUserScrollListener;
if (userScrollListener != null)
userScrollListener.onScrollStateChanged(view, scrollState);
}

@Override
public void onScroll(final AbsListView view, final int firstVisibleItem,
final int visibleItemCount, final int totalItemCount) {
final OnScrollListener userScrollListener = mUserScrollListener;
if (userScrollListener != null)
userScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
};

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -414,7 +437,7 @@ public boolean onTouch(final View v, final MotionEvent event) {
mScreenDensity = getResources().getDisplayMetrics().density;
// END initialize undo popup

setOnScrollListener(makeScrollListener());
super.setOnScrollListener(mScrollListener);

}

Expand Down Expand Up @@ -453,6 +476,14 @@ public EnhancedListView disableSwipeToDismiss() {
mSwipeEnabled = false;
return this;
}

@Override
public void setOnScrollListener(final OnScrollListener l) {
mUserScrollListener = l;

// call super again with ours so it gets fired as expected
super.setOnScrollListener(mScrollListener);
}

/**
* Sets the callback to be called when the user dismissed an item from the list (either by
Expand Down Expand Up @@ -928,19 +959,6 @@ private void changeButtonLabel() {
mUndoButton.setText(msg);
}

private OnScrollListener makeScrollListener() {
return new OnScrollListener() {
@Override
public void onScrollStateChanged(final AbsListView view, final int scrollState) {
mSwipePaused = scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL;
}

@Override
public void onScroll(final AbsListView view, final int firstVisibleItem, final int visibleItemCount, final int totalItemCount) {
}
};
}

/**
* Checks whether the delta of a swipe indicates, that the swipe is in the
* correct direction, regarding the direction set via
Expand Down

0 comments on commit 2af4137

Please sign in to comment.