package androidx.fragment.app;

import I1.a;
import M.AbstractC0195z;
import M.J;
import M.b0;
import P6.g;
import android.animation.LayoutTransition;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.FrameLayout;
import com.martsnew.tv.R;
import g0.AbstractC0969a;
import h0.C1000H;
import h0.C1001a;
import h0.ComponentCallbacksC1023x;
import h0.P;
import h0.W;
import h0.X;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import y5.AbstractActivityC1764i;

/* JADX INFO: loaded from: classes.dex */
public final class FragmentContainerView extends FrameLayout {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final ArrayList f8154q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final ArrayList f8155r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public View.OnApplyWindowInsetsListener f8156s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public boolean f8157t;

    public FragmentContainerView(Context context) {
        super(context);
        this.f8154q = new ArrayList();
        this.f8155r = new ArrayList();
        this.f8157t = true;
    }

    public final void a(View view) {
        if (this.f8155r.contains(view)) {
            this.f8154q.add(view);
        }
    }

    @Override // android.view.ViewGroup
    public final void addView(View view, int i, ViewGroup.LayoutParams layoutParams) {
        g.e(view, "child");
        Object tag = view.getTag(R.id.fragment_container_view_tag);
        if ((tag instanceof ComponentCallbacksC1023x ? (ComponentCallbacksC1023x) tag : null) != null) {
            super.addView(view, i, layoutParams);
            return;
        }
        throw new IllegalStateException(("Views added to a FragmentContainerView must be associated with a Fragment. View " + view + " is not associated with a Fragment.").toString());
    }

    @Override // android.view.ViewGroup, android.view.View
    public final WindowInsets dispatchApplyWindowInsets(WindowInsets windowInsets) {
        b0 b0VarD;
        g.e(windowInsets, "insets");
        b0 b0VarD2 = b0.d(windowInsets, null);
        View.OnApplyWindowInsetsListener onApplyWindowInsetsListener = this.f8156s;
        if (onApplyWindowInsetsListener != null) {
            WindowInsets windowInsetsOnApplyWindowInsets = onApplyWindowInsetsListener.onApplyWindowInsets(this, windowInsets);
            g.d(windowInsetsOnApplyWindowInsets, "onApplyWindowInsetsListe…lyWindowInsets(v, insets)");
            b0VarD = b0.d(windowInsetsOnApplyWindowInsets, null);
        } else {
            Field field = J.f4065a;
            WindowInsets windowInsetsC = b0VarD2.c();
            if (windowInsetsC != null) {
                WindowInsets windowInsetsB = AbstractC0195z.b(this, windowInsetsC);
                if (!windowInsetsB.equals(windowInsetsC)) {
                    b0VarD2 = b0.d(windowInsetsB, this);
                }
            }
            b0VarD = b0VarD2;
        }
        if (!b0VarD.f4102a.j()) {
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                J.a(getChildAt(i), b0VarD);
            }
        }
        return windowInsets;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void dispatchDraw(Canvas canvas) {
        g.e(canvas, "canvas");
        if (this.f8157t) {
            ArrayList arrayList = this.f8154q;
            int size = arrayList.size();
            int i = 0;
            while (i < size) {
                Object obj = arrayList.get(i);
                i++;
                super.drawChild(canvas, (View) obj, getDrawingTime());
            }
        }
        super.dispatchDraw(canvas);
    }

    @Override // android.view.ViewGroup
    public final boolean drawChild(Canvas canvas, View view, long j8) {
        g.e(canvas, "canvas");
        g.e(view, "child");
        if (this.f8157t) {
            ArrayList arrayList = this.f8154q;
            if (!arrayList.isEmpty() && arrayList.contains(view)) {
                return false;
            }
        }
        return super.drawChild(canvas, view, j8);
    }

    @Override // android.view.ViewGroup
    public final void endViewTransition(View view) {
        g.e(view, "view");
        this.f8155r.remove(view);
        if (this.f8154q.remove(view)) {
            this.f8157t = true;
        }
        super.endViewTransition(view);
    }

