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 androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.strictmode.FragmentStrictMode$Flag;
import androidx.fragment.app.strictmode.FragmentTagUsageViolation;

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

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

    public p0(d1 d1Var) {
        this.f2542a = d1Var;
    }

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

    @Override // android.view.LayoutInflater.Factory2
    @Nullable
    public View onCreateView(@Nullable View view, @NonNull String str, @NonNull Context context, @NonNull AttributeSet attributeSet) {
        l1 l1VarF;
        boolean zEquals = FragmentContainerView.class.getName().equals(str);
        d1 d1Var = this.f2542a;
        if (zEquals) {
            return new FragmentContainerView(context, attributeSet, d1Var);
        }
        if (!"fragment".equals(str)) {
            return null;
        }
        String attributeValue = attributeSet.getAttributeValue(null, "class");
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, i1.c.Fragment);
        if (attributeValue == null) {
            attributeValue = typedArrayObtainStyledAttributes.getString(i1.c.Fragment_android_name);
        }
        int resourceId = typedArrayObtainStyledAttributes.getResourceId(i1.c.Fragment_android_id, -1);
        String string = typedArrayObtainStyledAttributes.getString(i1.c.Fragment_android_tag);
        typedArrayObtainStyledAttributes.recycle();
        if (attributeValue != null) {
            try {
                if (e0.class.isAssignableFrom(m0.b(context.getClassLoader(), attributeValue))) {
                    int id2 = view != null ? view.getId() : 0;
                    if (id2 == -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);
                    }
                    e0 e0VarFindFragmentById = resourceId != -1 ? d1Var.findFragmentById(resourceId) : null;
                    if (e0VarFindFragmentById == null && string != null) {
                        e0VarFindFragmentById = d1Var.findFragmentByTag(string);
                    }
                    if (e0VarFindFragmentById == null && id2 != -1) {
                        e0VarFindFragmentById = d1Var.findFragmentById(id2);
                    }
                    if (e0VarFindFragmentById == null) {
                        m0 m0VarD = d1Var.D();
                        context.getClassLoader();
                        e0VarFindFragmentById = m0VarD.a(attributeValue);
                        e0VarFindFragmentById.Q = true;
                        e0VarFindFragmentById.Z = resourceId != 0 ? resourceId : id2;
                        e0VarFindFragmentById.f2399a0 = id2;
                        e0VarFindFragmentById.f2401b0 = string;
                        e0VarFindFragmentById.R = true;
                        e0VarFindFragmentById.V = d1Var;
                        n0 n0Var = d1Var.f2388w;
                        e0VarFindFragmentById.W = n0Var;
                        e0VarFindFragmentById.onInflate(n0Var.f2531b, attributeSet, e0VarFindFragmentById.f2400b);
                        l1VarF = d1Var.a(e0VarFindFragmentById);
                        if (Log.isLoggable("FragmentManager", 2)) {
                            e0VarFindFragmentById.toString();
                            Integer.toHexString(resourceId);
                        }
                    } else {
                        if (e0VarFindFragmentById.R) {
                            throw new IllegalArgumentException(attributeSet.getPositionDescription() + ": Duplicate id 0x" + Integer.toHexString(resourceId) + ", tag " + string + ", or parent id 0x" + Integer.toHexString(id2) + " with another fragment for " + attributeValue);
                        }
                        e0VarFindFragmentById.R = true;
                        e0VarFindFragmentById.V = d1Var;
                        n0 n0Var2 = d1Var.f2388w;
                        e0VarFindFragmentById.W = n0Var2;
                        e0VarFindFragmentById.onInflate(n0Var2.f2531b, attributeSet, e0VarFindFragmentById.f2400b);
                        l1VarF = d1Var.f(e0VarFindFragmentById);
                        if (Log.isLoggable("FragmentManager", 2)) {
                            e0VarFindFragmentById.toString();
                            Integer.toHexString(resourceId);
                        }
                    }
                    ViewGroup viewGroup = (ViewGroup) view;
                    j1.a aVar = j1.b.f28545a;
                    FragmentTagUsageViolation fragmentTagUsageViolation = new FragmentTagUsageViolation(e0VarFindFragmentById, viewGroup);
                    j1.b.c(fragmentTagUsageViolation);
                    j1.a aVarA = j1.b.a(e0VarFindFragmentById);
                    if (aVarA.f28543a.contains(FragmentStrictMode$Flag.f2586d) && j1.b.e(aVarA, e0VarFindFragmentById.getClass(), FragmentTagUsageViolation.class)) {
                        j1.b.b(aVarA, fragmentTagUsageViolation);
                    }
                    e0VarFindFragmentById.f2417j0 = viewGroup;
                    l1VarF.k();
                    l1VarF.j();
                    View view2 = e0VarFindFragmentById.f2419k0;
                    if (view2 == null) {
                        throw new IllegalStateException(com.google.android.gms.measurement.internal.u1.k("Fragment ", attributeValue, " did not create a view."));
                    }
                    if (resourceId != 0) {
                        view2.setId(resourceId);
                    }
                    if (e0VarFindFragmentById.f2419k0.getTag() == null) {
                        e0VarFindFragmentById.f2419k0.setTag(string);
                    }
                    e0VarFindFragmentById.f2419k0.addOnAttachStateChangeListener(new o0(this, l1VarF));
                    return e0VarFindFragmentById.f2419k0;
                }
            } catch (ClassNotFoundException unused) {
            }
        }
        return null;
    }
}
