Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnimateAddViewHolder, AnimateRemoveViewHolder and AnimateChangeViewHolder #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
Expand All @@ -30,7 +31,9 @@
import java.util.ArrayList;
import java.util.List;

import jp.wasabeef.recyclerview.animators.holder.AnimateViewHolder;
import jp.wasabeef.recyclerview.animators.holder.AnimateAddViewHolder;
import jp.wasabeef.recyclerview.animators.holder.AnimateChangeViewHolder;
import jp.wasabeef.recyclerview.animators.holder.AnimateRemoveViewHolder;
import jp.wasabeef.recyclerview.internal.ViewHelper;

public abstract class BaseItemAnimator extends SimpleItemAnimator {
Expand Down Expand Up @@ -107,7 +110,16 @@ public void setInterpolator(Interpolator mInterpolator) {
this.mInterpolator = mInterpolator;
}

@Override public void runPendingAnimations() {
@Override
public boolean canReuseUpdatedViewHolder(@NonNull final ViewHolder viewHolder, @NonNull final List<Object> payloads) {
if (viewHolder instanceof AnimateChangeViewHolder) {
return ((AnimateChangeViewHolder) viewHolder).canAnimateChange(payloads);
} else {
return super.canReuseUpdatedViewHolder(viewHolder, payloads);
}
}

@Override public void runPendingAnimations() {
boolean removalsPending = !mPendingRemovals.isEmpty();
boolean movesPending = !mPendingMoves.isEmpty();
boolean changesPending = !mPendingChanges.isEmpty();
Expand Down Expand Up @@ -219,8 +231,8 @@ protected void preAnimateAddImpl(final RecyclerView.ViewHolder holder) {
private void preAnimateRemove(final RecyclerView.ViewHolder holder) {
ViewHelper.clear(holder.itemView);

if (holder instanceof AnimateViewHolder) {
((AnimateViewHolder) holder).preAnimateRemoveImpl(holder);
if (holder instanceof AnimateRemoveViewHolder) {
((AnimateRemoveViewHolder) holder).preAnimateRemoveImpl(holder);
} else {
preAnimateRemoveImpl(holder);
}
Expand All @@ -229,16 +241,16 @@ private void preAnimateRemove(final RecyclerView.ViewHolder holder) {
private void preAnimateAdd(final RecyclerView.ViewHolder holder) {
ViewHelper.clear(holder.itemView);

if (holder instanceof AnimateViewHolder) {
((AnimateViewHolder) holder).preAnimateAddImpl(holder);
if (holder instanceof AnimateAddViewHolder) {
((AnimateAddViewHolder) holder).preAnimateAddImpl(holder);
} else {
preAnimateAddImpl(holder);
}
}

private void doAnimateRemove(final RecyclerView.ViewHolder holder) {
if (holder instanceof AnimateViewHolder) {
((AnimateViewHolder) holder).animateRemoveImpl(holder, new DefaultRemoveVpaListener(holder));
if (holder instanceof AnimateRemoveViewHolder) {
((AnimateRemoveViewHolder) holder).animateRemoveImpl(holder, new DefaultRemoveVpaListener(holder));
} else {
animateRemoveImpl(holder);
}
Expand All @@ -247,8 +259,8 @@ private void doAnimateRemove(final RecyclerView.ViewHolder holder) {
}

private void doAnimateAdd(final RecyclerView.ViewHolder holder) {
if (holder instanceof AnimateViewHolder) {
((AnimateViewHolder) holder).animateAddImpl(holder, new DefaultAddVpaListener(holder));
if (holder instanceof AnimateAddViewHolder) {
((AnimateAddViewHolder) holder).animateAddImpl(holder, new DefaultAddVpaListener(holder));
} else {
animateAddImpl(holder);
}
Expand Down Expand Up @@ -341,6 +353,12 @@ private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY,
int toX, int toY) {

if (oldHolder == newHolder && fromX == toX && fromY == toY) {
dispatchChangeFinished(newHolder, true);
return false;
}

final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package jp.wasabeef.recyclerview.animators.holder;

import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v7.widget.RecyclerView;

public interface AnimateAddViewHolder {

void preAnimateAddImpl(final RecyclerView.ViewHolder holder);

void animateAddImpl(final RecyclerView.ViewHolder holder, ViewPropertyAnimatorListener listener);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package jp.wasabeef.recyclerview.animators.holder;
import android.support.annotation.NonNull;

import java.util.List;

public interface AnimateChangeViewHolder {

boolean canAnimateChange(@NonNull List<Object> payloads);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package jp.wasabeef.recyclerview.animators.holder;

import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v7.widget.RecyclerView;

public interface AnimateRemoveViewHolder {

void preAnimateRemoveImpl(final RecyclerView.ViewHolder holder);

void animateRemoveImpl(final RecyclerView.ViewHolder holder, ViewPropertyAnimatorListener listener);

}

This file was deleted.