package androidx.fragment.app;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.core.os.d;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public abstract class r0 {

    /* renamed from: a, reason: collision with root package name */
    private final ViewGroup f4641a;

    /* renamed from: b, reason: collision with root package name */
    final ArrayList f4642b = new ArrayList();

    /* renamed from: c, reason: collision with root package name */
    final ArrayList f4643c = new ArrayList();

    /* renamed from: d, reason: collision with root package name */
    boolean f4644d = false;

    /* renamed from: e, reason: collision with root package name */
    boolean f4645e = false;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class a implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ d f4646p;

        a(d dVar) {
            this.f4646p = dVar;
        }

        @Override // java.lang.Runnable
        public void run() {
            if (r0.this.f4642b.contains(this.f4646p)) {
                this.f4646p.e().applyState(this.f4646p.f().mView);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class b implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ d f4648p;

        b(d dVar) {
            this.f4648p = dVar;
        }

        @Override // java.lang.Runnable
        public void run() {
            r0.this.f4642b.remove(this.f4648p);
            r0.this.f4643c.remove(this.f4648p);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static /* synthetic */ class c {

        /* renamed from: a, reason: collision with root package name */
        static final /* synthetic */ int[] f4650a;

        /* renamed from: b, reason: collision with root package name */
        static final /* synthetic */ int[] f4651b;

        static {
            int[] iArr = new int[e.b.values().length];
            f4651b = iArr;
            try {
                iArr[e.b.ADDING.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f4651b[e.b.REMOVING.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f4651b[e.b.NONE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            int[] iArr2 = new int[e.c.values().length];
            f4650a = iArr2;
            try {
                iArr2[e.c.REMOVED.ordinal()] = 1;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                f4650a[e.c.VISIBLE.ordinal()] = 2;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                f4650a[e.c.GONE.ordinal()] = 3;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                f4650a[e.c.INVISIBLE.ordinal()] = 4;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class d extends e {

        /* renamed from: h, reason: collision with root package name */
        private final h0 f4652h;

        d(e.c cVar, e.b bVar, h0 h0Var, androidx.core.os.d dVar) {
            super(cVar, bVar, h0Var.k(), dVar);
            this.f4652h = h0Var;
        }

        @Override // androidx.fragment.app.r0.e
        public void c() {
            super.c();
            this.f4652h.m();
        }

        @Override // androidx.fragment.app.r0.e
        void l() {
            if (g() != e.b.ADDING) {
                if (g() == e.b.REMOVING) {
                    f k10 = this.f4652h.k();
                    View requireView = k10.requireView();
                    if (z.N0(2)) {
                        Log.v("FragmentManager", "Clearing focus " + requireView.findFocus() + " on view " + requireView + " for Fragment " + k10);
                    }
                    requireView.clearFocus();
                    return;
                }
                return;
            }
            f k11 = this.f4652h.k();
            View findFocus = k11.mView.findFocus();
            if (findFocus != null) {
                k11.setFocusedView(findFocus);
                if (z.N0(2)) {
                    Log.v("FragmentManager", "requestFocus: Saved focused view " + findFocus + " for Fragment " + k11);
                }
            }
            View requireView2 = f().requireView();
            if (requireView2.getParent() == null) {
                this.f4652h.b();
                requireView2.setAlpha(BitmapDescriptorFactory.HUE_RED);
            }
            if (requireView2.getAlpha() == BitmapDescriptorFactory.HUE_RED && requireView2.getVisibility() == 0) {
                requireView2.setVisibility(4);
            }
            requireView2.setAlpha(k11.getPostOnViewCreatedAlpha());
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public r0(ViewGroup viewGroup) {
        this.f4641a = viewGroup;
    }

    private void a(e.c cVar, e.b bVar, h0 h0Var) {
        synchronized (this.f4642b) {
            androidx.core.os.d dVar = new androidx.core.os.d();
            e h10 = h(h0Var.k());
            if (h10 != null) {
                h10.k(cVar, bVar);
                return;
            }
            d dVar2 = new d(cVar, bVar, h0Var, dVar);
            this.f4642b.add(dVar2);
            dVar2.a(new a(dVar2));
            dVar2.a(new b(dVar2));
        }
    }

    private e h(f fVar) {
        Iterator it = this.f4642b.iterator();
        while (it.hasNext()) {
            e eVar = (e) it.next();
            if (eVar.f().equals(fVar) && !eVar.h()) {
                return eVar;
            }
        }
        return null;
    }

    private e i(f fVar) {
        Iterator it = this.f4643c.iterator();
        while (it.hasNext()) {
            e eVar = (e) it.next();
            if (eVar.f().equals(fVar) && !eVar.h()) {
                return eVar;
            }
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static r0 n(ViewGroup viewGroup, z zVar) {
        return o(viewGroup, zVar.F0());
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static r0 o(ViewGroup viewGroup, s0 s0Var) {
        int i10 = l4.b.f27460b;
        Object tag = viewGroup.getTag(i10);
        if (tag instanceof r0) {
            return (r0) tag;
        }
        r0 a10 = s0Var.a(viewGroup);
        viewGroup.setTag(i10, a10);
        return a10;
    }

    private void q() {
        Iterator it = this.f4642b.iterator();
        while (it.hasNext()) {
            e eVar = (e) it.next();
            if (eVar.g() == e.b.ADDING) {
                eVar.k(e.c.from(eVar.f().requireView().getVisibility()), e.b.NONE);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void b(e.c cVar, h0 h0Var) {
        if (z.N0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Enqueuing add operation for fragment " + h0Var.k());
        }
        a(cVar, e.b.ADDING, h0Var);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void c(h0 h0Var) {
        if (z.N0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Enqueuing hide operation for fragment " + h0Var.k());
        }
        a(e.c.GONE, e.b.NONE, h0Var);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void d(h0 h0Var) {
        if (z.N0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Enqueuing remove operation for fragment " + h0Var.k());
        }
        a(e.c.REMOVED, e.b.REMOVING, h0Var);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void e(h0 h0Var) {
        if (z.N0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Enqueuing show operation for fragment " + h0Var.k());
        }
        a(e.c.VISIBLE, e.b.NONE, h0Var);
    }

    abstract void f(List list, boolean z10);

    /* JADX INFO: Access modifiers changed from: package-private */
    public void g() {
        if (this.f4645e) {
            return;
        }
        if (!androidx.core.view.s0.P(this.f4641a)) {
            j();
            this.f4644d = false;
            return;
        }
        synchronized (this.f4642b) {
            if (!this.f4642b.isEmpty()) {
                ArrayList arrayList = new ArrayList(this.f4643c);
                this.f4643c.clear();
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    e eVar = (e) it.next();
                    if (z.N0(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Cancelling operation " + eVar);
                    }
                    eVar.b();
                    if (!eVar.i()) {
                        this.f4643c.add(eVar);
                    }
                }
                q();
                ArrayList arrayList2 = new ArrayList(this.f4642b);
                this.f4642b.clear();
                this.f4643c.addAll(arrayList2);
                if (z.N0(2)) {
                    Log.v("FragmentManager", "SpecialEffectsController: Executing pending operations");
                }
                Iterator it2 = arrayList2.iterator();
                while (it2.hasNext()) {
                    ((e) it2.next()).l();
                }
                f(arrayList2, this.f4644d);
                this.f4644d = false;
                if (z.N0(2)) {
                    Log.v("FragmentManager", "SpecialEffectsController: Finished executing pending operations");
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void j() {
        String str;
        String str2;
        if (z.N0(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Forcing all operations to complete");
        }
        boolean P = androidx.core.view.s0.P(this.f4641a);
        synchronized (this.f4642b) {
            q();
            Iterator it = this.f4642b.iterator();
            while (it.hasNext()) {
                ((e) it.next()).l();
            }
            Iterator it2 = new ArrayList(this.f4643c).iterator();
            while (it2.hasNext()) {
                e eVar = (e) it2.next();
                if (z.N0(2)) {
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append("SpecialEffectsController: ");
                    if (P) {
                        str2 = "";
                    } else {
                        str2 = "Container " + this.f4641a + " is not attached to window. ";
                    }
                    sb2.append(str2);
                    sb2.append("Cancelling running operation ");
                    sb2.append(eVar);
                    Log.v("FragmentManager", sb2.toString());
                }
                eVar.b();
            }
            Iterator it3 = new ArrayList(this.f4642b).iterator();
            while (it3.hasNext()) {
                e eVar2 = (e) it3.next();
                if (z.N0(2)) {
                    StringBuilder sb3 = new StringBuilder();
                    sb3.append("SpecialEffectsController: ");
                    if (P) {
                        str = "";
                    } else {
                        str = "Container " + this.f4641a + " is not attached to window. ";
                    }
                    sb3.append(str);
                    sb3.append("Cancelling pending operation ");
                    sb3.append(eVar2);
                    Log.v("FragmentManager", sb3.toString());
                }
                eVar2.b();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void k() {
        if (this.f4645e) {
            if (z.N0(2)) {
                Log.v("FragmentManager", "SpecialEffectsController: Forcing postponed operations");
            }
            this.f4645e = false;
            g();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public e.b l(h0 h0Var) {
        e h10 = h(h0Var.k());
        e.b g10 = h10 != null ? h10.g() : null;
        e i10 = i(h0Var.k());
        return (i10 == null || !(g10 == null || g10 == e.b.NONE)) ? g10 : i10.g();
    }

    public ViewGroup m() {
        return this.f4641a;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void p() {
        synchronized (this.f4642b) {
            q();
            this.f4645e = false;
            int size = this.f4642b.size() - 1;
            while (true) {
                if (size < 0) {
                    break;
                }
                e eVar = (e) this.f4642b.get(size);
                e.c from = e.c.from(eVar.f().mView);
                e.c e10 = eVar.e();
                e.c cVar = e.c.VISIBLE;
                if (e10 == cVar && from != cVar) {
                    this.f4645e = eVar.f().isPostponed();
                    break;
                }
                size--;
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void r(boolean z10) {
        this.f4644d = z10;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class e {

        /* renamed from: a, reason: collision with root package name */
        private c f4653a;

        /* renamed from: b, reason: collision with root package name */
        private b f4654b;

        /* renamed from: c, reason: collision with root package name */
        private final f f4655c;

        /* renamed from: d, reason: collision with root package name */
        private final List f4656d = new ArrayList();

        /* renamed from: e, reason: collision with root package name */
        private final HashSet f4657e = new HashSet();

        /* renamed from: f, reason: collision with root package name */
        private boolean f4658f = false;

        /* renamed from: g, reason: collision with root package name */
        private boolean f4659g = false;

        /* loaded from: classes.dex */
        class a implements d.a {
            a() {
            }

            @Override // androidx.core.os.d.a
            public void onCancel() {
                e.this.b();
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* loaded from: classes.dex */
        public enum b {
            NONE,
            ADDING,
            REMOVING
        }

        e(c cVar, b bVar, f fVar, androidx.core.os.d dVar) {
            this.f4653a = cVar;
            this.f4654b = bVar;
            this.f4655c = fVar;
            dVar.c(new a());
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        public final void a(Runnable runnable) {
            this.f4656d.add(runnable);
        }

        final void b() {
            if (h()) {
                return;
            }
            this.f4658f = true;
            if (this.f4657e.isEmpty()) {
                c();
                return;
            }
            Iterator it = new ArrayList(this.f4657e).iterator();
            while (it.hasNext()) {
                ((androidx.core.os.d) it.next()).a();
            }
        }

        public void c() {
            if (this.f4659g) {
                return;
            }
            if (z.N0(2)) {
                Log.v("FragmentManager", "SpecialEffectsController: " + this + " has called complete.");
            }
            this.f4659g = true;
            Iterator it = this.f4656d.iterator();
            while (it.hasNext()) {
                ((Runnable) it.next()).run();
            }
        }

        public final void d(androidx.core.os.d dVar) {
            if (this.f4657e.remove(dVar) && this.f4657e.isEmpty()) {
                c();
            }
        }

        public c e() {
            return this.f4653a;
        }

        public final f f() {
            return this.f4655c;
        }

        b g() {
            return this.f4654b;
        }

        final boolean h() {
            return this.f4658f;
        }

        final boolean i() {
            return this.f4659g;
        }

        public final void j(androidx.core.os.d dVar) {
            l();
            this.f4657e.add(dVar);
        }

        final void k(c cVar, b bVar) {
            int i10 = c.f4651b[bVar.ordinal()];
            if (i10 == 1) {
                if (this.f4653a == c.REMOVED) {
                    if (z.N0(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.f4655c + " mFinalState = REMOVED -> VISIBLE. mLifecycleImpact = " + this.f4654b + " to ADDING.");
                    }
                    this.f4653a = c.VISIBLE;
                    this.f4654b = b.ADDING;
                    return;
                }
                return;
            }
            if (i10 == 2) {
                if (z.N0(2)) {
                    Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.f4655c + " mFinalState = " + this.f4653a + " -> REMOVED. mLifecycleImpact  = " + this.f4654b + " to REMOVING.");
                }
                this.f4653a = c.REMOVED;
                this.f4654b = b.REMOVING;
                return;
            }
            if (i10 == 3 && this.f4653a != c.REMOVED) {
                if (z.N0(2)) {
                    Log.v("FragmentManager", "SpecialEffectsController: For fragment " + this.f4655c + " mFinalState = " + this.f4653a + " -> " + cVar + ". ");
                }
                this.f4653a = cVar;
            }
        }

        abstract void l();

        public String toString() {
            return "Operation {" + Integer.toHexString(System.identityHashCode(this)) + "} {mFinalState = " + this.f4653a + "} {mLifecycleImpact = " + this.f4654b + "} {mFragment = " + this.f4655c + "}";
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* loaded from: classes.dex */
        public enum c {
            REMOVED,
            VISIBLE,
            GONE,
            INVISIBLE;

            /* JADX INFO: Access modifiers changed from: package-private */
            public static c from(View view) {
                if (view.getAlpha() == BitmapDescriptorFactory.HUE_RED && view.getVisibility() == 0) {
                    return INVISIBLE;
                }
                return from(view.getVisibility());
            }

            /* JADX INFO: Access modifiers changed from: package-private */
            public void applyState(View view) {
                int i10 = c.f4650a[ordinal()];
                if (i10 == 1) {
                    ViewGroup viewGroup = (ViewGroup) view.getParent();
                    if (viewGroup != null) {
                        if (z.N0(2)) {
                            Log.v("FragmentManager", "SpecialEffectsController: Removing view " + view + " from container " + viewGroup);
                        }
                        viewGroup.removeView(view);
                        return;
                    }
                    return;
                }
                if (i10 == 2) {
                    if (z.N0(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to VISIBLE");
                    }
                    view.setVisibility(0);
                    return;
                }
                if (i10 == 3) {
                    if (z.N0(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to GONE");
                    }
                    view.setVisibility(8);
                    return;
                }
                if (i10 != 4) {
                    return;
                }
                if (z.N0(2)) {
                    Log.v("FragmentManager", "SpecialEffectsController: Setting view " + view + " to INVISIBLE");
                }
                view.setVisibility(4);
            }

            /* JADX INFO: Access modifiers changed from: package-private */
            public static c from(int i10) {
                if (i10 == 0) {
                    return VISIBLE;
                }
                if (i10 == 4) {
                    return INVISIBLE;
                }
                if (i10 == 8) {
                    return GONE;
                }
                throw new IllegalArgumentException("Unknown visibility " + i10);
            }
        }
    }
}
