content: package androidx.fragment.app;
  
  import android.util.Log;
  import android.view.View;
  import android.view.ViewGroup;
  import androidx.core.os.CancellationSignal;
  import androidx.core.view.ViewCompat;
  import androidx.fragment.R;
  import java.util.ArrayList;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import mt.Log1F380D;
  import okhttp3.HttpUrl;
  
  abstract class SpecialEffectsController {
      private final ViewGroup mContainer;
      boolean mIsContainerPostponed = false;
      boolean mOperationDirectionIsPop = false;
      final ArrayList<Operation> mPendingOperations = new ArrayList<>();
      final ArrayList<Operation> mRunningOperations = new ArrayList<>();
  
      /* renamed from: androidx.fragment.app.SpecialEffectsController$3  reason: invalid class name */
      static /* synthetic */ class AnonymousClass3 {
          static final /* synthetic */ int[] $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$LifecycleImpact;
          static final /* synthetic */ int[] $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$State;
  
          static {
              int[] iArr = new int[Operation.LifecycleImpact.values().length];
              $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$LifecycleImpact = iArr;
              try {
                  iArr[Operation.LifecycleImpact.ADDING.ordinal()] = 1;
              } catch (NoSuchFieldError e) {
              }
              try {
                  $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$LifecycleImpact[Operation.LifecycleImpact.REMOVING.ordinal()] = 2;
              } catch (NoSuchFieldError e2) {
              }
              try {
                  $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$LifecycleImpact[Operation.LifecycleImpact.NONE.ordinal()] = 3;
              } catch (NoSuchFieldError e3) {
              }
              int[] iArr2 = new int[Operation.State.values().length];
              $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$State = iArr2;
              try {
                  iArr2[Operation.State.REMOVED.ordinal()] = 1;
              } catch (NoSuchFieldError e4) {
              }
              try {
                  $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$State[Operation.State.VISIBLE.ordinal()] = 2;
              } catch (NoSuchFieldError e5) {
              }
              try {
                  $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$State[Operation.State.GONE.ordinal()] = 3;
              } catch (NoSuchFieldError e6) {
              }
              try {
                  $SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$State[Operation.State.INVISIBLE.ordinal()] = 4;
              } catch (NoSuchFieldError e7) {
              }
          }
      }
  
      private static class FragmentStateManagerOperation extends Operation {
          private final FragmentStateManager mFragmentStateManager;
  
          FragmentStateManagerOperation(Operation.State finalState, Operation.LifecycleImpact lifecycleImpact, FragmentStateManager fragmentStateManager, CancellationSignal cancellationSignal) {
              super(finalState, lifecycleImpact, fragmentStateManager.getFragment(), cancellationSignal);
              this.mFragmentStateManager = fragmentStateManager;
          }
  
          public void complete() {
              super.complete();
              this.mFragmentStateManager.moveToExpectedState();
          }
  
          /* access modifiers changed from: package-private */
          public void onStart() {
              if (getLifecycleImpact() == Operation.LifecycleImpact.ADDING) {
                  Fragment fragment = this.mFragmentStateManager.getFragment();
                  View findFocus = fragment.mView.findFocus();
                  if (findFocus != null) {
                      fragment.setFocusedView(findFocus);
                      if (FragmentManager.isLoggingEnabled(2)) {
                          Log.v("FragmentManager", "requestFocus: Saved focused view " + findFocus + " for Fragment " + fragment);
                      }
                  }
                  View requireView = getFragment().requireView();
                  if (requireView.getParent() == null) {
                      this.mFragmentStateManager.addViewToContainer();
                      requireView.setAlpha(0.0f);
                  }
                  if (requireView.getAlpha() == 0.0f && requireView.getVisibility() == 0) {
                      requireView.setVisibility(4);
                  }
                  requireView.setAlpha(fragment.getPostOnViewCreatedAlpha());
              }
          }
      }
  
      /* compiled from: 0082 */
      static class Operation {
          private final List<Runnable> mCompletionListeners = new ArrayList();
          private State mFinalState;
          private final Fragment mFragment;
          private boolean mIsCanceled = false;
          private boolean mIsComplete = false;
          private LifecycleImpact mLifecycleImpact;
          private final HashSet<CancellationSignal> mSpecialEffectsSignals = new HashSet<>();
  
          enum LifecycleImpact {
              NONE,
              ADDING,
              REMOVING
          }
  
          enum State {
              REMOVED,
              VISIBLE,
              GONE,
              INVISIBLE;
  
              static State from(int visibility) {
                  switch (visibility) {
                      case 0:
                          return VISIBLE;
                      case 4:
                          return INVISIBLE;
                      case 8:
                          return GONE;
                      default:
                          throw new IllegalArgumentException("Unknown visibility " + visibility);
                  }
              }
  
              static State from(View view) {
                  return (view.getAlpha() == 0.0f && view.getVisibility() == 0) ? INVISIBLE : from(view.getVisibility());
              }
  
              /* access modifiers changed from: package-private */
              public void applyState(View view) {
                  switch (AnonymousClass3.$SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$State[ordinal()]) {
                      case 1:
                          ViewGroup viewGroup = (ViewGroup) view.getParent();
                          if (viewGroup != null) {
                              if (FragmentManager.isLoggingEnabled(2)) {
                                  Log.v("FragmentManager", "SpecialEffectsController: Removing view " + view + " from container " + viewGroup);
                              }
                              viewGroup.removeView(view);
                              return;
                          }
                          return;
                      case 2:
                          if (FragmentManager.isLoggingEnabled(2)) {
                              Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to VISIBLE");
                          }
                          view.setVisibility(0);
                          return;
                      case 3:
                          if (FragmentManager.isLoggingEnabled(2)) {
                              Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to GONE");
                          }
                          view.setVisibility(8);
                          return;
                      case 4:
                          if (FragmentManager.isLoggingEnabled(2)) {
                              Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to INVISIBLE");
                          }
                          view.setVisibility(4);
                          return;
                      default:
                          return;
                  }
              }
          }
  
          Operation(State finalState, LifecycleImpact lifecycleImpact, Fragment fragment, CancellationSignal cancellationSignal) {
              this.mFinalState = finalState;
              this.mLifecycleImpact = lifecycleImpact;
              this.mFragment = fragment;
              cancellationSignal.setOnCancelListener(new CancellationSignal.OnCancelListener() {
                  public void onCancel() {
                      Operation.this.cancel();
                  }
              });
          }
  
          /* access modifiers changed from: package-private */
          public final void addCompletionListener(Runnable listener) {
              this.mCompletionListeners.add(listener);
          }
  
          /* access modifiers changed from: package-private */
          public final void cancel() {
              if (!isCanceled()) {
                  this.mIsCanceled = true;
                  if (this.mSpecialEffectsSignals.isEmpty()) {
                      complete();
                      return;
                  }
                  Iterator it = new ArrayList(this.mSpecialEffectsSignals).iterator();
                  while (it.hasNext()) {
                      ((CancellationSignal) it.next()).cancel();
                  }
              }
          }
  
          public void complete() {
              if (!this.mIsComplete) {
                  if (FragmentManager.isLoggingEnabled(2)) {
                      Log.v("FragmentManager", "SpecialEffectsController: " + this + " has called complete.");
                  }
                  this.mIsComplete = true;
                  for (Runnable run : this.mCompletionListeners) {
                      run.run();
                  }
              }
          }
  
          public final void completeSpecialEffect(CancellationSignal signal) {
              if (this.mSpecialEffectsSignals.remove(signal) && this.mSpecialEffectsSignals.isEmpty()) {
                  complete();
              }
          }
  
          public State getFinalState() {
              return this.mFinalState;
          }
  
          public final Fragment getFragment() {
              return this.mFragment;
          }
  
          /* access modifiers changed from: package-private */
          public LifecycleImpact getLifecycleImpact() {
              return this.mLifecycleImpact;
          }
  
          /* access modifiers changed from: package-private */
          public final boolean isCanceled() {
              return this.mIsCanceled;
          }
  
          /* access modifiers changed from: package-private */
          public final boolean isComplete() {
              return this.mIsComplete;
          }
  
          public final void markStartedSpecialEffect(CancellationSignal signal) {
              onStart();
              this.mSpecialEffectsSignals.add(signal);
          }
  
          /* access modifiers changed from: package-private */
          public final void mergeWith(State finalState, LifecycleImpact lifecycleImpact) {
              switch (AnonymousClass3.$SwitchMap$androidx$fragment$app$SpecialEffectsController$Operation$LifecycleImpact[lifecycleImpact.ordinal()]) {
                  case 1:
                      if (this.mFinalState == State.REMOVED) {
                          if (FragmentManager.isLoggingEnabled(2)) {
                              Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.mFragment + " mFinalState = REMOVED -> VISIBLE. mLifecycleImpact = " + this.mLifecycleImpact + " to ADDING.");
                          }
                          this.mFinalState = State.VISIBLE;
                          this.mLifecycleImpact = LifecycleImpact.ADDING;
                          return;
                      }
                      return;
                  case 2:
                      if (FragmentManager.isLoggingEnabled(2)) {
                          Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.mFragment + " mFinalState = " + this.mFinalState + " -> REMOVED. mLifecycleImpact  = " + this.mLifecycleImpact + " to REMOVING.");
                      }
                      this.mFinalState = State.REMOVED;
                      this.mLifecycleImpact = LifecycleImpact.REMOVING;
                      return;
                  case 3:
                      if (this.mFinalState != State.REMOVED) {
                          if (FragmentManager.isLoggingEnabled(2)) {
                              Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.mFragment + " mFinalState = " + this.mFinalState + " -> " + finalState + ". ");
                          }
                          this.mFinalState = finalState;
                          return;
                      }
                      return;
                  default:
                      return;
              }
          }
  
          /* access modifiers changed from: package-private */
          public void onStart() {
          }
  
          public String toString() {
              StringBuilder sb = new StringBuilder();
              sb.append("Operation ");
              sb.append("{");
              String hexString = Integer.toHexString(System.identityHashCode(this));
              Log1F380D.a((Object) hexString);
              sb.append(hexString);
              sb.append("} ");
              sb.append("{");
              sb.append("mFinalState = ");
              sb.append(this.mFinalState);
              sb.append("} ");
              sb.append("{");
              sb.append("mLifecycleImpact = ");
              sb.append(this.mLifecycleImpact);
              sb.append("} ");
              sb.append("{");
              sb.append("mFragment = ");
              sb.append(this.mFragment);
              sb.append("}");
              return sb.toString();
          }
      }
  
      SpecialEffectsController(ViewGroup container) {
          this.mContainer = container;
      }
  
      private void enqueue(Operation.State finalState, Operation.LifecycleImpact lifecycleImpact, FragmentStateManager fragmentStateManager) {
          synchronized (this.mPendingOperations) {
              CancellationSignal cancellationSignal = new CancellationSignal();
              Operation findPendingOperation = findPendingOperation(fragmentStateManager.getFragment());
              if (findPendingOperation != null) {
                  findPendingOperation.mergeWith(finalState, lifecycleImpact);
                  return;
              }
              final FragmentStateManagerOperation fragmentStateManagerOperation = new FragmentStateManagerOperation(finalState, lifecycleImpact, fragmentStateManager, cancellationSignal);
              this.mPendingOperations.add(fragmentStateManagerOperation);
              fragmentStateManagerOperation.addCompletionListener(new Runnable() {
                  public void run() {
                      if (SpecialEffectsController.this.mPendingOperations.contains(fragmentStateManagerOperation)) {
                          fragmentStateManagerOperation.getFinalState().applyState(fragmentStateManagerOperation.getFragment().mView);
                      }
                  }
              });
              fragmentStateManagerOperation.addCompletionListener(new Runnable() {
                  public void run() {
                      SpecialEffectsController.this.mPendingOperations.remove(fragmentStateManagerOperation);
                      SpecialEffectsController.this.mRunningOperations.remove(fragmentStateManagerOperation);
                  }
              });
          }
      }
  
      private Operation findPendingOperation(Fragment fragment) {
          Iterator<Operation> it = this.mPendingOperations.iterator();
          while (it.hasNext()) {
              Operation next = it.next();
              if (next.getFragment().equals(fragment) && !next.isCanceled()) {
                  return next;
              }
          }
          return null;
      }
  
      private Operation findRunningOperation(Fragment fragment) {
          Iterator<Operation> it = this.mRunningOperations.iterator();
          while (it.hasNext()) {
              Operation next = it.next();
              if (next.getFragment().equals(fragment) && !next.isCanceled()) {
                  return next;
              }
          }
          return null;
      }
  
      static SpecialEffectsController getOrCreateController(ViewGroup container, FragmentManager fragmentManager) {
          return getOrCreateController(container, fragmentManager.getSpecialEffectsControllerFactory());
      }
  
      static SpecialEffectsController getOrCreateController(ViewGroup container, SpecialEffectsControllerFactory factory) {
          Object tag = container.getTag(R.id.special_effects_controller_view_tag);
          if (tag instanceof SpecialEffectsController) {
              return (SpecialEffectsController) tag;
          }
          SpecialEffectsController createController = factory.createController(container);
          container.setTag(R.id.special_effects_controller_view_tag, createController);
          return createController;
      }
  
      private void updateFinalState() {
          Iterator<Operation> it = this.mPendingOperations.iterator();
          while (it.hasNext()) {
              Operation next = it.next();
              if (next.getLifecycleImpact() == Operation.LifecycleImpact.ADDING) {
                  next.mergeWith(Operation.State.from(next.getFragment().requireView().getVisibility()), Operation.LifecycleImpact.NONE);
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public void enqueueAdd(Operation.State finalState, FragmentStateManager fragmentStateManager) {
          if (FragmentManager.isLoggingEnabled(2)) {
              Log.v("FragmentManager", "SpecialEffectsController: Enqueuing add operation for fragment " + fragmentStateManager.getFragment());
          }
          enqueue(finalState, Operation.LifecycleImpact.ADDING, fragmentStateManager);
      }
  
      /* access modifiers changed from: package-private */
      public void enqueueHide(FragmentStateManager fragmentStateManager) {
          if (FragmentManager.isLoggingEnabled(2)) {
              Log.v("FragmentManager", "SpecialEffectsController: Enqueuing hide operation for fragment " + fragmentStateManager.getFragment());
          }
          enqueue(Operation.State.GONE, Operation.LifecycleImpact.NONE, fragmentStateManager);
      }
  
      /* access modifiers changed from: package-private */
      public void enqueueRemove(FragmentStateManager fragmentStateManager) {
          if (FragmentManager.isLoggingEnabled(2)) {
              Log.v("FragmentManager", "SpecialEffectsController: Enqueuing remove operation for fragment " + fragmentStateManager.getFragment());
          }
          enqueue(Operation.State.REMOVED, Operation.LifecycleImpact.REMOVING, fragmentStateManager);
      }
  
      /* access modifiers changed from: package-private */
      public void enqueueShow(FragmentStateManager fragmentStateManager) {
          if (FragmentManager.isLoggingEnabled(2)) {
              Log.v("FragmentManager", "SpecialEffectsController: Enqueuing show operation for fragment " + fragmentStateManager.getFragment());
          }
          enqueue(Operation.State.VISIBLE, Operation.LifecycleImpact.NONE, fragmentStateManager);
      }
  
      /* access modifiers changed from: package-private */
      public abstract void executeOperations(List<Operation> list, boolean z);
  
      /* access modifiers changed from: package-private */
      public void executePendingOperations() {
          if (!this.mIsContainerPostponed) {
              if (!ViewCompat.isAttachedToWindow(this.mContainer)) {
                  forceCompleteAllOperations();
                  this.mOperationDirectionIsPop = false;
                  return;
              }
              synchronized (this.mPendingOperations) {
                  if (!this.mPendingOperations.isEmpty()) {
                      ArrayList arrayList = new ArrayList(this.mRunningOperations);
                      this.mRunningOperations.clear();
                      Iterator it = arrayList.iterator();
                      while (it.hasNext()) {
                          Operation operation = (Operation) it.next();
                          if (FragmentManager.isLoggingEnabled(2)) {
                              Log.v("FragmentManager", "SpecialEffectsController: Cancelling operation " + operation);
                          }
                          operation.cancel();
                          if (!operation.isComplete()) {
                              this.mRunningOperations.add(operation);
                          }
                      }
                      updateFinalState();
                      ArrayList arrayList2 = new ArrayList(this.mPendingOperations);
                      this.mPendingOperations.clear();
                      this.mRunningOperations.addAll(arrayList2);
                      Iterator it2 = arrayList2.iterator();
                      while (it2.hasNext()) {
                          ((Operation) it2.next()).onStart();
                      }
                      executeOperations(arrayList2, this.mOperationDirectionIsPop);
                      this.mOperationDirectionIsPop = false;
                  }
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public void forceCompleteAllOperations() {
          boolean isAttachedToWindow = ViewCompat.isAttachedToWindow(this.mContainer);
          synchronized (this.mPendingOperations) {
              updateFinalState();
              Iterator<Operation> it = this.mPendingOperations.iterator();
              while (it.hasNext()) {
                  it.next().onStart();
              }
              Iterator it2 = new ArrayList(this.mRunningOperations).iterator();
              while (it2.hasNext()) {
                  Operation operation = (Operation) it2.next();
                  if (FragmentManager.isLoggingEnabled(2)) {
                      Log.v("FragmentManager", "SpecialEffectsController: " + (isAttachedToWindow ? HttpUrl.FRAGMENT_ENCODE_SET : "Container " + this.mContainer + " is not attached to window. ") + "Cancelling running operation " + operation);
                  }
                  operation.cancel();
              }
              Iterator it3 = new ArrayList(this.mPendingOperations).iterator();
              while (it3.hasNext()) {
                  Operation operation2 = (Operation) it3.next();
                  if (FragmentManager.isLoggingEnabled(2)) {
                      Log.v("FragmentManager", "SpecialEffectsController: " + (isAttachedToWindow ? HttpUrl.FRAGMENT_ENCODE_SET : "Container " + this.mContainer + " is not attached to window. ") + "Cancelling pending operation " + operation2);
                  }
                  operation2.cancel();
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public void forcePostponedExecutePendingOperations() {
          if (this.mIsContainerPostponed) {
              this.mIsContainerPostponed = false;
              executePendingOperations();
          }
      }
  
      /* access modifiers changed from: package-private */
      public Operation.LifecycleImpact getAwaitingCompletionLifecycleImpact(FragmentStateManager fragmentStateManager) {
          Operation.LifecycleImpact lifecycleImpact = null;
          Operation findPendingOperation = findPendingOperation(fragmentStateManager.getFragment());
          if (findPendingOperation != null) {
              lifecycleImpact = findPendingOperation.getLifecycleImpact();
          }
          Operation findRunningOperation = findRunningOperation(fragmentStateManager.getFragment());
          return (findRunningOperation == null || !(lifecycleImpact == null || lifecycleImpact == Operation.LifecycleImpact.NONE)) ? lifecycleImpact : findRunningOperation.getLifecycleImpact();
      }
  
      public ViewGroup getContainer() {
          return this.mContainer;
      }
  
      /* access modifiers changed from: package-private */
      public void markPostponedState() {
          synchronized (this.mPendingOperations) {
              updateFinalState();
              this.mIsContainerPostponed = false;
              int size = this.mPendingOperations.size() - 1;
              while (true) {
                  if (size < 0) {
                      break;
                  }
                  Operation operation = this.mPendingOperations.get(size);
                  Operation.State from = Operation.State.from(operation.getFragment().mView);
                  if (operation.getFinalState() == Operation.State.VISIBLE && from != Operation.State.VISIBLE) {
                      this.mIsContainerPostponed = operation.getFragment().isPostponed();
                      break;
                  }
                  size--;
              }
          }
      }
  
      /* access modifiers changed from: package-private */
      public void updateOperationDirection(boolean isPop) {
          this.mOperationDirectionIsPop = isPop;
      }
  }
  