package androidx.fragment.app; 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.annotation.RequiresApi; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import androidx.fragment.R; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; /* loaded from: classes.dex */ public final class FragmentContainerView extends FrameLayout { private View.OnApplyWindowInsetsListener applyWindowInsetsListener; private final List disappearingFragmentChildren; private boolean drawDisappearingViewsFirst; private final List transitioningFragmentViews; /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */ public FragmentContainerView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0, 4, null); Intrinsics.checkNotNullParameter(context, "context"); } @Override // android.view.View @RequiresApi(20) public WindowInsets onApplyWindowInsets(WindowInsets insets) { Intrinsics.checkNotNullParameter(insets, "insets"); return insets; } public final void setDrawDisappearingViewsLast(boolean z) { this.drawDisappearingViewsFirst = z; } @Override // android.view.View public void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener) { Intrinsics.checkNotNullParameter(listener, "listener"); this.applyWindowInsetsListener = listener; } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public FragmentContainerView(Context context) { super(context); Intrinsics.checkNotNullParameter(context, "context"); this.disappearingFragmentChildren = new ArrayList(); this.transitioningFragmentViews = new ArrayList(); this.drawDisappearingViewsFirst = true; } public /* synthetic */ FragmentContainerView(Context context, AttributeSet attributeSet, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) { this(context, attributeSet, (i2 & 4) != 0 ? 0 : i); } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public FragmentContainerView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); String str; Intrinsics.checkNotNullParameter(context, "context"); this.disappearingFragmentChildren = new ArrayList(); this.transitioningFragmentViews = new ArrayList(); this.drawDisappearingViewsFirst = true; if (attributeSet != null) { String classAttribute = attributeSet.getClassAttribute(); int[] FragmentContainerView = R.styleable.FragmentContainerView; Intrinsics.checkNotNullExpressionValue(FragmentContainerView, "FragmentContainerView"); TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, FragmentContainerView, 0, 0); if (classAttribute == null) { classAttribute = obtainStyledAttributes.getString(R.styleable.FragmentContainerView_android_name); str = "android:name"; } else { str = "class"; } obtainStyledAttributes.recycle(); if (classAttribute == null || isInEditMode()) { return; } throw new UnsupportedOperationException("FragmentContainerView must be within a FragmentActivity to use " + str + "=\"" + classAttribute + '\"'); } } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public FragmentContainerView(Context context, AttributeSet attrs, FragmentManager fm) { super(context, attrs); String str; Intrinsics.checkNotNullParameter(context, "context"); Intrinsics.checkNotNullParameter(attrs, "attrs"); Intrinsics.checkNotNullParameter(fm, "fm"); this.disappearingFragmentChildren = new ArrayList(); this.transitioningFragmentViews = new ArrayList(); this.drawDisappearingViewsFirst = true; String classAttribute = attrs.getClassAttribute(); int[] FragmentContainerView = R.styleable.FragmentContainerView; Intrinsics.checkNotNullExpressionValue(FragmentContainerView, "FragmentContainerView"); TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attrs, FragmentContainerView, 0, 0); classAttribute = classAttribute == null ? obtainStyledAttributes.getString(R.styleable.FragmentContainerView_android_name) : classAttribute; String string = obtainStyledAttributes.getString(R.styleable.FragmentContainerView_android_tag); obtainStyledAttributes.recycle(); int id = getId(); Fragment findFragmentById = fm.findFragmentById(id); if (classAttribute != null && findFragmentById == null) { if (id == -1) { if (string != null) { str = " with tag " + string; } else { str = ""; } throw new IllegalStateException("FragmentContainerView must have an android:id to add Fragment " + classAttribute + str); } Fragment instantiate = fm.getFragmentFactory().instantiate(context.getClassLoader(), classAttribute); Intrinsics.checkNotNullExpressionValue(instantiate, "fm.fragmentFactory.insta…ontext.classLoader, name)"); instantiate.onInflate(context, attrs, (Bundle) null); fm.beginTransaction().setReorderingAllowed(true).add(this, instantiate, string).commitNowAllowingStateLoss(); } fm.onContainerAvailable(this); } @Override // android.view.ViewGroup public void setLayoutTransition(LayoutTransition layoutTransition) { throw new UnsupportedOperationException("FragmentContainerView does not support Layout Transitions or animateLayoutChanges=\"true\"."); } @Override // android.view.ViewGroup, android.view.View @RequiresApi(20) public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { WindowInsetsCompat onApplyWindowInsets; Intrinsics.checkNotNullParameter(insets, "insets"); WindowInsetsCompat windowInsetsCompat = WindowInsetsCompat.toWindowInsetsCompat(insets); Intrinsics.checkNotNullExpressionValue(windowInsetsCompat, "toWindowInsetsCompat(insets)"); View.OnApplyWindowInsetsListener onApplyWindowInsetsListener = this.applyWindowInsetsListener; if (onApplyWindowInsetsListener != null) { Api20Impl api20Impl = Api20Impl.INSTANCE; Intrinsics.checkNotNull(onApplyWindowInsetsListener); onApplyWindowInsets = WindowInsetsCompat.toWindowInsetsCompat(api20Impl.onApplyWindowInsets(onApplyWindowInsetsListener, this, insets)); } else { onApplyWindowInsets = ViewCompat.onApplyWindowInsets(this, windowInsetsCompat); } Intrinsics.checkNotNullExpressionValue(onApplyWindowInsets, "if (applyWindowInsetsLis…, insetsCompat)\n }"); if (!onApplyWindowInsets.isConsumed()) { int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { ViewCompat.dispatchApplyWindowInsets(getChildAt(i), onApplyWindowInsets); } } return insets; } @Override // android.view.ViewGroup, android.view.View public void dispatchDraw(Canvas canvas) { Intrinsics.checkNotNullParameter(canvas, "canvas"); if (this.drawDisappearingViewsFirst) { Iterator it = this.disappearingFragmentChildren.iterator(); while (it.hasNext()) { super.drawChild(canvas, (View) it.next(), getDrawingTime()); } } super.dispatchDraw(canvas); } @Override // android.view.ViewGroup public boolean drawChild(Canvas canvas, View child, long j) { Intrinsics.checkNotNullParameter(canvas, "canvas"); Intrinsics.checkNotNullParameter(child, "child"); if (this.drawDisappearingViewsFirst && (!this.disappearingFragmentChildren.isEmpty()) && this.disappearingFragmentChildren.contains(child)) { return false; } return super.drawChild(canvas, child, j); } @Override // android.view.ViewGroup public void startViewTransition(View view) { Intrinsics.checkNotNullParameter(view, "view"); if (view.getParent() == this) { this.transitioningFragmentViews.add(view); } super.startViewTransition(view); } @Override // android.view.ViewGroup public void endViewTransition(View view) { Intrinsics.checkNotNullParameter(view, "view"); this.transitioningFragmentViews.remove(view); if (this.disappearingFragmentChildren.remove(view)) { this.drawDisappearingViewsFirst = true; } super.endViewTransition(view); } @Override // android.view.ViewGroup public void addView(View child, int i, ViewGroup.LayoutParams layoutParams) { Intrinsics.checkNotNullParameter(child, "child"); if (FragmentManager.getViewFragment(child) == null) { throw new IllegalStateException(("Views added to a FragmentContainerView must be associated with a Fragment. View " + child + " is not associated with a Fragment.").toString()); } super.addView(child, i, layoutParams); } @Override // android.view.ViewGroup public void removeViewAt(int i) { View view = getChildAt(i); Intrinsics.checkNotNullExpressionValue(view, "view"); addDisappearingFragmentView(view); super.removeViewAt(i); } @Override // android.view.ViewGroup public void removeViewInLayout(View view) { Intrinsics.checkNotNullParameter(view, "view"); addDisappearingFragmentView(view); super.removeViewInLayout(view); } @Override // android.view.ViewGroup, android.view.ViewManager public void removeView(View view) { Intrinsics.checkNotNullParameter(view, "view"); addDisappearingFragmentView(view); super.removeView(view); } @Override // android.view.ViewGroup public void removeViews(int i, int i2) { int i3 = i + i2; for (int i4 = i; i4 < i3; i4++) { View view = getChildAt(i4); Intrinsics.checkNotNullExpressionValue(view, "view"); addDisappearingFragmentView(view); } super.removeViews(i, i2); } @Override // android.view.ViewGroup public void removeViewsInLayout(int i, int i2) { int i3 = i + i2; for (int i4 = i; i4 < i3; i4++) { View view = getChildAt(i4); Intrinsics.checkNotNullExpressionValue(view, "view"); addDisappearingFragmentView(view); } super.removeViewsInLayout(i, i2); } @Override // android.view.ViewGroup public void removeAllViewsInLayout() { int childCount = getChildCount(); while (true) { childCount--; if (-1 < childCount) { View view = getChildAt(childCount); Intrinsics.checkNotNullExpressionValue(view, "view"); addDisappearingFragmentView(view); } else { super.removeAllViewsInLayout(); return; } } } private final void addDisappearingFragmentView(View view) { if (this.transitioningFragmentViews.contains(view)) { this.disappearingFragmentChildren.add(view); } } public final F getFragment() { return (F) FragmentManager.findFragmentManager(this).findFragmentById(getId()); } @RequiresApi(20) public static final class Api20Impl { public static final Api20Impl INSTANCE = new Api20Impl(); private Api20Impl() { } public final WindowInsets onApplyWindowInsets(View.OnApplyWindowInsetsListener onApplyWindowInsetsListener, View v, WindowInsets insets) { Intrinsics.checkNotNullParameter(onApplyWindowInsetsListener, "onApplyWindowInsetsListener"); Intrinsics.checkNotNullParameter(v, "v"); Intrinsics.checkNotNullParameter(insets, "insets"); WindowInsets onApplyWindowInsets = onApplyWindowInsetsListener.onApplyWindowInsets(v, insets); Intrinsics.checkNotNullExpressionValue(onApplyWindowInsets, "onApplyWindowInsetsListe…lyWindowInsets(v, insets)"); return onApplyWindowInsets; } } }