package androidx.fragment.app;

import android.content.res.Resources;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.common.R;
import java.util.ArrayList;
import java.util.Objects;
import java.util.WeakHashMap;
import o.AbstractC0126Ew;
import o.AbstractC1843mC;
import o.AbstractC2462sn;
import o.C0794bC;
import o.C1390hY;
import o.C1653kC;
import o.C1748lC;
import o.Ej0;
import o.InterfaceC1508ik0;
import o.Oj0;
import o.VK;
import o.ViewOnAttachStateChangeListenerC2491t3;
import o.WB;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class v {
    public final C1390hY a;
    public final w b;
    public final l c;
    public boolean d = false;
    public int e = -1;

    public v(C1390hY c1390hY, w wVar, l lVar) {
        this.a = c1390hY;
        this.b = wVar;
        this.c = lVar;
    }

    public final void a() {
        View view;
        View view2;
        ArrayList arrayList = this.b.a;
        l lVar = this.c;
        ViewGroup viewGroup = lVar.mContainer;
        int iIndexOfChild = -1;
        if (viewGroup != null) {
            int iIndexOf = arrayList.indexOf(lVar);
            int i = iIndexOf - 1;
            while (true) {
                if (i < 0) {
                    while (true) {
                        iIndexOf++;
                        if (iIndexOf >= arrayList.size()) {
                            break;
                        }
                        l lVar2 = (l) arrayList.get(iIndexOf);
                        if (lVar2.mContainer == viewGroup && (view = lVar2.mView) != null) {
                            iIndexOfChild = viewGroup.indexOfChild(view);
                            break;
                        }
                    }
                } else {
                    l lVar3 = (l) arrayList.get(i);
                    if (lVar3.mContainer == viewGroup && (view2 = lVar3.mView) != null) {
                        iIndexOfChild = viewGroup.indexOfChild(view2) + 1;
                        break;
                    }
                    i--;
                }
            }
        }
        lVar.mContainer.addView(lVar.mView, iIndexOfChild);
    }

    public final void b() {
        boolean zF = s.F(3);
        l lVar = this.c;
        if (zF) {
            Objects.toString(lVar);
        }
        l lVar2 = lVar.mTarget;
        v vVar = null;
        w wVar = this.b;
        if (lVar2 != null) {
            v vVar2 = (v) wVar.b.get(lVar2.mWho);
            if (vVar2 == null) {
                throw new IllegalStateException("Fragment " + lVar + " declared target fragment " + lVar.mTarget + " that does not belong to this FragmentManager!");
            }
            lVar.mTargetWho = lVar.mTarget.mWho;
            lVar.mTarget = null;
            vVar = vVar2;
        } else {
            String str = lVar.mTargetWho;
            if (str != null && (vVar = (v) wVar.b.get(str)) == null) {
                StringBuilder sb = new StringBuilder("Fragment ");
                sb.append(lVar);
                sb.append(" declared target fragment ");
                throw new IllegalStateException(AbstractC2462sn.n(sb, lVar.mTargetWho, " that does not belong to this FragmentManager!"));
            }
        }
        if (vVar != null) {
            vVar.i();
        }
        s sVar = lVar.mFragmentManager;
        lVar.mHost = sVar.t;
        lVar.mParentFragment = sVar.v;
        C1390hY c1390hY = this.a;
        c1390hY.l(false);
        lVar.performAttach();
        c1390hY.g(false);
    }

    public final int c() {
        x xVar;
        l lVar = this.c;
        if (lVar.mFragmentManager == null) {
            return lVar.mState;
        }
        int iMin = this.e;
        int iOrdinal = lVar.mMaxState.ordinal();
        int i = 0;
        if (iOrdinal == 1) {
            iMin = Math.min(iMin, 0);
        } else if (iOrdinal == 2) {
            iMin = Math.min(iMin, 1);
        } else if (iOrdinal == 3) {
            iMin = Math.min(iMin, 5);
        } else if (iOrdinal != 4) {
            iMin = Math.min(iMin, -1);
        }
        if (lVar.mFromLayout) {
            if (lVar.mInLayout) {
                iMin = Math.max(this.e, 2);
                View view = lVar.mView;
                if (view != null && view.getParent() == null) {
                    iMin = Math.min(iMin, 2);
                }
            } else {
                iMin = this.e < 4 ? Math.min(iMin, lVar.mState) : Math.min(iMin, 1);
            }
        }
        if (!lVar.mAdded) {
            iMin = Math.min(iMin, 1);
        }
        ViewGroup viewGroup = lVar.mContainer;
        if (viewGroup != null) {
            f fVarH = f.h(viewGroup, lVar.getParentFragmentManager());
            x xVarF = fVarH.f(lVar);
            int i2 = xVarF != null ? xVarF.b : 0;
            ArrayList arrayList = fVarH.c;
            int size = arrayList.size();
            while (true) {
                if (i >= size) {
                    xVar = null;
                    break;
                }
                Object obj = arrayList.get(i);
                i++;
                xVar = (x) obj;
                if (xVar.c.equals(lVar) && !xVar.f) {
                    break;
                }
            }
            i = (xVar == null || !(i2 == 0 || i2 == 1)) ? i2 : xVar.b;
        }
        if (i == 2) {
            iMin = Math.min(iMin, 6);
        } else if (i == 3) {
            iMin = Math.max(iMin, 3);
        } else if (lVar.mRemoving) {
            iMin = lVar.isInBackStack() ? Math.min(iMin, 1) : Math.min(iMin, -1);
        }
        if (lVar.mDeferStart && lVar.mState < 5) {
            iMin = Math.min(iMin, 4);
        }
        if (s.F(2)) {
            Objects.toString(lVar);
        }
        return iMin;
    }

    public final void d() throws Resources.NotFoundException {
        String resourceName;
        l lVar = this.c;
        if (lVar.mFromLayout) {
            return;
        }
        if (s.F(3)) {
            Objects.toString(lVar);
        }
        LayoutInflater layoutInflaterPerformGetLayoutInflater = lVar.performGetLayoutInflater(lVar.mSavedFragmentState);
        ViewGroup viewGroup = lVar.mContainer;
        if (viewGroup == null) {
            int i = lVar.mContainerId;
            if (i == 0) {
                viewGroup = null;
            } else {
                if (i == -1) {
                    throw new IllegalArgumentException(AbstractC0126Ew.m("Cannot create fragment ", lVar, " for a container view with no id"));
                }
                viewGroup = (ViewGroup) lVar.mFragmentManager.u.b(i);
                if (viewGroup == null) {
                    if (!lVar.mRestored) {
                        try {
                            resourceName = lVar.getResources().getResourceName(lVar.mContainerId);
                        } catch (Resources.NotFoundException unused) {
                            resourceName = "unknown";
                        }
                        throw new IllegalArgumentException("No view found for id 0x" + Integer.toHexString(lVar.mContainerId) + " (" + resourceName + ") for fragment " + lVar);
                    }
                } else if (!(viewGroup instanceof FragmentContainerView)) {
                    C1748lC c1748lC = AbstractC1843mC.a;
                    AbstractC1843mC.b(new C1653kC(lVar, "Attempting to add fragment " + lVar + " to container " + viewGroup + " which is not a FragmentContainerView"));
                    AbstractC1843mC.a(lVar).getClass();
                }
            }
        }
        lVar.mContainer = viewGroup;
        lVar.performCreateView(layoutInflaterPerformGetLayoutInflater, viewGroup, lVar.mSavedFragmentState);
        View view = lVar.mView;
        if (view != null) {
            view.setSaveFromParentEnabled(false);
            lVar.mView.setTag(R.id.fragment_container_view_tag, lVar);
            if (viewGroup != null) {
                a();
            }
            if (lVar.mHidden) {
                lVar.mView.setVisibility(8);
            }
            View view2 = lVar.mView;
            WeakHashMap weakHashMap = Oj0.a;
            if (view2.isAttachedToWindow()) {
                Ej0.c(lVar.mView);
            } else {
                View view3 = lVar.mView;
                view3.addOnAttachStateChangeListener(new ViewOnAttachStateChangeListenerC2491t3(4, view3));
            }
            lVar.performViewCreated();
            this.a.r(false);
            int visibility = lVar.mView.getVisibility();
            lVar.setPostOnViewCreatedAlpha(lVar.mView.getAlpha());
            if (lVar.mContainer != null && visibility == 0) {
                View viewFindFocus = lVar.mView.findFocus();
                if (viewFindFocus != null) {
                    lVar.setFocusedView(viewFindFocus);
                    if (s.F(2)) {
                        viewFindFocus.toString();
                        Objects.toString(lVar);
                    }
                }
                lVar.mView.setAlpha(0.0f);
            }
        }
        lVar.mState = 2;
    }

    public final void e() {
        l lVarB;
        boolean zF = s.F(3);
        l lVar = this.c;
        if (zF) {
            Objects.toString(lVar);
        }
        int i = 0;
        boolean zIsChangingConfigurations = true;
        boolean z = lVar.mRemoving && !lVar.isInBackStack();
        w wVar = this.b;
        if (z && !lVar.mBeingSaved) {
        }
        if (!z) {
            t tVar = wVar.d;
            if (!((tVar.b.containsKey(lVar.mWho) && tVar.e) ? tVar.f : true)) {
                String str = lVar.mTargetWho;
                if (str != null && (lVarB = wVar.b(str)) != null && lVarB.mRetainInstance) {
                    lVar.mTarget = lVarB;
                }
                lVar.mState = 0;
                return;
            }
        }
        WB wb = lVar.mHost;
        if (wb instanceof InterfaceC1508ik0) {
            zIsChangingConfigurations = wVar.d.f;
        } else {
            FragmentActivity fragmentActivity = wb.m;
            if (fragmentActivity != null) {
                zIsChangingConfigurations = true ^ fragmentActivity.isChangingConfigurations();
            }
        }
        if ((z && !lVar.mBeingSaved) || zIsChangingConfigurations) {
            t tVar2 = wVar.d;
            tVar2.getClass();
            if (s.F(3)) {
                Objects.toString(lVar);
            }
            tVar2.d(lVar.mWho);
        }
        lVar.performDestroy();
        this.a.i(false);
        ArrayList arrayListD = wVar.d();
        int size = arrayListD.size();
        while (i < size) {
            Object obj = arrayListD.get(i);
            i++;
            v vVar = (v) obj;
            if (vVar != null) {
                l lVar2 = vVar.c;
                if (lVar.mWho.equals(lVar2.mTargetWho)) {
                    lVar2.mTarget = lVar;
                    lVar2.mTargetWho = null;
                }
            }
        }
        String str2 = lVar.mTargetWho;
        if (str2 != null) {
            lVar.mTarget = wVar.b(str2);
        }
        wVar.h(this);
    }

    public final void f() {
        View view;
        boolean zF = s.F(3);
        l lVar = this.c;
        if (zF) {
            Objects.toString(lVar);
        }
        ViewGroup viewGroup = lVar.mContainer;
        if (viewGroup != null && (view = lVar.mView) != null) {
            viewGroup.removeView(view);
        }
        lVar.performDestroyView();
        this.a.s(false);
        lVar.mContainer = null;
        lVar.mView = null;
        lVar.mViewLifecycleOwner = null;
        lVar.mViewLifecycleOwnerLiveData.d(null);
        lVar.mInLayout = false;
    }

    public final void g() {
        boolean zF = s.F(3);
        l lVar = this.c;
        if (zF) {
            Objects.toString(lVar);
        }
        lVar.performDetach();
        this.a.j(false);
        lVar.mState = -1;
        lVar.mHost = null;
        lVar.mParentFragment = null;
        lVar.mFragmentManager = null;
        if (!lVar.mRemoving || lVar.isInBackStack()) {
            t tVar = this.b.d;
            if (!((tVar.b.containsKey(lVar.mWho) && tVar.e) ? tVar.f : true)) {
                return;
            }
        }
        if (s.F(3)) {
            Objects.toString(lVar);
        }
        lVar.initState();
    }

    public final void h() {
        l lVar = this.c;
        if (lVar.mFromLayout && lVar.mInLayout && !lVar.mPerformedCreateView) {
            if (s.F(3)) {
                Objects.toString(lVar);
            }
            lVar.performCreateView(lVar.performGetLayoutInflater(lVar.mSavedFragmentState), null, lVar.mSavedFragmentState);
            View view = lVar.mView;
            if (view != null) {
                view.setSaveFromParentEnabled(false);
                lVar.mView.setTag(R.id.fragment_container_view_tag, lVar);
                if (lVar.mHidden) {
                    lVar.mView.setVisibility(8);
                }
                lVar.performViewCreated();
                this.a.r(false);
                lVar.mState = 2;
            }
        }
    }

    public final void i() {
        ViewGroup viewGroup;
        ViewGroup viewGroup2;
        ViewGroup viewGroup3;
        boolean z = this.d;
        l lVar = this.c;
        if (z) {
            if (s.F(2)) {
                Objects.toString(lVar);
                return;
            }
            return;
        }
        try {
            this.d = true;
            boolean z2 = false;
            while (true) {
                int iC = c();
                int i = lVar.mState;
                w wVar = this.b;
                if (iC == i) {
                    if (!z2 && i == -1 && lVar.mRemoving && !lVar.isInBackStack() && !lVar.mBeingSaved) {
                        if (s.F(3)) {
                            Objects.toString(lVar);
                        }
                        t tVar = wVar.d;
                        tVar.getClass();
                        if (s.F(3)) {
                            Objects.toString(lVar);
                        }
                        tVar.d(lVar.mWho);
                        wVar.h(this);
                        if (s.F(3)) {
                            Objects.toString(lVar);
                        }
                        lVar.initState();
                    }
                    if (lVar.mHiddenChanged) {
                        if (lVar.mView != null && (viewGroup = lVar.mContainer) != null) {
                            f fVarH = f.h(viewGroup, lVar.getParentFragmentManager());
                            if (lVar.mHidden) {
                                if (s.F(2)) {
                                    Objects.toString(lVar);
                                }
                                fVarH.b(3, 1, this);
                            } else {
                                if (s.F(2)) {
                                    Objects.toString(lVar);
                                }
                                fVarH.b(2, 1, this);
                            }
                        }
                        s sVar = lVar.mFragmentManager;
                        if (sVar != null && lVar.mAdded && s.G(lVar)) {
                            sVar.D = true;
                        }
                        lVar.mHiddenChanged = false;
                        lVar.onHiddenChanged(lVar.mHidden);
                        lVar.mChildFragmentManager.n();
                    }
                    this.d = false;
                    return;
                }
                C1390hY c1390hY = this.a;
                if (iC <= i) {
                    switch (i - 1) {
                        case -1:
                            g();
                            break;
                        case 0:
                            if (lVar.mBeingSaved) {
                                if (((u) wVar.c.get(lVar.mWho)) == null) {
                                    l();
                                }
                            }
                            e();
                            break;
                        case 1:
                            f();
                            lVar.mState = 1;
                            break;
                        case 2:
                            lVar.mInLayout = false;
                            lVar.mState = 2;
                            break;
                        case 3:
                            if (s.F(3)) {
                                Objects.toString(lVar);
                            }
                            if (lVar.mBeingSaved) {
                                l();
                            } else if (lVar.mView != null && lVar.mSavedViewState == null) {
                                m();
                            }
                            if (lVar.mView != null && (viewGroup2 = lVar.mContainer) != null) {
                                f fVarH2 = f.h(viewGroup2, lVar.getParentFragmentManager());
                                if (s.F(2)) {
                                    Objects.toString(lVar);
                                }
                                fVarH2.b(1, 3, this);
                            }
                            lVar.mState = 3;
                            break;
                        case 4:
                            if (s.F(3)) {
                                Objects.toString(lVar);
                            }
                            lVar.performStop();
                            c1390hY.q(false);
                            break;
                        case 5:
                            lVar.mState = 5;
                            break;
                        case 6:
                            if (s.F(3)) {
                                Objects.toString(lVar);
                            }
                            lVar.performPause();
                            c1390hY.k(false);
                            break;
                    }
                } else {
                    switch (i + 1) {
                        case 0:
                            b();
                            break;
                        case 1:
                            if (s.F(3)) {
                                Objects.toString(lVar);
                            }
                            if (!lVar.mIsCreated) {
                                c1390hY.m(false);
                                lVar.performCreate(lVar.mSavedFragmentState);
                                c1390hY.h(false);
                                break;
                            } else {
                                lVar.restoreChildFragmentState(lVar.mSavedFragmentState);
                                lVar.mState = 1;
                                break;
                            }
                        case 2:
                            h();
                            d();
                            break;
                        case 3:
                            if (s.F(3)) {
                                Objects.toString(lVar);
                            }
                            lVar.performActivityCreated(lVar.mSavedFragmentState);
                            c1390hY.f(false);
                            break;
                        case 4:
                            if (lVar.mView != null && (viewGroup3 = lVar.mContainer) != null) {
                                f fVarH3 = f.h(viewGroup3, lVar.getParentFragmentManager());
                                int iB = AbstractC0126Ew.b(lVar.mView.getVisibility());
                                if (s.F(2)) {
                                    Objects.toString(lVar);
                                }
                                fVarH3.b(iB, 2, this);
                            }
                            lVar.mState = 4;
                            break;
                        case 5:
                            if (s.F(3)) {
                                Objects.toString(lVar);
                            }
                            lVar.performStart();
                            c1390hY.p(false);
                            break;
                        case 6:
                            lVar.mState = 6;
                            break;
                        case 7:
                            k();
                            break;
                    }
                }
                z2 = true;
            }
        } catch (Throwable th) {
            this.d = false;
            throw th;
        }
    }

    public final void j(ClassLoader classLoader) {
        l lVar = this.c;
        Bundle bundle = lVar.mSavedFragmentState;
        if (bundle == null) {
            return;
        }
        bundle.setClassLoader(classLoader);
        lVar.mSavedViewState = lVar.mSavedFragmentState.getSparseParcelableArray("android:view_state");
        lVar.mSavedViewRegistryState = lVar.mSavedFragmentState.getBundle("android:view_registry_state");
        lVar.mTargetWho = lVar.mSavedFragmentState.getString("android:target_state");
        if (lVar.mTargetWho != null) {
            lVar.mTargetRequestCode = lVar.mSavedFragmentState.getInt("android:target_req_state", 0);
        }
        Boolean bool = lVar.mSavedUserVisibleHint;
        if (bool != null) {
            lVar.mUserVisibleHint = bool.booleanValue();
            lVar.mSavedUserVisibleHint = null;
        } else {
            lVar.mUserVisibleHint = lVar.mSavedFragmentState.getBoolean("android:user_visible_hint", true);
        }
        if (lVar.mUserVisibleHint) {
            return;
        }
        lVar.mDeferStart = true;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x002b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void k() {
        /*
            r4 = this;
            r0 = 3
            boolean r0 = androidx.fragment.app.s.F(r0)
            androidx.fragment.app.l r1 = r4.c
            if (r0 == 0) goto Lc
            java.util.Objects.toString(r1)
        Lc:
            android.view.View r0 = r1.getFocusedView()
            if (r0 == 0) goto L40
            android.view.View r2 = r1.mView
            if (r0 != r2) goto L17
            goto L21
        L17:
            android.view.ViewParent r2 = r0.getParent()
        L1b:
            if (r2 == 0) goto L40
            android.view.View r3 = r1.mView
            if (r2 != r3) goto L3b
        L21:
            r0.requestFocus()
            r2 = 2
            boolean r2 = androidx.fragment.app.s.F(r2)
            if (r2 == 0) goto L40
            r0.toString()
            java.util.Objects.toString(r1)
            android.view.View r0 = r1.mView
            android.view.View r0 = r0.findFocus()
            java.util.Objects.toString(r0)
            goto L40
        L3b:
            android.view.ViewParent r2 = r2.getParent()
            goto L1b
        L40:
            r0 = 0
            r1.setFocusedView(r0)
            r1.performResume()
            o.hY r2 = r4.a
            r3 = 0
            r2.n(r3)
            r1.mSavedFragmentState = r0
            r1.mSavedViewState = r0
            r1.mSavedViewRegistryState = r0
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.fragment.app.v.k():void");
    }

    public final void l() {
        l lVar = this.c;
        u uVar = new u(lVar);
        if (lVar.mState <= -1 || uVar.x != null) {
            uVar.x = lVar.mSavedFragmentState;
        } else {
            Bundle bundle = new Bundle();
            lVar.performSaveInstanceState(bundle);
            this.a.o(false);
            if (bundle.isEmpty()) {
                bundle = null;
            }
            if (lVar.mView != null) {
                m();
            }
            if (lVar.mSavedViewState != null) {
                if (bundle == null) {
                    bundle = new Bundle();
                }
                bundle.putSparseParcelableArray("android:view_state", lVar.mSavedViewState);
            }
            if (lVar.mSavedViewRegistryState != null) {
                if (bundle == null) {
                    bundle = new Bundle();
                }
                bundle.putBundle("android:view_registry_state", lVar.mSavedViewRegistryState);
            }
            if (!lVar.mUserVisibleHint) {
                if (bundle == null) {
                    bundle = new Bundle();
                }
                bundle.putBoolean("android:user_visible_hint", lVar.mUserVisibleHint);
            }
            uVar.x = bundle;
            if (lVar.mTargetWho != null) {
                if (bundle == null) {
                    uVar.x = new Bundle();
                }
                uVar.x.putString("android:target_state", lVar.mTargetWho);
                int i = lVar.mTargetRequestCode;
                if (i != 0) {
                    uVar.x.putInt("android:target_req_state", i);
                }
            }
        }
    }

    public final void m() {
        l lVar = this.c;
        if (lVar.mView == null) {
            return;
        }
        if (s.F(2)) {
            Objects.toString(lVar);
            Objects.toString(lVar.mView);
        }
        SparseArray<Parcelable> sparseArray = new SparseArray<>();
        lVar.mView.saveHierarchyState(sparseArray);
        if (sparseArray.size() > 0) {
            lVar.mSavedViewState = sparseArray;
        }
        Bundle bundle = new Bundle();
        lVar.mViewLifecycleOwner.f66o.b(bundle);
        if (bundle.isEmpty()) {
            return;
        }
        lVar.mSavedViewRegistryState = bundle;
    }

    public v(C1390hY c1390hY, w wVar, ClassLoader classLoader, C0794bC c0794bC, u uVar) {
        this.a = c1390hY;
        this.b = wVar;
        l lVarInstantiate = l.instantiate(c0794bC.a.t.m, uVar.l, null);
        Bundle bundle = uVar.u;
        if (bundle != null) {
            bundle.setClassLoader(classLoader);
        }
        lVarInstantiate.setArguments(bundle);
        lVarInstantiate.mWho = uVar.m;
        lVarInstantiate.mFromLayout = uVar.n;
        lVarInstantiate.mRestored = true;
        lVarInstantiate.mFragmentId = uVar.f18o;
        lVarInstantiate.mContainerId = uVar.p;
        lVarInstantiate.mTag = uVar.q;
        lVarInstantiate.mRetainInstance = uVar.r;
        lVarInstantiate.mRemoving = uVar.s;
        lVarInstantiate.mDetached = uVar.t;
        lVarInstantiate.mHidden = uVar.v;
        lVarInstantiate.mMaxState = VK.values()[uVar.w];
        Bundle bundle2 = uVar.x;
        if (bundle2 != null) {
            lVarInstantiate.mSavedFragmentState = bundle2;
        } else {
            lVarInstantiate.mSavedFragmentState = new Bundle();
        }
        this.c = lVarInstantiate;
        if (s.F(2)) {
            Objects.toString(lVarInstantiate);
        }
    }

    public v(C1390hY c1390hY, w wVar, l lVar, u uVar) {
        this.a = c1390hY;
        this.b = wVar;
        this.c = lVar;
        lVar.mSavedViewState = null;
        lVar.mSavedViewRegistryState = null;
        lVar.mBackStackNesting = 0;
        lVar.mInLayout = false;
        lVar.mAdded = false;
        l lVar2 = lVar.mTarget;
        lVar.mTargetWho = lVar2 != null ? lVar2.mWho : null;
        lVar.mTarget = null;
        Bundle bundle = uVar.x;
        if (bundle != null) {
            lVar.mSavedFragmentState = bundle;
        } else {
            lVar.mSavedFragmentState = new Bundle();
        }
    }
}
