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: e, reason: collision with root package name */
    final m f2324e;

    /* JADX INFO: compiled from: FragmentLayoutInflaterFactory.java */
    class a implements View.OnAttachStateChangeListener {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        final /* synthetic */ t f2325e;

        a(t tVar) {
            this.f2325e = tVar;
        }

        @Override // android.view.View.OnAttachStateChangeListener
        public void onViewAttachedToWindow(View view) {
            Fragment fragmentK = this.f2325e.k();
            this.f2325e.m();
            b0.n((ViewGroup) fragmentK.L.getParent(), k.this.f2324e).j();
        }

        @Override // android.view.View.OnAttachStateChangeListener
        public void onViewDetachedFromWindow(View view) {
        }
    }

    k(m mVar) {
        this.f2324e = 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 (FragmentContainerView.class.getName().equals(str)) {
            return new FragmentContainerView(context, attributeSet, this.f2324e);
        }
        if (!"fragment".equals(str)) {
            return null;
        }
        String attributeValue = attributeSet.getAttributeValue(null, "class");
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, a0.c.f11a);
        if (attributeValue == null) {
            attributeValue = typedArrayObtainStyledAttributes.getString(a0.c.f12b);
        }
        int resourceId = typedArrayObtainStyledAttributes.getResourceId(a0.c.f13c, -1);
        String string = typedArrayObtainStyledAttributes.getString(a0.c.f14d);
        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.f2324e.g0(resourceId) : null;
        if (fragmentG0 == null && string != null) {
            fragmentG0 = this.f2324e.h0(string);
        }
        if (fragmentG0 == null && id != -1) {
            fragmentG0 = this.f2324e.g0(id);
        }
        if (fragmentG0 == null) {
            fragmentG0 = this.f2324e.p0().a(context.getClassLoader(), attributeValue);
            fragmentG0.f2150r = true;
            fragmentG0.A = resourceId != 0 ? resourceId : id;
            fragmentG0.B = id;
            fragmentG0.C = string;
            fragmentG0.f2151s = true;
            m mVar = this.f2324e;
            fragmentG0.f2155w = mVar;
            fragmentG0.f2156x = mVar.s0();
            fragmentG0.x0(this.f2324e.s0().k(), attributeSet, fragmentG0.f2138f);
            tVarV = this.f2324e.g(fragmentG0);
            if (m.E0(2)) {
                Log.v("FragmentManager", "Fragment " + fragmentG0 + " has been inflated via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
            }
        } else {
            if (fragmentG0.f2151s) {
                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.f2151s = true;
            m mVar2 = this.f2324e;
            fragmentG0.f2155w = mVar2;
            fragmentG0.f2156x = mVar2.s0();
            fragmentG0.x0(this.f2324e.s0().k(), attributeSet, fragmentG0.f2138f);
            tVarV = this.f2324e.v(fragmentG0);
            if (m.E0(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) {
            throw new IllegalStateException("Fragment " + attributeValue + " did not create a view.");
        }
        if (resourceId != 0) {
            view2.setId(resourceId);
        }
        if (fragmentG0.L.getTag() == null) {
            fragmentG0.L.setTag(string);
        }
        fragmentG0.L.addOnAttachStateChangeListener(new a(tVarV));
        return fragmentG0.L;
    }
}