    public final <F extends ComponentCallbacksC1023x> F getFragment() {
        AbstractActivityC1764i abstractActivityC1764i;
        ComponentCallbacksC1023x componentCallbacksC1023x;
        P pO;
        View view = this;
        while (true) {
            abstractActivityC1764i = null;
            if (view == null) {
                componentCallbacksC1023x = null;
                break;
            }
            Object tag = view.getTag(R.id.fragment_container_view_tag);
            componentCallbacksC1023x = tag instanceof ComponentCallbacksC1023x ? (ComponentCallbacksC1023x) tag : null;
            if (componentCallbacksC1023x != null) {
                break;
            }
            Object parent = view.getParent();
            view = parent instanceof View ? (View) parent : null;
        }
        if (componentCallbacksC1023x == null) {
            Context context = getContext();
            while (true) {
                if (!(context instanceof ContextWrapper)) {
                    break;
                }
                if (context instanceof AbstractActivityC1764i) {
                    abstractActivityC1764i = (AbstractActivityC1764i) context;
                    break;
                }
                context = ((ContextWrapper) context).getBaseContext();
            }
            if (abstractActivityC1764i == null) {
                throw new IllegalStateException("View " + this + " is not within a subclass of FragmentActivity.");
            }
            pO = abstractActivityC1764i.O();
        } else {
            if (componentCallbacksC1023x.f13266L == null || !componentCallbacksC1023x.f13257A) {
                throw new IllegalStateException("The Fragment " + componentCallbacksC1023x + " that owns View " + this + " has already been destroyed. Nested fragments should always use the child FragmentManager.");
            }
            pO = componentCallbacksC1023x.n();
        }
        return (F) pO.C(getId());
    }

