package h0;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.FragmentContainerView;
import g0.AbstractC0969a;
import i0.AbstractC1048d;
import i0.C1045a;
import i0.C1047c;

/* JADX INFO: renamed from: h0.C, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class LayoutInflaterFactory2C0995C implements LayoutInflater.Factory2 {

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

    public LayoutInflaterFactory2C0995C(P p3) {
        this.f13033q = p3;
    }

    @Override // android.view.LayoutInflater.Factory
    public final View onCreateView(String str, Context context, AttributeSet attributeSet) {
        return onCreateView(null, str, context, attributeSet);
    }

    @Override // android.view.LayoutInflater.Factory2
    public final View onCreateView(View view, String str, Context context, AttributeSet attributeSet) {
        boolean zIsAssignableFrom;
        W wG;
        boolean zEquals = FragmentContainerView.class.getName().equals(str);
        P p3 = this.f13033q;
        if (zEquals) {
            return new FragmentContainerView(context, attributeSet, p3);
        }
        if ("fragment".equals(str)) {
            String attributeValue = attributeSet.getAttributeValue(null, "class");
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC0969a.f12872a);
            if (attributeValue == null) {
                attributeValue = typedArrayObtainStyledAttributes.getString(0);
            }
            int resourceId = typedArrayObtainStyledAttributes.getResourceId(1, -1);
            String string = typedArrayObtainStyledAttributes.getString(2);
            typedArrayObtainStyledAttributes.recycle();
            if (attributeValue != null) {
                try {
                    zIsAssignableFrom = ComponentCallbacksC1023x.class.isAssignableFrom(C1000H.b(context.getClassLoader(), attributeValue));
                } catch (ClassNotFoundException unused) {
                    zIsAssignableFrom = false;
                }
                if (zIsAssignableFrom) {
                    int id = view != null ? view.getId() : 0;
                    if (id == -1 && resourceId == -1 && string == null) {
                        throw new IllegalArgumentException(attributeSet.getPositionDescription() + ": Must specify unique android:id, android:tag, or have a parent with an id for " + attributeValue);
                    }
                    ComponentCallbacksC1023x componentCallbacksC1023xC = resourceId != -1 ? p3.C(resourceId) : null;
                    if (componentCallbacksC1023xC == null && string != null) {
                        componentCallbacksC1023xC = p3.D(string);
                    }
                    if (componentCallbacksC1023xC == null && id != -1) {
                        componentCallbacksC1023xC = p3.C(id);
                    }
                    if (componentCallbacksC1023xC == null) {
                        C1000H c1000hI = p3.I();
                        context.getClassLoader();
                        componentCallbacksC1023xC = c1000hI.a(attributeValue);
                        componentCallbacksC1023xC.f13260E = true;
                        componentCallbacksC1023xC.f13269O = resourceId != 0 ? resourceId : id;
                        componentCallbacksC1023xC.f13270P = id;
                        componentCallbacksC1023xC.f13271Q = string;
                        componentCallbacksC1023xC.f13261F = true;
                        componentCallbacksC1023xC.f13265K = p3;
                        C1025z c1025z = p3.f13088w;
                        componentCallbacksC1023xC.f13266L = c1025z;
                        componentCallbacksC1023xC.N(c1025z.f13306u, attributeSet, componentCallbacksC1023xC.f13294r);
                        wG = p3.a(componentCallbacksC1023xC);
                        if (P.L(2)) {
                            Log.v("FragmentManager", "Fragment " + componentCallbacksC1023xC + " has been inflated via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
                        }
                    } else {
                        if (componentCallbacksC1023xC.f13261F) {
                            throw new IllegalArgumentException(attributeSet.getPositionDescription() + ": Duplicate id 0x" + Integer.toHexString(resourceId) + ", tag " + string + ", or parent id 0x" + Integer.toHexString(id) + " with another fragment for " + attributeValue);
                        }
                        componentCallbacksC1023xC.f13261F = true;
                        componentCallbacksC1023xC.f13265K = p3;
                        C1025z c1025z2 = p3.f13088w;
                        componentCallbacksC1023xC.f13266L = c1025z2;
                        componentCallbacksC1023xC.N(c1025z2.f13306u, attributeSet, componentCallbacksC1023xC.f13294r);
                        wG = p3.g(componentCallbacksC1023xC);
                        if (P.L(2)) {
                            Log.v("FragmentManager", "Retained Fragment " + componentCallbacksC1023xC + " has been re-attached via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
                        }
                    }
                    ViewGroup viewGroup = (ViewGroup) view;
                    C1047c c1047c = AbstractC1048d.f13482a;
                    AbstractC1048d.b(new C1045a(componentCallbacksC1023xC, "Attempting to use <fragment> tag to add fragment " + componentCallbacksC1023xC + " to container " + viewGroup));
                    AbstractC1048d.a(componentCallbacksC1023xC).getClass();
                    componentCallbacksC1023xC.f13277W = viewGroup;
                    wG.k();
                    wG.j();
                    View view2 = componentCallbacksC1023xC.X;
                    if (view2 == null) {
                        throw new IllegalStateException(I1.a.p("Fragment ", attributeValue, " did not create a view."));
                    }
                    if (resourceId != 0) {
                        view2.setId(resourceId);
                    }
                    if (componentCallbacksC1023xC.X.getTag() == null) {
                        componentCallbacksC1023xC.X.setTag(string);
                    }
                    componentCallbacksC1023xC.X.addOnAttachStateChangeListener(new ViewOnAttachStateChangeListenerC0994B(this, wG));
                    return componentCallbacksC1023xC.X;
                }
            }
        }
        return null;
    }
}
