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: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class s implements LayoutInflater.Factory2 {

    /* renamed from: p, reason: collision with root package name */
    final z f4661p;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class a implements View.OnAttachStateChangeListener {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ h0 f4662p;

        a(h0 h0Var) {
            this.f4662p = h0Var;
        }

        @Override // android.view.View.OnAttachStateChangeListener
        public void onViewAttachedToWindow(View view) {
            f k10 = this.f4662p.k();
            this.f4662p.m();
            r0.n((ViewGroup) k10.mView.getParent(), s.this.f4661p).j();
        }

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

    /* JADX INFO: Access modifiers changed from: package-private */
    public s(z zVar) {
        this.f4661p = zVar;
    }

    @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) {
        h0 y10;
        if (FragmentContainerView.class.getName().equals(str)) {
            return new FragmentContainerView(context, attributeSet, this.f4661p);
        }
        if (!"fragment".equals(str)) {
            return null;
        }
        String attributeValue = attributeSet.getAttributeValue(null, "class");
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, l4.c.f27462a);
        if (attributeValue == null) {
            attributeValue = obtainStyledAttributes.getString(l4.c.f27463b);
        }
        int resourceId = obtainStyledAttributes.getResourceId(l4.c.f27464c, -1);
        String string = obtainStyledAttributes.getString(l4.c.f27465d);
        obtainStyledAttributes.recycle();
        if (attributeValue == null || !o.b(context.getClassLoader(), attributeValue)) {
            return null;
        }
        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);
        }
        f k02 = resourceId != -1 ? this.f4661p.k0(resourceId) : null;
        if (k02 == null && string != null) {
            k02 = this.f4661p.l0(string);
        }
        if (k02 == null && id2 != -1) {
            k02 = this.f4661p.k0(id2);
        }
        if (k02 == null) {
            k02 = this.f4661p.x0().a(context.getClassLoader(), attributeValue);
            k02.mFromLayout = true;
            k02.mFragmentId = resourceId != 0 ? resourceId : id2;
            k02.mContainerId = id2;
            k02.mTag = string;
            k02.mInLayout = true;
            z zVar = this.f4661p;
            k02.mFragmentManager = zVar;
            k02.mHost = zVar.A0();
            k02.onInflate(this.f4661p.A0().f(), attributeSet, k02.mSavedFragmentState);
            y10 = this.f4661p.j(k02);
            if (z.N0(2)) {
                Log.v("FragmentManager", "Fragment " + k02 + " has been inflated via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
            }
        } else if (!k02.mInLayout) {
            k02.mInLayout = true;
            z zVar2 = this.f4661p;
            k02.mFragmentManager = zVar2;
            k02.mHost = zVar2.A0();
            k02.onInflate(this.f4661p.A0().f(), attributeSet, k02.mSavedFragmentState);
            y10 = this.f4661p.y(k02);
            if (z.N0(2)) {
                Log.v("FragmentManager", "Retained Fragment " + k02 + " has been re-attached via the <fragment> tag: id=0x" + Integer.toHexString(resourceId));
            }
        } else {
            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);
        }
        ViewGroup viewGroup = (ViewGroup) view;
        m4.c.g(k02, viewGroup);
        k02.mContainer = viewGroup;
        y10.m();
        y10.j();
        View view2 = k02.mView;
        if (view2 != null) {
            if (resourceId != 0) {
                view2.setId(resourceId);
            }
            if (k02.mView.getTag() == null) {
                k02.mView.setTag(string);
            }
            k02.mView.addOnAttachStateChangeListener(new a(y10));
            return k02.mView;
        }
        throw new IllegalStateException("Fragment " + attributeValue + " did not create a view.");
    }
}
