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;
import f0.AbstractC0589a;
import g0.C0611a;
import p0.AbstractC0928a;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final h0 f4201k;

    public V(h0 h0Var) {
        this.f4201k = h0Var;
    }

    @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;
        p0 p0VarG;
        boolean zEquals = FragmentContainerView.class.getName().equals(str);
        h0 h0Var = this.f4201k;
        if (zEquals) {
            return new FragmentContainerView(context, attributeSet, h0Var);
        }
        if ("fragment".equals(str)) {
            String attributeValue = attributeSet.getAttributeValue(null, "class");
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC0589a.f6336a);
            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 = I.class.isAssignableFrom(C0263a0.a(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);
                    }
                    I iB = resourceId != -1 ? h0Var.B(resourceId) : null;
                    if (iB == null && string != null) {
                        iB = h0Var.C(string);
                    }
                    if (iB == null && id != -1) {
                        iB = h0Var.B(id);
                    }
                    if (iB == null) {
                        C0263a0 c0263a0G = h0Var.G();
                        context.getClassLoader();
                        iB = I.instantiate(c0263a0G.f4224a.f4293v.f4196l, attributeValue, null);
                        iB.mFromLayout = true;
                        iB.mFragmentId = resourceId != 0 ? resourceId : id;
                        iB.mContainerId = id;
                        iB.mTag = string;
                        iB.mInLayout = true;
                        iB.mFragmentManager = h0Var;
                        T t4 = h0Var.f4293v;
                        iB.mHost = t4;
                        iB.onInflate((Context) t4.f4196l, attributeSet, iB.mSavedFragmentState);
                        p0VarG = h0Var.a(iB);
                        if (h0.J(2)) {
                            Log.v("FragmentManager", "Fragment " + iB + " has been inflated via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
                        }
                    } else {
                        if (iB.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);
                        }
                        iB.mInLayout = true;
                        iB.mFragmentManager = h0Var;
                        T t5 = h0Var.f4293v;
                        iB.mHost = t5;
                        iB.onInflate((Context) t5.f4196l, attributeSet, iB.mSavedFragmentState);
                        p0VarG = h0Var.g(iB);
                        if (h0.J(2)) {
                            Log.v("FragmentManager", "Retained Fragment " + iB + " has been re-attached via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
                        }
                    }
                    ViewGroup viewGroup = (ViewGroup) view;
                    g0.c cVar = g0.d.f6417a;
                    g0.d.b(new C0611a(iB, "Attempting to use <fragment> tag to add fragment " + iB + " to container " + viewGroup));
                    g0.d.a(iB).getClass();
                    iB.mContainer = viewGroup;
                    p0VarG.k();
                    p0VarG.j();
                    View view2 = iB.mView;
                    if (view2 == null) {
                        throw new IllegalStateException(AbstractC0928a.l("Fragment ", attributeValue, " did not create a view."));
                    }
                    if (resourceId != 0) {
                        view2.setId(resourceId);
                    }
                    if (iB.mView.getTag() == null) {
                        iB.mView.setTag(string);
                    }
                    iB.mView.addOnAttachStateChangeListener(new U(this, p0VarG));
                    return iB.mView;
                }
            }
        }
        return null;
    }
}
