package androidx.fragment.app;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import p011d0.C0605h;
import p023h0.C0829h1;
import p047p0.C1535b;

/* renamed from: androidx.fragment.app.q0 */
/* loaded from: classes.dex */
public abstract class AbstractC0360q0 {

    /* renamed from: a */
    public final ViewGroup f1449a;

    /* renamed from: b */
    public final ArrayList<C0365e> f1450b = new ArrayList<>();

    /* renamed from: c */
    public final ArrayList<C0365e> f1451c = new ArrayList<>();

    /* renamed from: d */
    public boolean f1452d = false;

    /* renamed from: e */
    public boolean f1453e = false;

    /* renamed from: androidx.fragment.app.q0$a */
    /* loaded from: classes.dex */
    public class RunnableC0361a implements Runnable {

        /* renamed from: d */
        public final /* synthetic */ C0364d f1454d;

        public RunnableC0361a(C0364d c0364d) {
            this.f1454d = c0364d;
        }

        @Override // java.lang.Runnable
        public void run() {
            if (AbstractC0360q0.this.f1450b.contains(this.f1454d)) {
                this.f1454d.m3853e().m3845a(this.f1454d.m3852f().f1162K);
            }
        }
    }

    /* renamed from: androidx.fragment.app.q0$b */
    /* loaded from: classes.dex */
    public class RunnableC0362b implements Runnable {

        /* renamed from: d */
        public final /* synthetic */ C0364d f1456d;

        public RunnableC0362b(C0364d c0364d) {
            this.f1456d = c0364d;
        }

        @Override // java.lang.Runnable
        public void run() {
            AbstractC0360q0.this.f1450b.remove(this.f1456d);
            AbstractC0360q0.this.f1451c.remove(this.f1456d);
        }
    }

