package c.k.b;

import android.animation.LayoutTransition;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.FrameLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.ifpdos.debugmenu.R;
import java.util.ArrayList;

/* JADX INFO: compiled from: FragmentContainerView.java */
/* JADX INFO: loaded from: classes.dex */
public final class s extends FrameLayout {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public ArrayList<View> f1735b;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public ArrayList<View> f1736e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public View.OnApplyWindowInsetsListener f1737f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f1738g;

    public s(Context context, AttributeSet attributeSet, FragmentManager fragmentManager) {
        View view;
        super(context, attributeSet);
        this.f1738g = true;
        String classAttribute = attributeSet.getClassAttribute();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, c.k.a.f1588b);
        classAttribute = classAttribute == null ? typedArrayObtainStyledAttributes.getString(0) : classAttribute;
        String string = typedArrayObtainStyledAttributes.getString(1);
        typedArrayObtainStyledAttributes.recycle();
        int id = getId();
        Fragment fragmentH = fragmentManager.H(id);
        if (classAttribute != null && fragmentH == null) {
            if (id <= 0) {
                throw new IllegalStateException(d.b.a.a.a.q("FragmentContainerView must have an android:id to add Fragment ", classAttribute, string != null ? d.b.a.a.a.p(" with tag ", string) : ""));
            }
            Fragment fragmentA = fragmentManager.J().a(context.getClassLoader(), classAttribute);
            fragmentA.onInflate(context, attributeSet, (Bundle) null);
            a aVar = new a(fragmentManager);
            aVar.o = true;
            fragmentA.mContainer = this;
            aVar.d(getId(), fragmentA, string, 1);
            if (aVar.f1615g) {
                throw new IllegalStateException("This transaction is already being added to the back stack");
            }
            aVar.p.D(aVar, true);
        }
        for (b0 b0Var : (ArrayList) fragmentManager.f336c.f()) {
            Fragment fragment = b0Var.f1600c;
            if (fragment.mContainerId == getId() && (view = fragment.mView) != null && view.getParent() == null) {
                fragment.mContainer = this;
                b0Var.b();
            }
        }
    }

    public final void a(View view) {
        ArrayList<View> arrayList = this.f1736e;
        if (arrayList == null || !arrayList.contains(view)) {
            return;
        }
        if (this.f1735b == null) {
            this.f1735b = new ArrayList<>();
        }
        this.f1735b.add(view);
    }

    @Override // android.view.ViewGroup
    public void addView(View view, int i2, ViewGroup.LayoutParams layoutParams) {
        Object tag = view.getTag(R.id.fragment_container_view_tag);
        if ((tag instanceof Fragment ? (Fragment) tag : null) != null) {
            super.addView(view, i2, layoutParams);
            return;
        }
        throw new IllegalStateException("Views added to a FragmentContainerView must be associated with a Fragment. View " + view + " is not associated with a Fragment.");
    }

    @Override // android.view.ViewGroup
    public boolean addViewInLayout(View view, int i2, ViewGroup.LayoutParams layoutParams, boolean z) {
        Object tag = view.getTag(R.id.fragment_container_view_tag);
        if ((tag instanceof Fragment ? (Fragment) tag : null) != null) {
            return super.addViewInLayout(view, i2, layoutParams, z);
        }
        throw new IllegalStateException("Views added to a FragmentContainerView must be associated with a Fragment. View " + view + " is not associated with a Fragment.");
    }

    @Override // android.view.ViewGroup, android.view.View
    public WindowInsets dispatchApplyWindowInsets(WindowInsets windowInsets) {
        c.f.j.m0 m0VarH = c.f.j.m0.h(windowInsets, null);
        View.OnApplyWindowInsetsListener onApplyWindowInsetsListener = this.f1737f;
        c.f.j.m0 m0VarG = onApplyWindowInsetsListener != null ? c.f.j.m0.g(onApplyWindowInsetsListener.onApplyWindowInsets(this, windowInsets)) : c.f.j.a0.i(this, m0VarH);
        if (!m0VarG.f1438b.i()) {
            int childCount = getChildCount();
            for (int i2 = 0; i2 < childCount; i2++) {
                c.f.j.a0.b(getChildAt(i2), m0VarG);
            }
        }
        return windowInsets;
    }

    @Override // android.view.ViewGroup, android.view.View
    public void dispatchDraw(Canvas canvas) {
        if (this.f1738g && this.f1735b != null) {
            for (int i2 = 0; i2 < this.f1735b.size(); i2++) {
                super.drawChild(canvas, this.f1735b.get(i2), getDrawingTime());
            }
        }
        super.dispatchDraw(canvas);
    }

    @Override // android.view.ViewGroup
    public boolean drawChild(Canvas canvas, View view, long j2) {
        ArrayList<View> arrayList;
        if (!this.f1738g || (arrayList = this.f1735b) == null || arrayList.size() <= 0 || !this.f1735b.contains(view)) {
            return super.drawChild(canvas, view, j2);
        }
        return false;
    }

    @Override // android.view.ViewGroup
    public void endViewTransition(View view) {
        ArrayList<View> arrayList = this.f1736e;
        if (arrayList != null) {
            arrayList.remove(view);
            ArrayList<View> arrayList2 = this.f1735b;
            if (arrayList2 != null && arrayList2.remove(view)) {
                this.f1738g = true;
            }
        }
        super.endViewTransition(view);
    }

    @Override // android.view.View
    public WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
        return windowInsets;
    }

    @Override // android.view.ViewGroup
    public void removeAllViewsInLayout() {
        for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) {
            a(getChildAt(childCount));
        }
        super.removeAllViewsInLayout();
    }

    @Override // android.view.ViewGroup
    public void removeDetachedView(View view, boolean z) {
        if (z) {
            a(view);
        }
        super.removeDetachedView(view, z);
    }

    @Override // android.view.ViewGroup, android.view.ViewManager
    public void removeView(View view) {
        a(view);
        super.removeView(view);
    }

    @Override // android.view.ViewGroup
    public void removeViewAt(int i2) {
        a(getChildAt(i2));
        super.removeViewAt(i2);
    }

    @Override // android.view.ViewGroup
    public void removeViewInLayout(View view) {
        a(view);
        super.removeViewInLayout(view);
    }

    @Override // android.view.ViewGroup
    public void removeViews(int i2, int i3) {
        for (int i4 = i2; i4 < i2 + i3; i4++) {
            a(getChildAt(i4));
        }
        super.removeViews(i2, i3);
    }

    @Override // android.view.ViewGroup
    public void removeViewsInLayout(int i2, int i3) {
        for (int i4 = i2; i4 < i2 + i3; i4++) {
            a(getChildAt(i4));
        }
        super.removeViewsInLayout(i2, i3);
    }

    public void setDrawDisappearingViewsLast(boolean z) {
        this.f1738g = z;
    }

    @Override // android.view.ViewGroup
    public void setLayoutTransition(LayoutTransition layoutTransition) {
        throw new UnsupportedOperationException("FragmentContainerView does not support Layout Transitions or animateLayoutChanges=\"true\".");
    }

    @Override // android.view.View
    public void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener onApplyWindowInsetsListener) {
        this.f1737f = onApplyWindowInsetsListener;
    }

    @Override // android.view.ViewGroup
    public void startViewTransition(View view) {
        if (view.getParent() == this) {
            if (this.f1736e == null) {
                this.f1736e = new ArrayList<>();
            }
            this.f1736e.add(view);
        }
        super.startViewTransition(view);
    }
}
