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: compiled from: FragmentLayoutInflaterFactory.java */
/* JADX INFO: loaded from: classes.dex */
class k implements LayoutInflater.Factory2 {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final m f771b;

    k(m mVar) {
        this.f771b = mVar;
    }

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

    @Override // android.view.LayoutInflater.Factory2
    public View onCreateView(View view, String str, Context context, AttributeSet attributeSet) {
        t tVarV;
        if (g.class.getName().equals(str)) {
            return new g(context, attributeSet, this.f771b);
        }
        if (!"fragment".equals(str)) {
            return null;
        }
        String attributeValue = attributeSet.getAttributeValue(null, "class");
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, c.i.c.Fragment);
        if (attributeValue == null) {
            attributeValue = typedArrayObtainStyledAttributes.getString(c.i.c.Fragment_android_name);
        }
        int resourceId = typedArrayObtainStyledAttributes.getResourceId(c.i.c.Fragment_android_id, -1);
        String string = typedArrayObtainStyledAttributes.getString(c.i.c.Fragment_android_tag);
        typedArrayObtainStyledAttributes.recycle();
        if (attributeValue == null || !i.b(context.getClassLoader(), attributeValue)) {
            return null;
        }
        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);
        }
        Fragment fragmentG0 = resourceId != -1 ? this.f771b.g0(resourceId) : null;
        if (fragmentG0 == null && string != null) {
            fragmentG0 = this.f771b.h0(string);
        }
        if (fragmentG0 == null && id != -1) {
            fragmentG0 = this.f771b.g0(id);
        }
        if (fragmentG0 == null) {
            fragmentG0 = this.f771b.p0().a(context.getClassLoader(), attributeValue);
            fragmentG0.r = true;
            fragmentG0.A = resourceId != 0 ? resourceId : id;
            fragmentG0.B = id;
            fragmentG0.C = string;
            fragmentG0.s = true;
            m mVar = this.f771b;
            fragmentG0.w = mVar;
            fragmentG0.x = mVar.s0();
            fragmentG0.v0(this.f771b.s0().k(), attributeSet, fragmentG0.f673f);
            tVarV = this.f771b.v(fragmentG0);
            this.f771b.g(fragmentG0);
            if (m.D0(2)) {
                Log.v("FragmentManager", "Fragment " + fragmentG0 + " has been inflated via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
            }
        } else {
            if (fragmentG0.s) {
                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);
            }
            fragmentG0.s = true;
            m mVar2 = this.f771b;
            fragmentG0.w = mVar2;
            fragmentG0.x = mVar2.s0();
            fragmentG0.v0(this.f771b.s0().k(), attributeSet, fragmentG0.f673f);
            tVarV = this.f771b.v(fragmentG0);
            if (m.D0(2)) {
                Log.v("FragmentManager", "Retained Fragment " + fragmentG0 + " has been re-attached via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
            }
        }
        fragmentG0.K = (ViewGroup) view;
        tVarV.m();
        tVarV.j();
        View view2 = fragmentG0.L;
        if (view2 != null) {
            if (resourceId != 0) {
                view2.setId(resourceId);
            }
            if (fragmentG0.L.getTag() == null) {
                fragmentG0.L.setTag(string);
            }
            return fragmentG0.L;
        }
        throw new IllegalStateException("Fragment " + attributeValue + " did not create a view.");
    }
}
