Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Commit

Permalink
fix issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
BinShao authored and krossovochkin committed Jan 13, 2015
1 parent 0af2de6 commit 77d5edd
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
Expand Down Expand Up @@ -88,6 +89,7 @@ public class SwipeDismissRecyclerViewTouchListener implements View.OnTouchListen

// Transient properties
private List<PendingDismissData> mPendingDismisses = new ArrayList<PendingDismissData>();
private List<View> mAnimatedViews = new LinkedList<View>();
private int mDismissAnimationRefCount = 0;
private float mDownX;
private float mDownY;
Expand All @@ -98,6 +100,7 @@ public class SwipeDismissRecyclerViewTouchListener implements View.OnTouchListen
private View mDownView;
private boolean mPaused;

private final Object mAnimationLock = new Object();
/**
* The callback interface used by {@link SwipeDismissRecyclerViewTouchListener} to inform its client
* about a successful dismissal of one or more list item positions.
Expand Down Expand Up @@ -262,7 +265,13 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
// dismiss
final View downView = mDownView; // mDownView gets null'd before animation ends
final int downPosition = mDownPosition;
++mDismissAnimationRefCount;
synchronized (mAnimationLock) {
if (mAnimatedViews.contains(downView)) {
break;
}
++mDismissAnimationRefCount;
mAnimatedViews.add(downView);
}
mDownView.animate()
.translationX(dismissRight ? mViewWidth : -mViewWidth)
.alpha(0)
Expand Down Expand Up @@ -354,8 +363,13 @@ private void performDismiss(final View dismissView, final int dismissPosition) {
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
--mDismissAnimationRefCount;
if (mDismissAnimationRefCount == 0) {
boolean noAnimationLeft;
synchronized (mAnimationLock) {
--mDismissAnimationRefCount;
mAnimatedViews.remove(dismissView);
noAnimationLeft = mDismissAnimationRefCount == 0;
}
if (noAnimationLeft) {
// No active animations, process all pending dismisses.
// Sort by descending position
Collections.sort(mPendingDismisses);
Expand Down

0 comments on commit 77d5edd

Please sign in to comment.