package androidx.fragment.app;

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;

/* JADX INFO: loaded from: classes.dex */
public final class U implements LayoutInflater.Factory2 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final AbstractC1050g0 f11545a;

    public U(AbstractC1050g0 abstractC1050g0) {
        this.f11545a = abstractC1050g0;
    }

    @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;
        o0 o0VarF;
        boolean zEquals = P.class.getName().equals(str);
        AbstractC1050g0 abstractC1050g0 = this.f11545a;
        if (zEquals) {
            return new P(context, attributeSet, abstractC1050g0);
        }
        if ("fragment".equals(str)) {
            String attributeValue = attributeSet.getAttributeValue(null, "class");
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, W1.a.f8422a);
            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 = G.class.isAssignableFrom(Z.a(attributeValue, context.getClassLoader()));
                } 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);
                    }
                    G gA = resourceId != -1 ? abstractC1050g0.A(resourceId) : null;
                    if (gA == null && string != null) {
                        gA = abstractC1050g0.B(string);
                    }
                    if (gA == null && id != -1) {
                        gA = abstractC1050g0.A(id);
                    }
                    if (gA == null) {
                        Z zE = abstractC1050g0.E();
                        context.getClassLoader();
                        gA = G.instantiate(zE.f11554a.f11623u.f11540b, attributeValue, null);
                        gA.mFromLayout = true;
                        gA.mFragmentId = resourceId != 0 ? resourceId : id;
                        gA.mContainerId = id;
                        gA.mTag = string;
                        gA.mInLayout = true;
                        gA.mFragmentManager = abstractC1050g0;
                        S s6 = abstractC1050g0.f11623u;
                        gA.mHost = s6;
                        gA.onInflate((Context) s6.f11540b, attributeSet, gA.mSavedFragmentState);
                        o0VarF = abstractC1050g0.a(gA);
                        if (AbstractC1050g0.H(2)) {
                            Log.v("FragmentManager", "Fragment " + gA + " has been inflated via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
                        }
                    } else {
                        if (gA.mInLayout) {
                            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);
                        }
                        gA.mInLayout = true;
                        gA.mFragmentManager = abstractC1050g0;
                        S s7 = abstractC1050g0.f11623u;
                        gA.mHost = s7;
                        gA.onInflate((Context) s7.f11540b, attributeSet, gA.mSavedFragmentState);
                        o0VarF = abstractC1050g0.f(gA);
                        if (AbstractC1050g0.H(2)) {
                            Log.v("FragmentManager", "Retained Fragment " + gA + " has been re-attached via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
                        }
                    }
                    ViewGroup viewGroup = (ViewGroup) view;
                    X1.c cVar = X1.d.f8547a;
                    X1.d.b(new X1.a(gA, "Attempting to use <fragment> tag to add fragment " + gA + " to container " + viewGroup));
                    X1.d.a(gA).getClass();
                    gA.mContainer = viewGroup;
                    o0VarF.k();
                    o0VarF.j();
                    View view2 = gA.mView;
                    if (view2 == null) {
                        throw new IllegalStateException(Z0.o.o("Fragment ", attributeValue, " did not create a view."));
                    }
                    if (resourceId != 0) {
                        view2.setId(resourceId);
                    }
                    if (gA.mView.getTag() == null) {
                        gA.mView.setTag(string);
                    }
                    gA.mView.addOnAttachStateChangeListener(new T(this, o0VarF));
                    return gA.mView;
                }
            }
        }
        return null;
    }
}
