use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.
the class PendingItemAnimator method endAnimations.
@Override
public void endAnimations() {
int count = mPendingMoves.size();
for (int i = count - 1; i >= 0; i--) {
MoveInfo item = mPendingMoves.get(i);
View view = item.holder.itemView;
ViewCompat.animate(view).cancel();
ViewCompat.setTranslationY(view, 0);
ViewCompat.setTranslationX(view, 0);
dispatchMoveFinished(item.holder);
mPendingMoves.remove(item);
}
count = mPendingRemovals.size();
for (int i = count - 1; i >= 0; i--) {
H item = mPendingRemovals.get(i);
dispatchRemoveFinished(item);
mPendingRemovals.remove(item);
}
count = mPendingAdditions.size();
for (int i = count - 1; i >= 0; i--) {
H item = mPendingAdditions.get(i);
dispatchAddFinished(item);
mPendingAdditions.remove(item);
}
if (!isRunning()) {
return;
}
count = mMoveAnimations.size();
for (int i = count - 1; i >= 0; i--) {
ViewHolder item = mMoveAnimations.get(i);
View view = item.itemView;
ViewCompat.animate(view).cancel();
ViewCompat.setTranslationY(view, 0);
ViewCompat.setTranslationX(view, 0);
dispatchMoveFinished(item);
mMoveAnimations.remove(item);
}
count = mRemoveAnimations.size();
for (int i = count - 1; i >= 0; i--) {
H item = mRemoveAnimations.get(i);
View view = item.itemView;
ViewCompat.animate(view).cancel();
dispatchRemoveFinished(item);
mRemoveAnimations.remove(item);
}
count = mAddAnimations.size();
for (int i = count - 1; i >= 0; i--) {
H item = mAddAnimations.get(i);
View view = item.itemView;
ViewCompat.animate(view).cancel();
dispatchAddFinished(item);
mAddAnimations.remove(item);
}
mMoves.clear();
mAdditions.clear();
dispatchAnimationsFinished();
}
use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.
the class FlexibleItemAnimator method runChangeAnimation.
// 3rd Change
private void runChangeAnimation(boolean removalsPending, boolean changesPending) {
// Change animation to run in parallel with move animations
if (changesPending) {
final ArrayList<ChangeInfo> changes = new ArrayList<>();
changes.addAll(mPendingChanges);
mChangesList.add(changes);
mPendingChanges.clear();
Runnable changer = new Runnable() {
@Override
public void run() {
for (ChangeInfo change : changes) {
animateChangeImpl(change);
}
changes.clear();
mChangesList.remove(changes);
}
};
if (removalsPending) {
ViewHolder holder = changes.get(0).oldHolder;
ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
} else {
changer.run();
}
}
}
use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.
the class FlexibleItemAnimator method endAnimations.
@Override
public void endAnimations() {
int count = mPendingMoves.size();
for (int i = count - 1; i >= 0; i--) {
MoveInfo item = mPendingMoves.get(i);
View view = item.holder.itemView;
view.setTranslationY(0);
view.setTranslationX(0);
dispatchMoveFinished(item.holder);
mPendingMoves.remove(i);
}
count = mPendingRemovals.size();
for (int i = count - 1; i >= 0; i--) {
ViewHolder item = mPendingRemovals.get(i);
dispatchRemoveFinished(item);
mPendingRemovals.remove(i);
}
count = mPendingAdditions.size();
for (int i = count - 1; i >= 0; i--) {
ViewHolder item = mPendingAdditions.get(i);
clear(item.itemView);
dispatchAddFinished(item);
mPendingAdditions.remove(i);
}
count = mPendingChanges.size();
for (int i = count - 1; i >= 0; i--) {
endChangeAnimationIfNecessary(mPendingChanges.get(i));
}
mPendingChanges.clear();
if (!isRunning()) {
return;
}
int listCount = mMovesList.size();
for (int i = listCount - 1; i >= 0; i--) {
ArrayList<MoveInfo> moves = mMovesList.get(i);
count = moves.size();
for (int j = count - 1; j >= 0; j--) {
MoveInfo moveInfo = moves.get(j);
ViewHolder item = moveInfo.holder;
View view = item.itemView;
view.setTranslationY(0);
view.setTranslationX(0);
dispatchMoveFinished(moveInfo.holder);
moves.remove(j);
if (moves.isEmpty()) {
mMovesList.remove(moves);
}
}
}
listCount = mAdditionsList.size();
for (int i = listCount - 1; i >= 0; i--) {
ArrayList<ViewHolder> additions = mAdditionsList.get(i);
count = additions.size();
for (int j = count - 1; j >= 0; j--) {
ViewHolder item = additions.get(j);
View view = item.itemView;
view.setAlpha(1);
dispatchAddFinished(item);
// Prevent exception when removal already occurred during finishing animation
if (j < additions.size()) {
additions.remove(j);
}
if (additions.isEmpty()) {
mAdditionsList.remove(additions);
}
}
}
listCount = mChangesList.size();
for (int i = listCount - 1; i >= 0; i--) {
ArrayList<ChangeInfo> changes = mChangesList.get(i);
count = changes.size();
for (int j = count - 1; j >= 0; j--) {
endChangeAnimationIfNecessary(changes.get(j));
if (changes.isEmpty()) {
mChangesList.remove(changes);
}
}
}
cancelAll(mRemoveAnimations);
cancelAll(mMoveAnimations);
cancelAll(mAddAnimations);
cancelAll(mChangeAnimations);
dispatchAnimationsFinished();
}
use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.
the class FlexibleItemAnimator method runAddAnimation.
// 4th Add
private void runAddAnimation(boolean removalsPending, boolean changesPending, boolean movesPending, boolean additionsPending) {
if (additionsPending) {
final ArrayList<ViewHolder> additions = new ArrayList<>();
// Sorting addition animations based on it's original layout position
Collections.sort(mPendingAdditions, new Comparator<ViewHolder>() {
@Override
public int compare(ViewHolder vh1, ViewHolder vh2) {
return vh1.getLayoutPosition() - vh2.getLayoutPosition();
}
});
additions.addAll(mPendingAdditions);
mAdditionsList.add(additions);
mPendingAdditions.clear();
Runnable adder = new Runnable() {
public void run() {
int index = 0;
for (ViewHolder holder : additions) {
doAnimateAdd(holder, index++);
}
additions.clear();
mAdditionsList.remove(additions);
}
};
if (removalsPending || movesPending || changesPending) {
long removeDuration = removalsPending ? getRemoveDuration() : 0;
long moveDuration = movesPending ? getMoveDuration() : 0;
long changeDuration = changesPending ? getChangeDuration() : 0;
long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
View view = additions.get(0).itemView;
ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
} else {
adder.run();
}
}
}
use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project Lightning-Browser by anthonycr.
the class VerticalItemAnimator method endAnimation.
@Override
public void endAnimation(@NonNull ViewHolder item) {
final View view = item.itemView;
// this will trigger end callback which should set properties to their target values.
ViewCompat.animate(view).cancel();
// TODO if some other animations are chained to end, how do we cancel them as well?
for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
MoveInfo moveInfo = mPendingMoves.get(i);
if (moveInfo.holder == item) {
ViewCompat.setTranslationY(view, 0);
ViewCompat.setTranslationX(view, 0);
dispatchMoveFinished(item);
mPendingMoves.remove(i);
}
}
endChangeAnimation(mPendingChanges, item);
if (mPendingRemovals.remove(item)) {
ViewCompat.setAlpha(view, 1);
dispatchRemoveFinished(item);
}
if (mPendingAdditions.remove(item)) {
ViewCompat.setAlpha(view, 1);
dispatchAddFinished(item);
}
for (int i = mChangesList.size() - 1; i >= 0; i--) {
ArrayList<ChangeInfo> changes = mChangesList.get(i);
endChangeAnimation(changes, item);
if (changes.isEmpty()) {
mChangesList.remove(i);
}
}
for (int i = mMovesList.size() - 1; i >= 0; i--) {
ArrayList<MoveInfo> moves = mMovesList.get(i);
for (int j = moves.size() - 1; j >= 0; j--) {
MoveInfo moveInfo = moves.get(j);
if (moveInfo.holder == item) {
ViewCompat.setTranslationY(view, 0);
ViewCompat.setTranslationX(view, 0);
dispatchMoveFinished(item);
moves.remove(j);
if (moves.isEmpty()) {
mMovesList.remove(i);
}
break;
}
}
}
for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
ArrayList<ViewHolder> additions = mAdditionsList.get(i);
if (additions.remove(item)) {
ViewCompat.setAlpha(view, 1);
dispatchAddFinished(item);
if (additions.isEmpty()) {
mAdditionsList.remove(i);
}
}
}
// noinspection PointlessBooleanExpression,ConstantConditions
if (mRemoveAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mRemoveAnimations list");
}
// noinspection PointlessBooleanExpression,ConstantConditions
if (mAddAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mAddAnimations list");
}
// noinspection PointlessBooleanExpression,ConstantConditions
if (mChangeAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mChangeAnimations list");
}
// noinspection PointlessBooleanExpression,ConstantConditions
if (mMoveAnimations.remove(item) && DEBUG) {
throw new IllegalStateException("after animation is cancelled, item should not be in " + "mMoveAnimations list");
}
dispatchFinishedWhenDone();
}
Aggregations