From 97fdad7004e43241eaa87cfafb16df8f5af2e77c Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 17 Jun 2019 23:50:32 -0700 Subject: Fix extra dependency errors --- fastadapter/build.gradle | 1 + .../allanwang/kau/animators/AnimatorInterfaces.kt | 50 -- .../allanwang/kau/animators/BaseItemAnimator.java | 765 --------------------- .../ca/allanwang/kau/animators/DefaultAnimator.kt | 77 --- .../allanwang/kau/animators/FadeScaleAnimator.kt | 73 -- .../ca/allanwang/kau/animators/KauAnimator.kt | 89 --- .../ca/allanwang/kau/animators/NoAnimator.kt | 55 -- .../ca/allanwang/kau/animators/SlideAnimator.kt | 83 --- 8 files changed, 1 insertion(+), 1192 deletions(-) delete mode 100644 fastadapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt delete mode 100644 fastadapter/src/main/kotlin/ca/allanwang/kau/animators/BaseItemAnimator.java delete mode 100644 fastadapter/src/main/kotlin/ca/allanwang/kau/animators/DefaultAnimator.kt delete mode 100644 fastadapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt delete mode 100644 fastadapter/src/main/kotlin/ca/allanwang/kau/animators/KauAnimator.kt delete mode 100644 fastadapter/src/main/kotlin/ca/allanwang/kau/animators/NoAnimator.kt delete mode 100644 fastadapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt (limited to 'fastadapter') diff --git a/fastadapter/build.gradle b/fastadapter/build.gradle index 86fd084..9fd848e 100644 --- a/fastadapter/build.gradle +++ b/fastadapter/build.gradle @@ -3,6 +3,7 @@ ext.kauSubModuleMinSdk = kau.Versions.coreMinSdk apply from: '../android-lib.gradle' dependencies { + implementation project(':core') api project(':adapter') api kau.Dependencies.fastAdapter diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt deleted file mode 100644 index b83a2d0..0000000 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/AnimatorInterfaces.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2018 Allan Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ca.allanwang.kau.animators - -import android.view.View -import android.view.ViewPropertyAnimator -import androidx.recyclerview.widget.RecyclerView - -/** - * Created by Allan Wang on 2017-07-11. - */ -class KauAnimatorException(message: String) : RuntimeException(message) - -interface KauAnimatorAdd { - fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit - fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit - fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit - fun getDelay(remove: Long, move: Long, change: Long): Long - var itemDelayFactor: Float -} - -interface KauAnimatorRemove { - fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit - fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit - fun getDelay(remove: Long, move: Long, change: Long): Long - var itemDelayFactor: Float -} - -interface KauAnimatorChange { - fun changeOldAnimation( - holder: RecyclerView.ViewHolder, - changeInfo: BaseItemAnimator.ChangeInfo - ): ViewPropertyAnimator.() -> Unit - - fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit - fun changeAnimationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit -} diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/BaseItemAnimator.java b/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/BaseItemAnimator.java deleted file mode 100644 index 4ead735..0000000 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/BaseItemAnimator.java +++ /dev/null @@ -1,765 +0,0 @@ -package ca.allanwang.kau.animators; - -/* - * Created by Allan Wang on 2017-06-27. - * - * Based on Item Animator by {@author Mike Penz} - * Rewritten to match with the updated compat dependencies - */ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.TimeInterpolator; -import android.animation.ValueAnimator; -import androidx.annotation.NonNull; -import androidx.core.view.ViewCompat; -import androidx.recyclerview.widget.RecyclerView.ViewHolder; -import androidx.recyclerview.widget.SimpleItemAnimator; - -import android.view.View; -import android.view.ViewPropertyAnimator; -import android.view.animation.Interpolator; - -import java.util.ArrayList; -import java.util.List; - -/** - * This implementation of {@link androidx.recyclerview.widget.RecyclerView.ItemAnimator} provides basic - * animations on remove, add, and move events that happen to the items in - * a RecyclerView. RecyclerView uses a DefaultItemAnimator by default. - * - * @see androidx.recyclerview.widget.RecyclerView#setItemAnimator(androidx.recyclerview.widget.RecyclerView.ItemAnimator) - */ -public abstract class BaseItemAnimator extends SimpleItemAnimator { - private static final boolean DEBUG = false; - - private static TimeInterpolator sDefaultInterpolator; - - private ArrayList mPendingRemovals = new ArrayList<>(); - private ArrayList mPendingAdditions = new ArrayList<>(); - private ArrayList mPendingMoves = new ArrayList<>(); - private ArrayList mPendingChanges = new ArrayList<>(); - - ArrayList> mAdditionsList = new ArrayList<>(); - ArrayList> mMovesList = new ArrayList<>(); - ArrayList> mChangesList = new ArrayList<>(); - - ArrayList mAddAnimations = new ArrayList<>(); - ArrayList mMoveAnimations = new ArrayList<>(); - ArrayList mRemoveAnimations = new ArrayList<>(); - ArrayList mChangeAnimations = new ArrayList<>(); - - public Interpolator interpolator; - - private static class MoveInfo { - public ViewHolder holder; - public int fromX, fromY, toX, toY; - - MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) { - this.holder = holder; - this.fromX = fromX; - this.fromY = fromY; - this.toX = toX; - this.toY = toY; - } - } - - public static class ChangeInfo { - public ViewHolder oldHolder, newHolder; - public int fromX, fromY, toX, toY; - - private ChangeInfo(ViewHolder oldHolder, ViewHolder newHolder) { - this.oldHolder = oldHolder; - this.newHolder = newHolder; - } - - ChangeInfo(ViewHolder oldHolder, ViewHolder newHolder, - int fromX, int fromY, int toX, int toY) { - this(oldHolder, newHolder); - this.fromX = fromX; - this.fromY = fromY; - this.toX = toX; - this.toY = toY; - } - - @Override - public String toString() { - return "ChangeInfo{" - + "oldHolder=" + oldHolder - + ", newHolder=" + newHolder - + ", fromX=" + fromX - + ", fromY=" + fromY - + ", toX=" + toX - + ", toY=" + toY - + '}'; - } - } - - @Override - public void runPendingAnimations() { - boolean removalsPending = !mPendingRemovals.isEmpty(); - boolean movesPending = !mPendingMoves.isEmpty(); - boolean changesPending = !mPendingChanges.isEmpty(); - boolean additionsPending = !mPendingAdditions.isEmpty(); - if (!removalsPending && !movesPending && !additionsPending && !changesPending) { - // nothing to animate - return; - } - // First, remove stuff - for (ViewHolder holder : mPendingRemovals) { - animateRemoveImpl(holder); - } - mPendingRemovals.clear(); - // Next, move stuff - if (movesPending) { - final ArrayList moves = new ArrayList<>(); - moves.addAll(mPendingMoves); - mMovesList.add(moves); - mPendingMoves.clear(); - Runnable mover = new Runnable() { - @Override - public void run() { - for (MoveInfo moveInfo : moves) { - animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, - moveInfo.toX, moveInfo.toY); - } - moves.clear(); - mMovesList.remove(moves); - } - }; - if (removalsPending) { - View view = moves.get(0).holder.itemView; - ViewCompat.postOnAnimationDelayed(view, mover, 0); - } else { - mover.run(); - } - } - // Next, change stuff, to run in parallel with move animations - if (changesPending) { - final ArrayList 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; - long moveDuration = movesPending ? getMoveDuration() : 0; - ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDelay(getRemoveDuration(), moveDuration, getChangeDuration())); - } else { - changer.run(); - } - } - // Next, add stuff - if (additionsPending) { - final ArrayList additions = new ArrayList<>(); - additions.addAll(mPendingAdditions); - mAdditionsList.add(additions); - mPendingAdditions.clear(); - Runnable adder = new Runnable() { - @Override - public void run() { - for (ViewHolder holder : additions) { - animateAddImpl(holder); - } - additions.clear(); - mAdditionsList.remove(additions); - } - }; - if (removalsPending || movesPending || changesPending) { - long removeDuration = removalsPending ? getRemoveDuration() : 0; - long moveDuration = movesPending ? getMoveDuration() : 0; - long changeDuration = changesPending ? getChangeDuration() : 0; - View view = additions.get(0).itemView; - ViewCompat.postOnAnimationDelayed(view, adder, getAddDelay(removeDuration, moveDuration, changeDuration)); - } else { - adder.run(); - } - } - } - - /** - * used to calculated the delay until the remove animation should start - * - * @param remove the remove duration - * @param move the move duration - * @param change the change duration - * @return the calculated delay for the remove items animation - */ - public long getRemoveDelay(long remove, long move, long change) { - return remove + Math.max(move, change); - } - - /** - * used to calculated the delay until the add animation should start - * - * @param remove the remove duration - * @param move the move duration - * @param change the change duration - * @return the calculated delay for the add items animation - */ - public long getAddDelay(long remove, long move, long change) { - return remove + Math.max(move, change); - } - - @Override - public boolean animateRemove(final ViewHolder holder) { - resetAnimation(holder); - mPendingRemovals.add(holder); - return true; - } - - private void animateRemoveImpl(final ViewHolder holder) { - final ViewPropertyAnimator animation = removeAnimation(holder); - mRemoveAnimations.add(holder); - animation.setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animator) { - dispatchRemoveStarting(holder); - } - - @Override - public void onAnimationEnd(Animator animator) { - animation.setListener(null); - removeAnimationCleanup(holder); - dispatchRemoveFinished(holder); - mRemoveAnimations.remove(holder); - dispatchFinishedWhenDone(); - } - }).start(); - } - - abstract public ViewPropertyAnimator removeAnimation(ViewHolder holder); - - abstract public void removeAnimationCleanup(ViewHolder holder); - - @Override - public boolean animateAdd(final ViewHolder holder) { - resetAnimation(holder); - addAnimationPrepare(holder); - mPendingAdditions.add(holder); - return true; - } - - void animateAddImpl(final ViewHolder holder) { - final ViewPropertyAnimator animation = addAnimation(holder); - mAddAnimations.add(holder); - animation.setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animator) { - dispatchAddStarting(holder); - } - - @Override - public void onAnimationCancel(Animator animator) { - addAnimationCleanup(holder); - } - - @Override - public void onAnimationEnd(Animator animator) { - animation.setListener(null); - dispatchAddFinished(holder); - mAddAnimations.remove(holder); - dispatchFinishedWhenDone(); - addAnimationCleanup(holder); - } - }).start(); - } - - /** - * the animation to prepare the view before the add animation is run - * - * @param holder - */ - public abstract void addAnimationPrepare(ViewHolder holder); - - /** - * the animation for adding a view - * - * @param holder - * @return - */ - public abstract ViewPropertyAnimator addAnimation(ViewHolder holder); - - /** - * the cleanup method if the animation needs to be stopped. and tro prepare for the next view - * - * @param holder - */ - abstract void addAnimationCleanup(ViewHolder holder); - - @Override - public boolean animateMove(final ViewHolder holder, int fromX, int fromY, - int toX, int toY) { - final View view = holder.itemView; - fromX += (int) holder.itemView.getTranslationX(); - fromY += (int) holder.itemView.getTranslationY(); - resetAnimation(holder); - int deltaX = toX - fromX; - int deltaY = toY - fromY; - if (deltaX == 0 && deltaY == 0) { - dispatchMoveFinished(holder); - return false; - } - if (deltaX != 0) { - view.setTranslationX(-deltaX); - } - if (deltaY != 0) { - view.setTranslationY(-deltaY); - } - mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY)); - return true; - } - - void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) { - final View view = holder.itemView; - final int deltaX = toX - fromX; - final int deltaY = toY - fromY; - if (deltaX != 0) { - view.animate().translationX(0); - } - if (deltaY != 0) { - view.animate().translationY(0); - } - // TODO: make EndActions end listeners instead, since end actions aren't called when - // vpas are canceled (and can't end them. why?) - // need listener functionality in VPACompat for this. Ick. - final ViewPropertyAnimator animation = view.animate(); - mMoveAnimations.add(holder); - animation.setDuration(getMoveDuration()).setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animator) { - dispatchMoveStarting(holder); - } - - @Override - public void onAnimationCancel(Animator animator) { - if (deltaX != 0) { - view.setTranslationX(0); - } - if (deltaY != 0) { - view.setTranslationY(0); - } - } - - @Override - public void onAnimationEnd(Animator animator) { - animation.setListener(null); - dispatchMoveFinished(holder); - mMoveAnimations.remove(holder); - dispatchFinishedWhenDone(); - } - }).start(); - } - - @Override - public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, - int fromX, int fromY, int toX, int toY) { - if (oldHolder == newHolder) { - // Don't know how to run change animations when the same view holder is re-used. - // run a move animation to handle position changes. - return animateMove(oldHolder, fromX, fromY, toX, toY); - } - changeAnimation(oldHolder, newHolder, - fromX, fromY, toX, toY); - mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY)); - return true; - } - - void animateChangeImpl(final ChangeInfo changeInfo) { - final ViewHolder holder = changeInfo.oldHolder; - final View view = holder == null ? null : holder.itemView; - final ViewHolder newHolder = changeInfo.newHolder; - final View newView = newHolder != null ? newHolder.itemView : null; - if (view != null) { - final ViewPropertyAnimator oldViewAnim = changeOldAnimation(holder, changeInfo); - mChangeAnimations.add(changeInfo.oldHolder); - oldViewAnim.setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animator) { - dispatchChangeStarting(changeInfo.oldHolder, true); - } - - @Override - public void onAnimationEnd(Animator animator) { - oldViewAnim.setListener(null); - changeAnimationCleanup(holder); - view.setTranslationX(0); - view.setTranslationY(0); - dispatchChangeFinished(changeInfo.oldHolder, true); - mChangeAnimations.remove(changeInfo.oldHolder); - dispatchFinishedWhenDone(); - } - }).start(); - } - if (newView != null) { - final ViewPropertyAnimator newViewAnimation = changeNewAnimation(newHolder); - mChangeAnimations.add(changeInfo.newHolder); - newViewAnimation.setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animator) { - dispatchChangeStarting(changeInfo.newHolder, false); - } - - @Override - public void onAnimationEnd(Animator animator) { - newViewAnimation.setListener(null); - changeAnimationCleanup(newHolder); - newView.setTranslationX(0); - newView.setTranslationY(0); - dispatchChangeFinished(changeInfo.newHolder, false); - mChangeAnimations.remove(changeInfo.newHolder); - dispatchFinishedWhenDone(); - } - }).start(); - } - } - - /** - * the whole change animation if we have to cross animate two views - * - * @param oldHolder - * @param newHolder - * @param fromX - * @param fromY - * @param toX - * @param toY - */ - public void changeAnimation(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { - final float prevTranslationX = oldHolder.itemView.getTranslationX(); - final float prevTranslationY = oldHolder.itemView.getTranslationY(); - final float prevValue = oldHolder.itemView.getAlpha(); - resetAnimation(oldHolder); - int deltaX = (int) (toX - fromX - prevTranslationX); - int deltaY = (int) (toY - fromY - prevTranslationY); - // recover prev translation state after ending animation - oldHolder.itemView.setTranslationX(prevTranslationX); - oldHolder.itemView.setTranslationY(prevTranslationY); - - oldHolder.itemView.setAlpha(prevValue); - if (newHolder != null) { - // carry over translation values - resetAnimation(newHolder); - newHolder.itemView.setTranslationX(-deltaX); - newHolder.itemView.setTranslationY(-deltaY); - newHolder.itemView.setAlpha(0); - } - } - - /** - * the animation for removing the old view - * - * @param holder - * @return - */ - public abstract ViewPropertyAnimator changeOldAnimation(ViewHolder holder, ChangeInfo changeInfo); - - /** - * the animation for changing the new view - * - * @param holder - * @return - */ - public abstract ViewPropertyAnimator changeNewAnimation(ViewHolder holder); - - /** - * the cleanup method if the animation needs to be stopped. and to prepare for the next view - * - * @param holder - */ - public abstract void changeAnimationCleanup(ViewHolder holder); - - private void endChangeAnimation(List infoList, ViewHolder item) { - for (int i = infoList.size() - 1; i >= 0; i--) { - ChangeInfo changeInfo = infoList.get(i); - if (endChangeAnimationIfNecessary(changeInfo, item)) { - if (changeInfo.oldHolder == null && changeInfo.newHolder == null) { - infoList.remove(changeInfo); - } - } - } - } - - private void endChangeAnimationIfNecessary(ChangeInfo changeInfo) { - if (changeInfo.oldHolder != null) { - endChangeAnimationIfNecessary(changeInfo, changeInfo.oldHolder); - } - if (changeInfo.newHolder != null) { - endChangeAnimationIfNecessary(changeInfo, changeInfo.newHolder); - } - } - - private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) { - boolean oldItem = false; - if (changeInfo.newHolder == item) { - changeInfo.newHolder = null; - } else if (changeInfo.oldHolder == item) { - changeInfo.oldHolder = null; - oldItem = true; - } else { - return false; - } - changeAnimationCleanup(item); - item.itemView.setTranslationX(0); - item.itemView.setTranslationY(0); - dispatchChangeFinished(item, oldItem); - return true; - } - - @Override - public void endAnimation(ViewHolder item) { - final View view = item.itemView; - // this will trigger end callback which should set properties to their target values. - view.animate().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) { - view.setTranslationY(0); - view.setTranslationX(0); - dispatchMoveFinished(item); - mPendingMoves.remove(i); - } - } - endChangeAnimation(mPendingChanges, item); - if (mPendingRemovals.remove(item)) { - removeAnimationCleanup(item); - dispatchRemoveFinished(item); - } - if (mPendingAdditions.remove(item)) { - addAnimationCleanup(item); - dispatchAddFinished(item); - } - - for (int i = mChangesList.size() - 1; i >= 0; i--) { - ArrayList changes = mChangesList.get(i); - endChangeAnimation(changes, item); - if (changes.isEmpty()) { - mChangesList.remove(i); - } - } - for (int i = mMovesList.size() - 1; i >= 0; i--) { - ArrayList moves = mMovesList.get(i); - for (int j = moves.size() - 1; j >= 0; j--) { - MoveInfo moveInfo = moves.get(j); - if (moveInfo.holder == item) { - view.setTranslationY(0); - view.setTranslationX(0); - dispatchMoveFinished(item); - moves.remove(j); - if (moves.isEmpty()) { - mMovesList.remove(i); - } - break; - } - } - } - for (int i = mAdditionsList.size() - 1; i >= 0; i--) { - ArrayList additions = mAdditionsList.get(i); - if (additions.remove(item)) { - addAnimationCleanup(item); - dispatchAddFinished(item); - if (additions.isEmpty()) { - mAdditionsList.remove(i); - } - } - } - - // animations should be ended by the cancel above. - //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(); - } - - private void resetAnimation(ViewHolder holder) { - - if (sDefaultInterpolator == null) { - sDefaultInterpolator = new ValueAnimator().getInterpolator(); - } - holder.itemView.animate().setInterpolator(sDefaultInterpolator); - endAnimation(holder); - } - - @Override - public boolean isRunning() { - return (!mPendingAdditions.isEmpty() - || !mPendingChanges.isEmpty() - || !mPendingMoves.isEmpty() - || !mPendingRemovals.isEmpty() - || !mMoveAnimations.isEmpty() - || !mRemoveAnimations.isEmpty() - || !mAddAnimations.isEmpty() - || !mChangeAnimations.isEmpty() - || !mMovesList.isEmpty() - || !mAdditionsList.isEmpty() - || !mChangesList.isEmpty()); - } - - /** - * Check the state of currently pending and running animations. If there are none - * pending/running, call {@link #dispatchAnimationsFinished()} to notify any - * listeners. - */ - void dispatchFinishedWhenDone() { - if (!isRunning()) { - dispatchAnimationsFinished(); - } - } - - @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); - addAnimationCleanup(item); - 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 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 additions = mAdditionsList.get(i); - count = additions.size(); - for (int j = count - 1; j >= 0; j--) { - ViewHolder item = additions.get(j); - View view = item.itemView; - addAnimationCleanup(item); - dispatchAddFinished(item); - additions.remove(j); - if (additions.isEmpty()) { - mAdditionsList.remove(additions); - } - } - } - listCount = mChangesList.size(); - for (int i = listCount - 1; i >= 0; i--) { - ArrayList 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(); - } - - void cancelAll(List viewHolders) { - for (int i = viewHolders.size() - 1; i >= 0; i--) { - viewHolders.get(i).itemView.animate().cancel(); - } - } - - /** - * {@inheritDoc} - *

- * If the payload list is not empty, DefaultItemAnimator returns true. - * When this is the case: - *

    - *
  • If you override {@link #animateChange(ViewHolder, ViewHolder, int, int, int, int)}, both - * ViewHolder arguments will be the same instance. - *
  • - *
  • - * If you are not overriding {@link #animateChange(ViewHolder, ViewHolder, int, int, int, int)}, - * then DefaultItemAnimator will call {@link #animateMove(ViewHolder, int, int, int, int)} and - * run a move animation instead. - *
  • - *
- */ - @Override - public boolean canReuseUpdatedViewHolder(@NonNull ViewHolder viewHolder, - @NonNull List payloads) { - return !payloads.isEmpty() || super.canReuseUpdatedViewHolder(viewHolder, payloads); - } -} diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/DefaultAnimator.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/DefaultAnimator.kt deleted file mode 100644 index 4e342ab..0000000 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/DefaultAnimator.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2018 Allan Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ca.allanwang.kau.animators - -import android.view.ViewPropertyAnimator -import androidx.recyclerview.widget.RecyclerView - -/** - * Created by Allan Wang on 2017-06-27. - */ -open class DefaultAnimator : BaseItemAnimator() { - - override fun removeAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return holder.itemView.animate().apply { - alpha(0f) - duration = this@DefaultAnimator.removeDuration - interpolator = this@DefaultAnimator.interpolator - } - } - - override fun removeAnimationCleanup(holder: RecyclerView.ViewHolder) { - holder.itemView.alpha = 1f - } - - override fun addAnimationPrepare(holder: RecyclerView.ViewHolder) { - holder.itemView.alpha = 0f - } - - override fun addAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return holder.itemView.animate().apply { - alpha(1f) - duration = this@DefaultAnimator.addDuration - interpolator = this@DefaultAnimator.interpolator - } - } - - override fun addAnimationCleanup(holder: RecyclerView.ViewHolder) { - holder.itemView.alpha = 1f - } - - override fun changeOldAnimation(holder: RecyclerView.ViewHolder, changeInfo: ChangeInfo): ViewPropertyAnimator { - return holder.itemView.animate().apply { - alpha(0f) - translationX(changeInfo.toX.toFloat() - changeInfo.fromX) - translationY(changeInfo.toY.toFloat() - changeInfo.fromY) - duration = this@DefaultAnimator.changeDuration - interpolator = this@DefaultAnimator.interpolator - } - } - - override fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return holder.itemView.animate().apply { - alpha(1f) - translationX(0f) - translationY(0f) - duration = this@DefaultAnimator.changeDuration - interpolator = this@DefaultAnimator.interpolator - } - } - - override fun changeAnimationCleanup(holder: RecyclerView.ViewHolder) { - holder.itemView.alpha = 1f - } -} diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt deleted file mode 100644 index 9113b0e..0000000 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/FadeScaleAnimator.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2018 Allan Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ca.allanwang.kau.animators - -import android.view.View -import android.view.ViewPropertyAnimator -import androidx.recyclerview.widget.RecyclerView -import ca.allanwang.kau.utils.scaleXY - -/** - * Created by Allan Wang on 2017-07-11. - */ -class FadeScaleAnimatorAdd(val scaleFactor: Float = 1.0f, override var itemDelayFactor: Float = 0.125f) : - KauAnimatorAdd { - - override fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit = { - scaleXY = scaleFactor - alpha = 0f - } - - override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { - scaleXY(1f) - alpha(1f) - } - - override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { - scaleXY = 1f - alpha = 1f - } - - override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L -} - -class FadeScaleAnimatorRemove(val scaleFactor: Float = 1.0f, override var itemDelayFactor: Float = 0.125f) : - KauAnimatorRemove { - - override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { - scaleXY(scaleFactor) - alpha(0f) - } - - override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { - scaleXY = 1f - alpha = 1f - } - - override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L -} - -class FadeAnimatorChange : KauAnimatorChange { - - override fun changeOldAnimation( - holder: RecyclerView.ViewHolder, - changeInfo: BaseItemAnimator.ChangeInfo - ): ViewPropertyAnimator.() -> Unit = { alpha(0f) } - - override fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { alpha(1f) } - - override fun changeAnimationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { alpha = 1f } -} diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/KauAnimator.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/KauAnimator.kt deleted file mode 100644 index b9df946..0000000 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/KauAnimator.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2018 Allan Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ca.allanwang.kau.animators - -import android.view.ViewPropertyAnimator -import androidx.recyclerview.widget.RecyclerView -import ca.allanwang.kau.utils.KAU_BOTTOM -import ca.allanwang.kau.utils.KAU_RIGHT - -/** - * Created by Allan Wang on 2017-06-27. - */ -open class KauAnimator( - val addAnimator: KauAnimatorAdd = SlideAnimatorAdd(KAU_BOTTOM), - val removeAnimator: KauAnimatorRemove = SlideAnimatorRemove(KAU_RIGHT), - val changeAnimator: KauAnimatorChange = FadeAnimatorChange() -) : BaseItemAnimator() { - - open fun startDelay(holder: RecyclerView.ViewHolder, duration: Long, factor: Float) = - Math.max(0L, (holder.adapterPosition * duration * factor).toLong()) - - override fun removeAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return holder.itemView.animate().apply { - startDelay = startDelay(holder, removeDuration, removeAnimator.itemDelayFactor) - duration = removeDuration - interpolator = this@KauAnimator.interpolator - removeAnimator.animation(holder)() - } - } - - override fun removeAnimationCleanup(holder: RecyclerView.ViewHolder) { - holder.itemView.apply { removeAnimator.animationCleanup(holder)() } - } - - override fun getRemoveDelay(remove: Long, move: Long, change: Long): Long = - removeAnimator.getDelay(remove, move, change) - - override fun addAnimationPrepare(holder: RecyclerView.ViewHolder) { - holder.itemView.apply { addAnimator.animationPrepare(holder)() } - } - - override fun addAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return holder.itemView.animate().apply { - startDelay = startDelay(holder, addDuration, addAnimator.itemDelayFactor) - duration = addDuration - interpolator = this@KauAnimator.interpolator - addAnimator.animation(holder)() - } - } - - override fun addAnimationCleanup(holder: RecyclerView.ViewHolder) { - holder.itemView.apply { addAnimator.animationCleanup(holder)() } - } - - override fun getAddDelay(remove: Long, move: Long, change: Long): Long = addAnimator.getDelay(remove, move, change) - - override fun changeOldAnimation(holder: RecyclerView.ViewHolder, changeInfo: ChangeInfo): ViewPropertyAnimator { - return holder.itemView.animate().apply { - duration = changeDuration - interpolator = this@KauAnimator.interpolator - changeAnimator.changeOldAnimation(holder, changeInfo)() - } - } - - override fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator { - return holder.itemView.animate().apply { - duration = changeDuration - interpolator = this@KauAnimator.interpolator - changeAnimator.changeNewAnimation(holder)() - } - } - - override fun changeAnimationCleanup(holder: RecyclerView.ViewHolder) { - holder.itemView.apply { changeAnimator.changeAnimationCleanup(holder)() } - } -} diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/NoAnimator.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/NoAnimator.kt deleted file mode 100644 index cca8a25..0000000 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/NoAnimator.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2018 Allan Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ca.allanwang.kau.animators - -import android.view.View -import android.view.ViewPropertyAnimator -import androidx.recyclerview.widget.RecyclerView - -/** - * Created by Allan Wang on 2017-08-02. - */ -class NoAnimatorAdd(override var itemDelayFactor: Float = 0f) : KauAnimatorAdd { - - override fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit = {} - - override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = {} - - override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { } - - override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L -} - -class NoAnimatorRemove(override var itemDelayFactor: Float = 0f) : KauAnimatorRemove { - - override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { } - - override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = {} - - override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L -} - -class NoAnimatorChange : KauAnimatorChange { - - override fun changeOldAnimation( - holder: RecyclerView.ViewHolder, - changeInfo: BaseItemAnimator.ChangeInfo - ): ViewPropertyAnimator.() -> Unit = { } - - override fun changeNewAnimation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { } - - override fun changeAnimationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { alpha = 1f } -} diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt deleted file mode 100644 index 55d5b2e..0000000 --- a/fastadapter/src/main/kotlin/ca/allanwang/kau/animators/SlideAnimator.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2018 Allan Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ca.allanwang.kau.animators - -import android.view.View -import android.view.ViewPropertyAnimator -import androidx.recyclerview.widget.RecyclerView -import ca.allanwang.kau.utils.KAU_BOTTOM -import ca.allanwang.kau.utils.KAU_LEFT -import ca.allanwang.kau.utils.KAU_RIGHT -import ca.allanwang.kau.utils.KAU_TOP - -/** - * Created by Allan Wang on 2017-07-11. - */ -class SlideAnimatorAdd(val fromEdge: Int, val slideFactor: Float = 1f, override var itemDelayFactor: Float = 0.125f) : - KauAnimatorAdd { - - override fun animationPrepare(holder: RecyclerView.ViewHolder): View.() -> Unit = { - when (fromEdge) { - KAU_TOP -> translationY = slideFactor * -height - KAU_LEFT -> translationX = slideFactor * -width - KAU_BOTTOM -> translationY = slideFactor * height - KAU_RIGHT -> translationX = slideFactor * width - else -> throw KauAnimatorException("Invalid edge flag used in Slide Animator; use one of KAU_*") - } - alpha = 0f - } - - override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { - translationY(0f) - translationX(0f) - alpha(1f) - } - - override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { - translationY = 0f - translationX = 0f - alpha = 1f - } - - override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L -} - -class SlideAnimatorRemove( - val fromEdge: Int, - val slideFactor: Float = 1f, - override var itemDelayFactor: Float = 0.125f -) : KauAnimatorRemove { - override fun animation(holder: RecyclerView.ViewHolder): ViewPropertyAnimator.() -> Unit = { - with(holder.itemView) { - when (fromEdge) { - KAU_TOP -> translationY(slideFactor * -height) - KAU_LEFT -> translationX(slideFactor * -width) - KAU_BOTTOM -> translationY(slideFactor * height) - KAU_RIGHT -> translationX(slideFactor * width) - else -> throw KauAnimatorException("Invalid edge flag used in Slide Animator; use one of KAU_*") - } - } - alpha(0f) - } - - override fun animationCleanup(holder: RecyclerView.ViewHolder): View.() -> Unit = { - translationY = 0f - translationX = 0f - alpha = 1f - } - - override fun getDelay(remove: Long, move: Long, change: Long): Long = 0L -} -- cgit v1.2.3