    /* renamed from: androidx.fragment.app.q0$c */
    /* loaded from: classes.dex */
    public static /* synthetic */ class C0363c {

        /* renamed from: a */
        public static final /* synthetic */ int[] f1458a;

        /* renamed from: b */
        public static final /* synthetic */ int[] f1459b;

        static {
            int[] iArr = new int[C0365e.EnumC0367b.values().length];
            f1459b = iArr;
            try {
                iArr[C0365e.EnumC0367b.ADDING.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f1459b[C0365e.EnumC0367b.REMOVING.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f1459b[C0365e.EnumC0367b.NONE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            int[] iArr2 = new int[C0365e.EnumC0368c.values().length];
            f1458a = iArr2;
            try {
                iArr2[C0365e.EnumC0368c.REMOVED.ordinal()] = 1;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                f1458a[C0365e.EnumC0368c.VISIBLE.ordinal()] = 2;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                f1458a[C0365e.EnumC0368c.GONE.ordinal()] = 3;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                f1458a[C0365e.EnumC0368c.INVISIBLE.ordinal()] = 4;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    /* renamed from: androidx.fragment.app.q0$d */
    /* loaded from: classes.dex */
    public static class C0364d extends C0365e {

        /* renamed from: h */
        public final C0372s f1460h;

        public C0364d(C0365e.EnumC0368c enumC0368c, C0365e.EnumC0367b enumC0367b, C0372s c0372s, C0605h c0605h) {
            super(enumC0368c, enumC0367b, c0372s.m3829k(), c0605h);
            this.f1460h = c0372s;
        }

        @Override // androidx.fragment.app.AbstractC0360q0.C0365e
        /* renamed from: c */
        public void mo3855c() {
            super.mo3855c();
            this.f1460h.m3827m();
        }

        @Override // androidx.fragment.app.AbstractC0360q0.C0365e
        /* renamed from: l */
        public void mo3846l() {
            if (m3851g() == C0365e.EnumC0367b.ADDING) {
                Fragment m3829k = this.f1460h.m3829k();
                View findFocus = m3829k.f1162K.findFocus();
                if (findFocus != null) {
                    m3829k.m4190r1(findFocus);
                    if (AbstractC0330m.m4049B0(2)) {
                        Log.v("FragmentManager", "requestFocus: Saved focused view " + findFocus + " for Fragment " + m3829k);
                    }
                }
                View m4214j1 = m3852f().m4214j1();
                if (m4214j1.getParent() == null) {
                    this.f1460h.m3838b();
                    m4214j1.setAlpha(0.0f);
                }
                if (m4214j1.getAlpha() == 0.0f && m4214j1.getVisibility() == 0) {
                    m4214j1.setVisibility(4);
                }
                m4214j1.setAlpha(m3829k.m4276H());
            }
        }
    }

    /* renamed from: androidx.fragment.app.q0$e */
    /* loaded from: classes.dex */
    public static class C0365e {

        /* renamed from: a */
        public EnumC0368c f1461a;

        /* renamed from: b */
        public EnumC0367b f1462b;

        /* renamed from: c */
        public final Fragment f1463c;

        /* renamed from: d */
        public final List<Runnable> f1464d = new ArrayList();

        /* renamed from: e */
        public final HashSet<C0605h> f1465e = new HashSet<>();

        /* renamed from: f */
        public boolean f1466f = false;

        /* renamed from: g */
        public boolean f1467g = false;

        /* renamed from: androidx.fragment.app.q0$e$a */
        /* loaded from: classes.dex */
        public class C0366a implements C0605h.InterfaceC0607b {
            public C0366a() {
            }

            @Override // p011d0.C0605h.InterfaceC0607b
            public void onCancel() {
                C0365e.this.m3856b();
            }
        }

        /* renamed from: androidx.fragment.app.q0$e$b */
        /* loaded from: classes.dex */
        public enum EnumC0367b {
            NONE,
            ADDING,
            REMOVING
        }

        /* renamed from: androidx.fragment.app.q0$e$c */
        /* loaded from: classes.dex */
        public enum EnumC0368c {
            REMOVED,
            VISIBLE,
            GONE,
            INVISIBLE;

            /* renamed from: b */
            public static EnumC0368c m3844b(int i) {
                if (i != 0) {
                    if (i != 4) {
                        if (i == 8) {
                            return GONE;
                        }
                        throw new IllegalArgumentException("Unknown visibility " + i);
                    }
                    return INVISIBLE;
                }
                return VISIBLE;
            }

            /* renamed from: c */
            public static EnumC0368c m3843c(View view) {
                return (view.getAlpha() == 0.0f && view.getVisibility() == 0) ? INVISIBLE : m3844b(view.getVisibility());
            }

            /* renamed from: a */
            public void m3845a(View view) {
                int i;
                int i2 = C0363c.f1458a[ordinal()];
                if (i2 == 1) {
                    ViewGroup viewGroup = (ViewGroup) view.getParent();
                    if (viewGroup != null) {
                        if (AbstractC0330m.m4049B0(2)) {
                            Log.v("FragmentManager", "SpecialEffectsController: Removing view " + view + " from container " + viewGroup);
                        }
                        viewGroup.removeView(view);
                        return;
                    }
                    return;
                }
                if (i2 == 2) {
                    if (AbstractC0330m.m4049B0(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to VISIBLE");
                    }
                    i = 0;
                } else if (i2 != 3) {
                    if (i2 != 4) {
                        return;
                    }
                    if (AbstractC0330m.m4049B0(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to INVISIBLE");
                    }
                    view.setVisibility(4);
                    return;
                } else {
                    if (AbstractC0330m.m4049B0(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to GONE");
                    }
                    i = 8;
                }
                view.setVisibility(i);
            }
        }

        public C0365e(EnumC0368c enumC0368c, EnumC0367b enumC0367b, Fragment fragment, C0605h c0605h) {
            this.f1461a = enumC0368c;
            this.f1462b = enumC0367b;
            this.f1463c = fragment;
            c0605h.m3279c(new C0366a());
        }

        /* renamed from: a */
        public final void m3857a(Runnable runnable) {
            this.f1464d.add(runnable);
        }

        /* renamed from: b */
        public final void m3856b() {
            if (m3850h()) {
                return;
            }
            this.f1466f = true;
            if (this.f1465e.isEmpty()) {
                mo3855c();
                return;
            }
            Iterator it = new ArrayList(this.f1465e).iterator();
            while (it.hasNext()) {
                ((C0605h) it.next()).m3281a();
            }
        }

        /* renamed from: c */
        public void mo3855c() {
            if (this.f1467g) {
                return;
            }
            if (AbstractC0330m.m4049B0(2)) {
                Log.v("FragmentManager", "SpecialEffectsController: " + this + " has called complete.");
            }
            this.f1467g = true;
            for (Runnable runnable : this.f1464d) {
                runnable.run();
            }
        }

        /* renamed from: d */
        public final void m3854d(C0605h c0605h) {
            if (this.f1465e.remove(c0605h) && this.f1465e.isEmpty()) {
                mo3855c();
            }
        }

        /* renamed from: e */
        public EnumC0368c m3853e() {
            return this.f1461a;
        }

        /* renamed from: f */
        public final Fragment m3852f() {
            return this.f1463c;
        }

        /* renamed from: g */
        public EnumC0367b m3851g() {
            return this.f1462b;
        }

        /* renamed from: h */
        public final boolean m3850h() {
            return this.f1466f;
        }

        /* renamed from: i */
        public final boolean m3849i() {
            return this.f1467g;
        }

        /* renamed from: j */
        public final void m3848j(C0605h c0605h) {
            mo3846l();
            this.f1465e.add(c0605h);
        }

        /* renamed from: k */
        public final void m3847k(EnumC0368c enumC0368c, EnumC0367b enumC0367b) {
            EnumC0367b enumC0367b2;
            int i = C0363c.f1459b[enumC0367b.ordinal()];
            if (i != 1) {
                if (i != 2) {
                    if (i == 3 && this.f1461a != EnumC0368c.REMOVED) {
                        if (AbstractC0330m.m4049B0(2)) {
                            Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.f1463c + " mFinalState = " + this.f1461a + " -> " + enumC0368c + ". ");
                        }
                        this.f1461a = enumC0368c;
                        return;
                    }
                    return;
                }
                if (AbstractC0330m.m4049B0(2)) {
                    Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.f1463c + " mFinalState = " + this.f1461a + " -> REMOVED. mLifecycleImpact  = " + this.f1462b + " to REMOVING.");
                }
                this.f1461a = EnumC0368c.REMOVED;
                enumC0367b2 = EnumC0367b.REMOVING;
            } else if (this.f1461a != EnumC0368c.REMOVED) {
                return;
            } else {
                if (AbstractC0330m.m4049B0(2)) {
                    Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.f1463c + " mFinalState = REMOVED -> VISIBLE. mLifecycleImpact = " + this.f1462b + " to ADDING.");
                }
                this.f1461a = EnumC0368c.VISIBLE;
                enumC0367b2 = EnumC0367b.ADDING;
            }
            this.f1462b = enumC0367b2;
        }

        /* renamed from: l */
        public void mo3846l() {
        }

        public String toString() {
            return "Operation {" + Integer.toHexString(System.identityHashCode(this)) + "} {mFinalState = " + this.f1461a + "} {mLifecycleImpact = " + this.f1462b + "} {mFragment = " + this.f1463c + "}";
        }
    }

    public AbstractC0360q0(ViewGroup viewGroup) {
        this.f1449a = viewGroup;
    }

    /* renamed from: n */
    public static AbstractC0360q0 m3862n(ViewGroup viewGroup, AbstractC0330m abstractC0330m) {
        return m3861o(viewGroup, abstractC0330m.m3951u0());
    }

    /* renamed from: o */
    public static AbstractC0360q0 m3861o(ViewGroup viewGroup, InterfaceC0371r0 interfaceC0371r0) {
        int i = C1535b.special_effects_controller_view_tag;
        Object tag = viewGroup.getTag(i);
        if (tag instanceof AbstractC0360q0) {
            return (AbstractC0360q0) tag;
        }
        AbstractC0360q0 mo3840a = interfaceC0371r0.mo3840a(viewGroup);
        viewGroup.setTag(i, mo3840a);
        return mo3840a;
    }

    /* renamed from: a */
    public final void m3875a(C0365e.EnumC0368c enumC0368c, C0365e.EnumC0367b enumC0367b, C0372s c0372s) {
        synchronized (this.f1450b) {
            C0605h c0605h = new C0605h();
            C0365e m3868h = m3868h(c0372s.m3829k());
            if (m3868h != null) {
                m3868h.m3847k(enumC0368c, enumC0367b);
                return;
            }
            C0364d c0364d = new C0364d(enumC0368c, enumC0367b, c0372s, c0605h);
            this.f1450b.add(c0364d);
            c0364d.m3857a(new RunnableC0361a(c0364d));
            c0364d.m3857a(new RunnableC0362b(c0364d));
        }
    }

    /* renamed from: b */
    public void m3874b(C0365e.EnumC0368c enumC0368c, C0372s c0372s) {
        if (AbstractC0330m.m4049B0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Enqueuing add operation for fragment " + c0372s.m3829k());
        }
        m3875a(enumC0368c, C0365e.EnumC0367b.ADDING, c0372s);
    }

    /* renamed from: c */
    public void m3873c(C0372s c0372s) {
        if (AbstractC0330m.m4049B0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Enqueuing hide operation for fragment " + c0372s.m3829k());
        }
        m3875a(C0365e.EnumC0368c.GONE, C0365e.EnumC0367b.NONE, c0372s);
    }

    /* renamed from: d */
    public void m3872d(C0372s c0372s) {
        if (AbstractC0330m.m4049B0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Enqueuing remove operation for fragment " + c0372s.m3829k());
        }
        m3875a(C0365e.EnumC0368c.REMOVED, C0365e.EnumC0367b.REMOVING, c0372s);
    }

    /* renamed from: e */
    public void m3871e(C0372s c0372s) {
        if (AbstractC0330m.m4049B0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Enqueuing show operation for fragment " + c0372s.m3829k());
        }
        m3875a(C0365e.EnumC0368c.VISIBLE, C0365e.EnumC0367b.NONE, c0372s);
    }

    /* renamed from: f */
    public abstract void mo3870f(List<C0365e> list, boolean z);

    /* renamed from: g */
    public void m3869g() {
        if (this.f1453e) {
            return;
        }
        if (!C0829h1.m2862A(this.f1449a)) {
            m3866j();
            this.f1452d = false;
            return;
        }
        synchronized (this.f1450b) {
            if (!this.f1450b.isEmpty()) {
                ArrayList arrayList = new ArrayList(this.f1451c);
                this.f1451c.clear();
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    C0365e c0365e = (C0365e) it.next();
                    if (AbstractC0330m.m4049B0(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Cancelling operation " + c0365e);
                    }
                    c0365e.m3856b();
                    if (!c0365e.m3849i()) {
                        this.f1451c.add(c0365e);
                    }
                }
                m3859q();
                ArrayList arrayList2 = new ArrayList(this.f1450b);
                this.f1450b.clear();
                this.f1451c.addAll(arrayList2);
                Iterator it2 = arrayList2.iterator();
                while (it2.hasNext()) {
                    ((C0365e) it2.next()).mo3846l();
                }
                mo3870f(arrayList2, this.f1452d);
                this.f1452d = false;
            }
        }
    }

    /* renamed from: h */
    public final C0365e m3868h(Fragment fragment) {
        Iterator<C0365e> it = this.f1450b.iterator();
        while (it.hasNext()) {
            C0365e next = it.next();
            if (next.m3852f().equals(fragment) && !next.m3850h()) {
                return next;
            }
        }
        return null;
    }

    /* renamed from: i */
    public final C0365e m3867i(Fragment fragment) {
        Iterator<C0365e> it = this.f1451c.iterator();
        while (it.hasNext()) {
            C0365e next = it.next();
            if (next.m3852f().equals(fragment) && !next.m3850h()) {
                return next;
            }
        }
        return null;
    }

    /* renamed from: j */
    public void m3866j() {
        String str;
        String str2;
        boolean m2862A = C0829h1.m2862A(this.f1449a);
        synchronized (this.f1450b) {
            m3859q();
            Iterator<C0365e> it = this.f1450b.iterator();
            while (it.hasNext()) {
                it.next().mo3846l();
            }
            Iterator it2 = new ArrayList(this.f1451c).iterator();
            while (it2.hasNext()) {
                C0365e c0365e = (C0365e) it2.next();
                if (AbstractC0330m.m4049B0(2)) {
                    StringBuilder sb = new StringBuilder();
                    sb.append("SpecialEffectsController: ");
                    if (m2862A) {
                        str2 = "";
                    } else {
                        str2 = "Container " + this.f1449a + " is not attached to window. ";
                    }
                    sb.append(str2);
                    sb.append("Cancelling running operation ");
                    sb.append(c0365e);
                    Log.v("FragmentManager", sb.toString());
                }
                c0365e.m3856b();
            }
            Iterator it3 = new ArrayList(this.f1450b).iterator();
            while (it3.hasNext()) {
                C0365e c0365e2 = (C0365e) it3.next();
                if (AbstractC0330m.m4049B0(2)) {
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append("SpecialEffectsController: ");
                    if (m2862A) {
                        str = "";
                    } else {
                        str = "Container " + this.f1449a + " is not attached to window. ";
                    }
                    sb2.append(str);
                    sb2.append("Cancelling pending operation ");
                    sb2.append(c0365e2);
                    Log.v("FragmentManager", sb2.toString());
                }
                c0365e2.m3856b();
            }
        }
    }

    /* renamed from: k */
    public void m3865k() {
        if (this.f1453e) {
            this.f1453e = false;
            m3869g();
        }
    }

    /* renamed from: l */
    public C0365e.EnumC0367b m3864l(C0372s c0372s) {
        C0365e m3868h = m3868h(c0372s.m3829k());
        C0365e.EnumC0367b m3851g = m3868h != null ? m3868h.m3851g() : null;
        C0365e m3867i = m3867i(c0372s.m3829k());
        return (m3867i == null || !(m3851g == null || m3851g == C0365e.EnumC0367b.NONE)) ? m3851g : m3867i.m3851g();
    }

    /* renamed from: m */
    public ViewGroup m3863m() {
        return this.f1449a;
    }

    /* renamed from: p */
    public void m3860p() {
        synchronized (this.f1450b) {
            m3859q();
            this.f1453e = false;
            int size = this.f1450b.size() - 1;
            while (true) {
                if (size < 0) {
                    break;
                }
                C0365e c0365e = this.f1450b.get(size);
                C0365e.EnumC0368c m3843c = C0365e.EnumC0368c.m3843c(c0365e.m3852f().f1162K);
                C0365e.EnumC0368c m3853e = c0365e.m3853e();
                C0365e.EnumC0368c enumC0368c = C0365e.EnumC0368c.VISIBLE;
                if (m3853e == enumC0368c && m3843c != enumC0368c) {
                    this.f1453e = c0365e.m3852f().m4244X();
                    break;
                }
                size--;
            }
        }
    }

    /* renamed from: q */
    public final void m3859q() {
        Iterator<C0365e> it = this.f1450b.iterator();
        while (it.hasNext()) {
            C0365e next = it.next();
            if (next.m3851g() == C0365e.EnumC0367b.ADDING) {
                next.m3847k(C0365e.EnumC0368c.m3844b(next.m3852f().m4214j1().getVisibility()), C0365e.EnumC0367b.NONE);
            }
        }
    }

    /* renamed from: r */
    public void m3858r(boolean z) {
        this.f1452d = z;
    }
}