content: package androidx.recyclerview.widget;
  
  import android.animation.Animator;
  import android.animation.AnimatorListenerAdapter;
  import android.animation.TimeInterpolator;
  import android.animation.ValueAnimator;
  import android.view.View;
  import android.view.ViewPropertyAnimator;
  import androidx.core.view.ViewCompat;
  import androidx.recyclerview.widget.RecyclerView;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  public class DefaultItemAnimator extends SimpleItemAnimator {
      private static final boolean DEBUG = false;
      private static TimeInterpolator sDefaultInterpolator;
      ArrayList<RecyclerView.ViewHolder> mAddAnimations = new ArrayList<>();
      ArrayList<ArrayList<RecyclerView.ViewHolder>> mAdditionsList = new ArrayList<>();
      ArrayList<RecyclerView.ViewHolder> mChangeAnimations = new ArrayList<>();
      ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>();
      ArrayList<RecyclerView.ViewHolder> mMoveAnimations = new ArrayList<>();
      ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>();
      private ArrayList<RecyclerView.ViewHolder> mPendingAdditions = new ArrayList<>();
      private ArrayList<ChangeInfo> mPendingChanges = new ArrayList<>();
      private ArrayList<MoveInfo> mPendingMoves = new ArrayList<>();
      private ArrayList<RecyclerView.ViewHolder> mPendingRemovals = new ArrayList<>();
      ArrayList<RecyclerView.ViewHolder> mRemoveAnimations = new ArrayList<>();
  
      private static class ChangeInfo {
          public int fromX;
          public int fromY;
          public RecyclerView.ViewHolder newHolder;
          public RecyclerView.ViewHolder oldHolder;
          public int toX;
          public int toY;
  
          private ChangeInfo(RecyclerView.ViewHolder oldHolder2, RecyclerView.ViewHolder newHolder2) {
              this.oldHolder = oldHolder2;
              this.newHolder = newHolder2;
          }
  
          ChangeInfo(RecyclerView.ViewHolder oldHolder2, RecyclerView.ViewHolder newHolder2, int fromX2, int fromY2, int toX2, int toY2) {
              this(oldHolder2, newHolder2);
              this.fromX = fromX2;
              this.fromY = fromY2;
              this.toX = toX2;
              this.toY = toY2;
          }
  
          public String toString() {
              return "ChangeInfo{oldHolder=" + this.oldHolder + ", newHolder=" + this.newHolder + ", fromX=" + this.fromX + ", fromY=" + this.fromY + ", toX=" + this.toX + ", toY=" + this.toY + '}';
          }
      }
  
      private static class MoveInfo {
          public int fromX;
          public int fromY;
          public RecyclerView.ViewHolder holder;
          public int toX;
          public int toY;
  
          MoveInfo(RecyclerView.ViewHolder holder2, int fromX2, int fromY2, int toX2, int toY2) {
              this.holder = holder2;
              this.fromX = fromX2;
              this.fromY = fromY2;
              this.toX = toX2;
              this.toY = toY2;
          }
      }
  
      private void animateRemoveImpl(final RecyclerView.ViewHolder holder) {
          final View view = holder.itemView;
          final ViewPropertyAnimator animate = view.animate();
          this.mRemoveAnimations.add(holder);
          animate.setDuration(getRemoveDuration()).alpha(0.0f).setListener(new AnimatorListenerAdapter() {
              public void onAnimationEnd(Animator animator) {
                  animate.setListener((Animator.AnimatorListener) null);
                  view.setAlpha(1.0f);
                  DefaultItemAnimator.this.dispatchRemoveFinished(holder);
                  DefaultItemAnimator.this.mRemoveAnimations.remove(holder);
                  DefaultItemAnimator.this.dispatchFinishedWhenDone();
              }
  
              public void onAnimationStart(Animator animator) {
                  DefaultItemAnimator.this.dispatchRemoveStarting(holder);
              }
          }).start();
      }
  
      private void endChangeAnimation(List<ChangeInfo> list, RecyclerView.ViewHolder item) {
          for (int size = list.size() - 1; size >= 0; size--) {
              ChangeInfo changeInfo = list.get(size);
              if (endChangeAnimationIfNecessary(changeInfo, item) && changeInfo.oldHolder == null && changeInfo.newHolder == null) {
                  list.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, RecyclerView.ViewHolder item) {
          boolean z = false;
          if (changeInfo.newHolder == item) {
              changeInfo.newHolder = null;
          } else if (changeInfo.oldHolder != item) {
              return false;
          } else {
              changeInfo.oldHolder = null;
              z = true;
          }
          item.itemView.setAlpha(1.0f);
          item.itemView.setTranslationX(0.0f);
          item.itemView.setTranslationY(0.0f);
          dispatchChangeFinished(item, z);
          return true;
      }
  
      private void resetAnimation(RecyclerView.ViewHolder holder) {
          if (sDefaultInterpolator == null) {
              sDefaultInterpolator = new ValueAnimator().getInterpolator();
          }
          holder.itemView.animate().setInterpolator(sDefaultInterpolator);
          endAnimation(holder);
      }
  
      public boolean animateAdd(RecyclerView.ViewHolder holder) {
          resetAnimation(holder);
          holder.itemView.setAlpha(0.0f);
          this.mPendingAdditions.add(holder);
          return true;
      }
  
      /* access modifiers changed from: package-private */
      public void animateAddImpl(final RecyclerView.ViewHolder holder) {
          final View view = holder.itemView;
          final ViewPropertyAnimator animate = view.animate();
          this.mAddAnimations.add(holder);
          animate.alpha(1.0f).setDuration(getAddDuration()).setListener(new AnimatorListenerAdapter() {
              public void onAnimationCancel(Animator animator) {
                  view.setAlpha(1.0f);
              }
  
              public void onAnimationEnd(Animator animator) {
                  animate.setListener((Animator.AnimatorListener) null);
                  DefaultItemAnimator.this.dispatchAddFinished(holder);
                  DefaultItemAnimator.this.mAddAnimations.remove(holder);
                  DefaultItemAnimator.this.dispatchFinishedWhenDone();
              }
  
              public void onAnimationStart(Animator animator) {
                  DefaultItemAnimator.this.dispatchAddStarting(holder);
              }
          }).start();
      }
  
      public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
          RecyclerView.ViewHolder viewHolder = oldHolder;
          RecyclerView.ViewHolder viewHolder2 = newHolder;
          if (viewHolder == viewHolder2) {
              return animateMove(oldHolder, fromX, fromY, toX, toY);
          }
          float translationX = viewHolder.itemView.getTranslationX();
          float translationY = viewHolder.itemView.getTranslationY();
          float alpha = viewHolder.itemView.getAlpha();
          resetAnimation(oldHolder);
          int i = (int) (((float) (toX - fromX)) - translationX);
          int i2 = (int) (((float) (toY - fromY)) - translationY);
          viewHolder.itemView.setTranslationX(translationX);
          viewHolder.itemView.setTranslationY(translationY);
          viewHolder.itemView.setAlpha(alpha);
          if (viewHolder2 != null) {
              resetAnimation(viewHolder2);
              viewHolder2.itemView.setTranslationX((float) (-i));
              viewHolder2.itemView.setTranslationY((float) (-i2));
              viewHolder2.itemView.setAlpha(0.0f);
          }
          ArrayList<ChangeInfo> arrayList = this.mPendingChanges;
          float f = translationX;
          ChangeInfo changeInfo = r7;
          ChangeInfo changeInfo2 = new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY);
          arrayList.add(changeInfo);
          return true;
      }
  
      /* access modifiers changed from: package-private */
      public void animateChangeImpl(final ChangeInfo changeInfo) {
          RecyclerView.ViewHolder viewHolder = changeInfo.oldHolder;
          final View view = null;
          final View view2 = viewHolder == null ? null : viewHolder.itemView;
          RecyclerView.ViewHolder viewHolder2 = changeInfo.newHolder;
          if (viewHolder2 != null) {
              view = viewHolder2.itemView;
          }
          if (view2 != null) {
              final ViewPropertyAnimator duration = view2.animate().setDuration(getChangeDuration());
              this.mChangeAnimations.add(changeInfo.oldHolder);
              duration.translationX((float) (changeInfo.toX - changeInfo.fromX));
              duration.translationY((float) (changeInfo.toY - changeInfo.fromY));
              duration.alpha(0.0f).setListener(new AnimatorListenerAdapter() {
                  public void onAnimationEnd(Animator animator) {
                      duration.setListener((Animator.AnimatorListener) null);
                      view2.setAlpha(1.0f);
                      view2.setTranslationX(0.0f);
                      view2.setTranslationY(0.0f);
                      DefaultItemAnimator.this.dispatchChangeFinished(changeInfo.oldHolder, true);
                      DefaultItemAnimator.this.mChangeAnimations.remove(changeInfo.oldHolder);
                      DefaultItemAnimator.this.dispatchFinishedWhenDone();
                  }
  
                  public void onAnimationStart(Animator animator) {
                      DefaultItemAnimator.this.dispatchChangeStarting(changeInfo.oldHolder, true);
                  }
              }).start();
          }
          if (view != null) {
              final ViewPropertyAnimator animate = view.animate();
              this.mChangeAnimations.add(changeInfo.newHolder);
              animate.translationX(0.0f).translationY(0.0f).setDuration(getChangeDuration()).alpha(1.0f).setListener(new AnimatorListenerAdapter() {
                  public void onAnimationEnd(Animator animator) {
                      animate.setListener((Animator.AnimatorListener) null);
                      view.setAlpha(1.0f);
                      view.setTranslationX(0.0f);
                      view.setTranslationY(0.0f);
                      DefaultItemAnimator.this.dispatchChangeFinished(changeInfo.newHolder, false);
                      DefaultItemAnimator.this.mChangeAnimations.remove(changeInfo.newHolder);
                      DefaultItemAnimator.this.dispatchFinishedWhenDone();
                  }
  
                  public void onAnimationStart(Animator animator) {
                      DefaultItemAnimator.this.dispatchChangeStarting(changeInfo.newHolder, false);
                  }
              }).start();
          }
      }
  
      public boolean animateMove(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
          RecyclerView.ViewHolder viewHolder = holder;
          View view = viewHolder.itemView;
          int translationX = fromX + ((int) viewHolder.itemView.getTranslationX());
          int translationY = fromY + ((int) viewHolder.itemView.getTranslationY());
          resetAnimation(holder);
          int i = toX - translationX;
          int i2 = toY - translationY;
          if (i == 0 && i2 == 0) {
              dispatchMoveFinished(holder);
              return false;
          }
          if (i != 0) {
              view.setTranslationX((float) (-i));
          }
          if (i2 != 0) {
              view.setTranslationY((float) (-i2));
          }
          this.mPendingMoves.add(new MoveInfo(holder, translationX, translationY, toX, toY));
          return true;
      }
  
      /* access modifiers changed from: package-private */
      public void animateMoveImpl(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
          RecyclerView.ViewHolder viewHolder = holder;
          View view = viewHolder.itemView;
          int i = toX - fromX;
          int i2 = toY - fromY;
          if (i != 0) {
              view.animate().translationX(0.0f);
          }
          if (i2 != 0) {
              view.animate().translationY(0.0f);
          }
          ViewPropertyAnimator animate = view.animate();
          this.mMoveAnimations.add(viewHolder);
          final RecyclerView.ViewHolder viewHolder2 = holder;
          final int i3 = i;
          final View view2 = view;
          final int i4 = i2;
          final ViewPropertyAnimator viewPropertyAnimator = animate;
          animate.setDuration(getMoveDuration()).setListener(new AnimatorListenerAdapter() {
              public void onAnimationCancel(Animator animator) {
                  if (i3 != 0) {
                      view2.setTranslationX(0.0f);
                  }
                  if (i4 != 0) {
                      view2.setTranslationY(0.0f);
                  }
              }
  
              public void onAnimationEnd(Animator animator) {
                  viewPropertyAnimator.setListener((Animator.AnimatorListener) null);
                  DefaultItemAnimator.this.dispatchMoveFinished(viewHolder2);
                  DefaultItemAnimator.this.mMoveAnimations.remove(viewHolder2);
                  DefaultItemAnimator.this.dispatchFinishedWhenDone();
              }
  
              public void onAnimationStart(Animator animator) {
                  DefaultItemAnimator.this.dispatchMoveStarting(viewHolder2);
              }
          }).start();
      }
  
      public boolean animateRemove(RecyclerView.ViewHolder holder) {
          resetAnimation(holder);
          this.mPendingRemovals.add(holder);
          return true;
      }
  
      public boolean canReuseUpdatedViewHolder(RecyclerView.ViewHolder viewHolder, List<Object> list) {
          return !list.isEmpty() || super.canReuseUpdatedViewHolder(viewHolder, list);
      }
  
      /* access modifiers changed from: package-private */
      public void cancelAll(List<RecyclerView.ViewHolder> list) {
          for (int size = list.size() - 1; size >= 0; size--) {
              list.get(size).itemView.animate().cancel();
          }
      }
  
      /* access modifiers changed from: package-private */
      public void dispatchFinishedWhenDone() {
          if (!isRunning()) {
              dispatchAnimationsFinished();
          }
      }
  
      public void endAnimation(RecyclerView.ViewHolder item) {
          View view = item.itemView;
          view.animate().cancel();
          int size = this.mPendingMoves.size();
          while (true) {
              size--;
              if (size < 0) {
                  break;
              } else if (this.mPendingMoves.get(size).holder == item) {
                  view.setTranslationY(0.0f);
                  view.setTranslationX(0.0f);
                  dispatchMoveFinished(item);
                  this.mPendingMoves.remove(size);
              }
          }
          endChangeAnimation(this.mPendingChanges, item);
          if (this.mPendingRemovals.remove(item)) {
              view.setAlpha(1.0f);
              dispatchRemoveFinished(item);
          }
          if (this.mPendingAdditions.remove(item)) {
              view.setAlpha(1.0f);
              dispatchAddFinished(item);
          }
          for (int size2 = this.mChangesList.size() - 1; size2 >= 0; size2--) {
              ArrayList arrayList = this.mChangesList.get(size2);
              endChangeAnimation(arrayList, item);
              if (arrayList.isEmpty()) {
                  this.mChangesList.remove(size2);
              }
          }
          for (int size3 = this.mMovesList.size() - 1; size3 >= 0; size3--) {
              ArrayList arrayList2 = this.mMovesList.get(size3);
              int size4 = arrayList2.size() - 1;
              while (true) {
                  if (size4 < 0) {
                      break;
                  } else if (((MoveInfo) arrayList2.get(size4)).holder == item) {
                      view.setTranslationY(0.0f);
                      view.setTranslationX(0.0f);
                      dispatchMoveFinished(item);
                      arrayList2.remove(size4);
                      if (arrayList2.isEmpty()) {
                          this.mMovesList.remove(size3);
                      }
                  } else {
                      size4--;
                  }
              }
          }
          for (int size5 = this.mAdditionsList.size() - 1; size5 >= 0; size5--) {
              ArrayList arrayList3 = this.mAdditionsList.get(size5);
              if (arrayList3.remove(item)) {
                  view.setAlpha(1.0f);
                  dispatchAddFinished(item);
                  if (arrayList3.isEmpty()) {
                      this.mAdditionsList.remove(size5);
                  }
              }
          }
          this.mRemoveAnimations.remove(item);
          this.mAddAnimations.remove(item);
          this.mChangeAnimations.remove(item);
          this.mMoveAnimations.remove(item);
          dispatchFinishedWhenDone();
      }
  
      public void endAnimations() {
          for (int size = this.mPendingMoves.size() - 1; size >= 0; size--) {
              MoveInfo moveInfo = this.mPendingMoves.get(size);
              View view = moveInfo.holder.itemView;
              view.setTranslationY(0.0f);
              view.setTranslationX(0.0f);
              dispatchMoveFinished(moveInfo.holder);
              this.mPendingMoves.remove(size);
          }
          for (int size2 = this.mPendingRemovals.size() - 1; size2 >= 0; size2--) {
              dispatchRemoveFinished(this.mPendingRemovals.get(size2));
              this.mPendingRemovals.remove(size2);
          }
          for (int size3 = this.mPendingAdditions.size() - 1; size3 >= 0; size3--) {
              RecyclerView.ViewHolder viewHolder = this.mPendingAdditions.get(size3);
              viewHolder.itemView.setAlpha(1.0f);
              dispatchAddFinished(viewHolder);
              this.mPendingAdditions.remove(size3);
          }
          for (int size4 = this.mPendingChanges.size() - 1; size4 >= 0; size4--) {
              endChangeAnimationIfNecessary(this.mPendingChanges.get(size4));
          }
          this.mPendingChanges.clear();
          if (isRunning()) {
              for (int size5 = this.mMovesList.size() - 1; size5 >= 0; size5--) {
                  ArrayList arrayList = this.mMovesList.get(size5);
                  for (int size6 = arrayList.size() - 1; size6 >= 0; size6--) {
                      MoveInfo moveInfo2 = (MoveInfo) arrayList.get(size6);
                      View view2 = moveInfo2.holder.itemView;
                      view2.setTranslationY(0.0f);
                      view2.setTranslationX(0.0f);
                      dispatchMoveFinished(moveInfo2.holder);
                      arrayList.remove(size6);
                      if (arrayList.isEmpty()) {
                          this.mMovesList.remove(arrayList);
                      }
                  }
              }
              for (int size7 = this.mAdditionsList.size() - 1; size7 >= 0; size7--) {
                  ArrayList arrayList2 = this.mAdditionsList.get(size7);
                  for (int size8 = arrayList2.size() - 1; size8 >= 0; size8--) {
                      RecyclerView.ViewHolder viewHolder2 = (RecyclerView.ViewHolder) arrayList2.get(size8);
                      viewHolder2.itemView.setAlpha(1.0f);
                      dispatchAddFinished(viewHolder2);
                      arrayList2.remove(size8);
                      if (arrayList2.isEmpty()) {
                          this.mAdditionsList.remove(arrayList2);
                      }
                  }
              }
              for (int size9 = this.mChangesList.size() - 1; size9 >= 0; size9--) {
                  ArrayList arrayList3 = this.mChangesList.get(size9);
                  for (int size10 = arrayList3.size() - 1; size10 >= 0; size10--) {
                      endChangeAnimationIfNecessary((ChangeInfo) arrayList3.get(size10));
                      if (arrayList3.isEmpty()) {
                          this.mChangesList.remove(arrayList3);
                      }
                  }
              }
              cancelAll(this.mRemoveAnimations);
              cancelAll(this.mMoveAnimations);
              cancelAll(this.mAddAnimations);
              cancelAll(this.mChangeAnimations);
              dispatchAnimationsFinished();
          }
      }
  
      public boolean isRunning() {
          return !this.mPendingAdditions.isEmpty() || !this.mPendingChanges.isEmpty() || !this.mPendingMoves.isEmpty() || !this.mPendingRemovals.isEmpty() || !this.mMoveAnimations.isEmpty() || !this.mRemoveAnimations.isEmpty() || !this.mAddAnimations.isEmpty() || !this.mChangeAnimations.isEmpty() || !this.mMovesList.isEmpty() || !this.mAdditionsList.isEmpty() || !this.mChangesList.isEmpty();
      }
  
      public void runPendingAnimations() {
          boolean z = !this.mPendingRemovals.isEmpty();
          boolean z2 = !this.mPendingMoves.isEmpty();
          boolean z3 = !this.mPendingChanges.isEmpty();
          boolean z4 = !this.mPendingAdditions.isEmpty();
          if (z || z2 || z4 || z3) {
              Iterator<RecyclerView.ViewHolder> it = this.mPendingRemovals.iterator();
              while (it.hasNext()) {
                  animateRemoveImpl(it.next());
              }
              this.mPendingRemovals.clear();
              if (z2) {
                  final ArrayList arrayList = new ArrayList();
                  arrayList.addAll(this.mPendingMoves);
                  this.mMovesList.add(arrayList);
                  this.mPendingMoves.clear();
                  AnonymousClass1 r6 = new Runnable() {
                      public void run() {
                          Iterator it = arrayList.iterator();
                          while (it.hasNext()) {
                              MoveInfo moveInfo = (MoveInfo) it.next();
                              DefaultItemAnimator.this.animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY);
                          }
                          arrayList.clear();
                          DefaultItemAnimator.this.mMovesList.remove(arrayList);
                      }
                  };
                  if (z) {
                      ViewCompat.postOnAnimationDelayed(((MoveInfo) arrayList.get(0)).holder.itemView, r6, getRemoveDuration());
                  } else {
                      r6.run();
                  }
              }
              if (z3) {
                  final ArrayList arrayList2 = new ArrayList();
                  arrayList2.addAll(this.mPendingChanges);
                  this.mChangesList.add(arrayList2);
                  this.mPendingChanges.clear();
                  AnonymousClass2 r62 = new Runnable() {
                      public void run() {
                          Iterator it = arrayList2.iterator();
                          while (it.hasNext()) {
                              DefaultItemAnimator.this.animateChangeImpl((ChangeInfo) it.next());
                          }
                          arrayList2.clear();
                          DefaultItemAnimator.this.mChangesList.remove(arrayList2);
                      }
                  };
                  if (z) {
                      ViewCompat.postOnAnimationDelayed(((ChangeInfo) arrayList2.get(0)).oldHolder.itemView, r62, getRemoveDuration());
                  } else {
                      r62.run();
                  }
              }
              if (z4) {
                  final ArrayList arrayList3 = new ArrayList();
                  arrayList3.addAll(this.mPendingAdditions);
                  this.mAdditionsList.add(arrayList3);
                  this.mPendingAdditions.clear();
                  AnonymousClass3 r63 = new Runnable() {
                      public void run() {
                          Iterator it = arrayList3.iterator();
                          while (it.hasNext()) {
                              DefaultItemAnimator.this.animateAddImpl((RecyclerView.ViewHolder) it.next());
                          }
                          arrayList3.clear();
                          DefaultItemAnimator.this.mAdditionsList.remove(arrayList3);
                      }
                  };
                  if (z || z2 || z3) {
                      long j = 0;
                      long removeDuration = z ? getRemoveDuration() : 0;
                      long moveDuration = z2 ? getMoveDuration() : 0;
                      if (z3) {
                          j = getChangeDuration();
                      }
                      ViewCompat.postOnAnimationDelayed(((RecyclerView.ViewHolder) arrayList3.get(0)).itemView, r63, Math.max(moveDuration, j) + removeDuration);
                      return;
                  }
                  r63.run();
              }
          }
      }
  }
  