    @Override // android.view.View
    public final WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
        g.e(windowInsets, "insets");
        return windowInsets;
    }

    @Override // android.view.ViewGroup
    public final void removeAllViewsInLayout() {
        int childCount = getChildCount();
        while (true) {
            childCount--;
            if (-1 >= childCount) {
                super.removeAllViewsInLayout();
                return;
            } else {
                View childAt = getChildAt(childCount);
                g.d(childAt, "view");
                a(childAt);
            }
        }
    }

    @Override // android.view.ViewGroup, android.view.ViewManager
    public final void removeView(View view) {
        g.e(view, "view");
        a(view);
        super.removeView(view);
    }

    @Override // android.view.ViewGroup
    public final void removeViewAt(int i) {
        View childAt = getChildAt(i);
        g.d(childAt, "view");
        a(childAt);
        super.removeViewAt(i);
    }

    @Override // android.view.ViewGroup
    public final void removeViewInLayout(View view) {
        g.e(view, "view");
        a(view);
        super.removeViewInLayout(view);
    }

    @Override // android.view.ViewGroup
    public final void removeViews(int i, int i5) {
        int i8 = i + i5;
        for (int i9 = i; i9 < i8; i9++) {
            View childAt = getChildAt(i9);
            g.d(childAt, "view");
            a(childAt);
        }
        super.removeViews(i, i5);
    }

    @Override // android.view.ViewGroup
    public final void removeViewsInLayout(int i, int i5) {
        int i8 = i + i5;
        for (int i9 = i; i9 < i8; i9++) {
            View childAt = getChildAt(i9);
            g.d(childAt, "view");
            a(childAt);
        }
        super.removeViewsInLayout(i, i5);
    }

    public final void setDrawDisappearingViewsLast(boolean z8) {
        this.f8157t = z8;
    }

    @Override // android.view.ViewGroup
    public void setLayoutTransition(LayoutTransition layoutTransition) {
        throw new UnsupportedOperationException("FragmentContainerView does not support Layout Transitions or animateLayoutChanges=\"true\".");
    }

    @Override // android.view.View
    public void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener onApplyWindowInsetsListener) {
        this.f8156s = onApplyWindowInsetsListener;
    }

    @Override // android.view.ViewGroup
    public final void startViewTransition(View view) {
        g.e(view, "view");
        if (view.getParent() == this) {
            this.f8155r.add(view);
        }
        super.startViewTransition(view);
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public FragmentContainerView(Context context, AttributeSet attributeSet) {
        String str;
        super(context, attributeSet, 0);
        g.e(context, "context");
        this.f8154q = new ArrayList();
        this.f8155r = new ArrayList();
        this.f8157t = true;
        if (attributeSet != null) {
            String classAttribute = attributeSet.getClassAttribute();
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC0969a.f12873b, 0, 0);
            if (classAttribute == null) {
                classAttribute = typedArrayObtainStyledAttributes.getString(0);
                str = "android:name";
            } else {
                str = "class";
            }
            typedArrayObtainStyledAttributes.recycle();
            if (classAttribute == null || isInEditMode()) {
                return;
            }
            throw new UnsupportedOperationException("FragmentContainerView must be within a FragmentActivity to use " + str + "=\"" + classAttribute + '\"');
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public FragmentContainerView(Context context, AttributeSet attributeSet, P p3) {
        View view;
        super(context, attributeSet);
        g.e(context, "context");
        g.e(attributeSet, "attrs");
        g.e(p3, "fm");
        this.f8154q = new ArrayList();
        this.f8155r = new ArrayList();
        this.f8157t = true;
        String classAttribute = attributeSet.getClassAttribute();
        int i = 0;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC0969a.f12873b, 0, 0);
        classAttribute = classAttribute == null ? typedArrayObtainStyledAttributes.getString(0) : classAttribute;
        String string = typedArrayObtainStyledAttributes.getString(1);
        typedArrayObtainStyledAttributes.recycle();
        int id = getId();
        ComponentCallbacksC1023x componentCallbacksC1023xC = p3.C(id);
        if (classAttribute != null && componentCallbacksC1023xC == null) {
            if (id == -1) {
                throw new IllegalStateException(a.p("FragmentContainerView must have an android:id to add Fragment ", classAttribute, string != null ? " with tag ".concat(string) : ""));
            }
            C1000H c1000hI = p3.I();
            context.getClassLoader();
            ComponentCallbacksC1023x componentCallbacksC1023xA = c1000hI.a(classAttribute);
            g.d(componentCallbacksC1023xA, "fm.fragmentFactory.insta…ontext.classLoader, name)");
            componentCallbacksC1023xA.f13269O = id;
            componentCallbacksC1023xA.f13270P = id;
            componentCallbacksC1023xA.f13271Q = string;
            componentCallbacksC1023xA.f13265K = p3;
            componentCallbacksC1023xA.f13266L = p3.f13088w;
            componentCallbacksC1023xA.N(context, attributeSet, null);
            C1001a c1001a = new C1001a(p3);
            c1001a.f13158p = true;
            componentCallbacksC1023xA.f13277W = this;
            componentCallbacksC1023xA.f13262G = true;
            c1001a.h(getId(), componentCallbacksC1023xA, string, 1);
            if (!c1001a.f13150g) {
                c1001a.f13151h = false;
                P p4 = c1001a.f13160r;
                if (p4.f13088w != null && !p4.f13060J) {
                    p4.y(true);
                    C1001a c1001a2 = p4.f13074h;
                    if (c1001a2 != null) {
                        c1001a2.f13161s = false;
                        c1001a2.e();
                        if (P.L(3)) {
                            Log.d("FragmentManager", "Reversing mTransitioningOp " + p4.f13074h + " as part of execSingleAction for action " + c1001a);
                        }
                        p4.f13074h.g(false, false);
                        p4.f13074h.a(p4.f13062L, p4.f13063M);
                        ArrayList arrayList = p4.f13074h.f13144a;
                        int size = arrayList.size();
                        int i5 = 0;
                        while (i5 < size) {
                            Object obj = arrayList.get(i5);
                            i5++;
                            ComponentCallbacksC1023x componentCallbacksC1023x = ((X) obj).f13129b;
                            if (componentCallbacksC1023x != null) {
                                componentCallbacksC1023x.f13259C = false;
                            }
                        }
                        p4.f13074h = null;
                    }
                    c1001a.a(p4.f13062L, p4.f13063M);
                    p4.f13068b = true;
                    try {
                        p4.X(p4.f13062L, p4.f13063M);
                        p4.d();
                        p4.i0();
                        if (p4.f13061K) {
                            p4.f13061K = false;
                            p4.g0();
                        }
                        ((HashMap) p4.f13069c.f1158s).values().removeAll(Collections.singleton(null));
                    } catch (Throwable th) {
                        p4.d();
                        throw th;
                    }
                }
            } else {
                throw new IllegalStateException("This transaction is already being added to the back stack");
            }
        }
        ArrayList arrayListQ = p3.f13069c.q();
        int size2 = arrayListQ.size();
        while (i < size2) {
            Object obj2 = arrayListQ.get(i);
            i++;
            W w4 = (W) obj2;
            ComponentCallbacksC1023x componentCallbacksC1023x2 = w4.f13125c;
            if (componentCallbacksC1023x2.f13270P == getId() && (view = componentCallbacksC1023x2.X) != null && view.getParent() == null) {
                componentCallbacksC1023x2.f13277W = this;
                w4.b();
                w4.k();
            }
        }
    }
}
