Skip to content

Commit

Permalink
Отладил плавное закрываение при клике на другой элемент
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachilin Ivan committed Feb 18, 2019
1 parent 825f813 commit a7aeee1
Showing 1 changed file with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public class ItemTouchHelperExtension extends RecyclerView.ItemDecoration

private RecyclerView mRecyclerView;
private ValueAnimator mDemoSwipe = null;
private Boolean isAnimatedCloseOpenedPreItem = false;

/**
* When user drags a view to the edge, we start scrolling the LayoutManager as long as View
Expand Down Expand Up @@ -413,6 +414,7 @@ private void closeOpenedPreItem() {
objectAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
isAnimatedCloseOpenedPreItem = true;
super.onAnimationStart(animation);
if (mPreOpened != null) mCallback.clearView(mRecyclerView, mPreOpened);
if (mPreOpened != null) mPendingCleanup.remove(mPreOpened.itemView);
Expand All @@ -422,6 +424,7 @@ public void onAnimationStart(Animator animation) {

@Override
public void onAnimationEnd(Animator animation) {
isAnimatedCloseOpenedPreItem = false;
super.onAnimationEnd(animation);
mRecoverAnimations.clear();
}
Expand Down Expand Up @@ -670,40 +673,42 @@ private void select(ViewHolder selected, int actionState) {
getSelectedDxDy(mTmpPosition);
final float currentTranslateX = mTmpPosition[0];
final float currentTranslateY = mTmpPosition[1];
final RecoverAnimation rv = new RecoverAnimation(prevSelected, animationType,
prevActionState, currentTranslateX, currentTranslateY,
targetTranslateX, targetTranslateY) {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (this.mOverridden) {
return;
}
if (swipeDir <= 0) {
// this is a drag or failed swipe. recover immediately
mCallback.clearView(mRecyclerView, prevSelected);
} else {
// wait until remove animation is complete.
mPendingCleanup.add(prevSelected.itemView);
mPreOpened = prevSelected;
mIsPendingCleanup = true;
if (swipeDir > 0) {
// Animation might be ended by other animators during a layout.
// We defer callback to avoid editing adapter during a layout.
postDispatchSwipe(this, swipeDir);
if (!isAnimatedCloseOpenedPreItem) {
final RecoverAnimation rv = new RecoverAnimation(prevSelected, animationType,
prevActionState, currentTranslateX, currentTranslateY,
targetTranslateX, targetTranslateY) {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (this.mOverridden) {
return;
}
if (swipeDir <= 0) {
// this is a drag or failed swipe. recover immediately
mCallback.clearView(mRecyclerView, prevSelected);
} else {
// wait until remove animation is complete.
mPendingCleanup.add(prevSelected.itemView);
mPreOpened = prevSelected;
mIsPendingCleanup = true;
if (swipeDir > 0) {
// Animation might be ended by other animators during a layout.
// We defer callback to avoid editing adapter during a layout.
postDispatchSwipe(this, swipeDir);
}
}
// removed from the list after it is drawn for the last time
if (mOverdrawChild == prevSelected.itemView) {
removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
}
}
// removed from the list after it is drawn for the last time
if (mOverdrawChild == prevSelected.itemView) {
removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
}
}
};
final long duration = mCallback.getAnimationDuration(mRecyclerView, animationType,
targetTranslateX - currentTranslateX, targetTranslateY - currentTranslateY);
rv.setDuration(duration);
mRecoverAnimations.add(rv);
rv.start();
};
final long duration = mCallback.getAnimationDuration(mRecyclerView, animationType,
targetTranslateX - currentTranslateX, targetTranslateY - currentTranslateY);
rv.setDuration(duration);
mRecoverAnimations.add(rv);
rv.start();
}
preventLayout = true;
} else {
removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
Expand Down Expand Up @@ -1237,7 +1242,6 @@ public float getInterpolation(float input) {
mDemoSwipe.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Log.d("DBG", "updateListener");
mDx = Integer.valueOf(animation.getAnimatedValue().toString());
moveIfNecessary(viewHolder);
mRecyclerView.removeCallbacks(mScrollRunnable);
Expand Down Expand Up @@ -2562,7 +2566,6 @@ public float getHitY() {

@Override
public void onAnimationStart(Animator animation) {

}

@Override
Expand All @@ -2580,7 +2583,6 @@ public void onAnimationCancel(Animator animation) {

@Override
public void onAnimationRepeat(Animator animation) {

}
}

Expand Down

0 comments on commit a7aeee1

Please sign in to comment.