package androidx.fragment.app;

import X6FRs_4.XnFJ5_9.KQgRr5e_0.IFxWkV_5;
import X6FRs_4.XnFJ5_9.KQgRr5e_0.Xgtqvk_8;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TabHost;
import java.util.ArrayList;
/* loaded from: classes.dex */
public class FragmentTabHost extends TabHost implements TabHost.OnTabChangeListener {
    public int KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public IFxWkV_5 f2348KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public Context f2349KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public TabHost.OnTabChangeListener f2350KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public KQgRr5e_0 f2351KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final ArrayList<KQgRr5e_0> f2352KQgRr5e_0;
    public boolean QxJ9d_1;

    /* loaded from: classes.dex */
    public static final class KQgRr5e_0 {
        public final Bundle KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public Fragment f2353KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final Class<?> f2354KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final String f2355KQgRr5e_0;
    }

    /* loaded from: classes.dex */
    public static class SavedState extends View.BaseSavedState {
        public static final Parcelable.Creator<SavedState> CREATOR = new KQgRr5e_0();
        public String KQgRr5e_0;

        /* loaded from: classes.dex */
        public static class KQgRr5e_0 implements Parcelable.Creator<SavedState> {
            @Override // android.os.Parcelable.Creator
            /* renamed from: KQgRr5e_0 */
            public SavedState createFromParcel(Parcel parcel) {
                return new SavedState(parcel);
            }

            @Override // android.os.Parcelable.Creator
            /* renamed from: KQgRr5e_0 */
            public SavedState[] newArray(int i) {
                return new SavedState[i];
            }
        }

        public SavedState(Parcelable parcelable) {
            super(parcelable);
        }

        public String toString() {
            return "FragmentTabHost.SavedState{" + Integer.toHexString(System.identityHashCode(this)) + " curTab=" + this.KQgRr5e_0 + "}";
        }

        @Override // android.view.View.BaseSavedState, android.view.AbsSavedState, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeString(this.KQgRr5e_0);
        }

        public SavedState(Parcel parcel) {
            super(parcel);
            this.KQgRr5e_0 = parcel.readString();
        }
    }

    public FragmentTabHost(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f2352KQgRr5e_0 = new ArrayList<>();
        KQgRr5e_0(context, attributeSet);
    }

    public final void KQgRr5e_0(Context context, AttributeSet attributeSet) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{16842995}, 0, 0);
        this.KQgRr5e_0 = obtainStyledAttributes.getResourceId(0, 0);
        obtainStyledAttributes.recycle();
        super.setOnTabChangedListener(this);
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        String currentTabTag = getCurrentTabTag();
        int size = this.f2352KQgRr5e_0.size();
        Xgtqvk_8 xgtqvk_8 = null;
        for (int i = 0; i < size; i++) {
            KQgRr5e_0 kQgRr5e_0 = this.f2352KQgRr5e_0.get(i);
            Fragment KQgRr5e_02 = this.f2348KQgRr5e_0.KQgRr5e_0(kQgRr5e_0.f2355KQgRr5e_0);
            kQgRr5e_0.f2353KQgRr5e_0 = KQgRr5e_02;
            if (KQgRr5e_02 != null && !KQgRr5e_02.isDetached()) {
                if (kQgRr5e_0.f2355KQgRr5e_0.equals(currentTabTag)) {
                    this.f2351KQgRr5e_0 = kQgRr5e_0;
                } else {
                    if (xgtqvk_8 == null) {
                        xgtqvk_8 = this.f2348KQgRr5e_0.KQgRr5e_0();
                    }
                    xgtqvk_8.QxJ9d_1(kQgRr5e_0.f2353KQgRr5e_0);
                }
            }
        }
        this.QxJ9d_1 = true;
        Xgtqvk_8 KQgRr5e_03 = KQgRr5e_0(currentTabTag, xgtqvk_8);
        if (KQgRr5e_03 != null) {
            KQgRr5e_03.KQgRr5e_0();
            this.f2348KQgRr5e_0.m599KQgRr5e_0();
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.QxJ9d_1 = false;
    }

    @Override // android.view.View
    public void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof SavedState)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        SavedState savedState = (SavedState) parcelable;
        super.onRestoreInstanceState(savedState.getSuperState());
        setCurrentTabByTag(savedState.KQgRr5e_0);
    }

    @Override // android.view.View
    public Parcelable onSaveInstanceState() {
        SavedState savedState = new SavedState(super.onSaveInstanceState());
        savedState.KQgRr5e_0 = getCurrentTabTag();
        return savedState;
    }

    @Override // android.widget.TabHost.OnTabChangeListener
    public void onTabChanged(String str) {
        Xgtqvk_8 KQgRr5e_02;
        if (this.QxJ9d_1 && (KQgRr5e_02 = KQgRr5e_0(str, (Xgtqvk_8) null)) != null) {
            KQgRr5e_02.KQgRr5e_0();
        }
        TabHost.OnTabChangeListener onTabChangeListener = this.f2350KQgRr5e_0;
        if (onTabChangeListener != null) {
            onTabChangeListener.onTabChanged(str);
        }
    }

    @Override // android.widget.TabHost
    public void setOnTabChangedListener(TabHost.OnTabChangeListener onTabChangeListener) {
        this.f2350KQgRr5e_0 = onTabChangeListener;
    }

    @Override // android.widget.TabHost
    @Deprecated
    public void setup() {
        throw new IllegalStateException("Must call setup() that takes a Context and FragmentManager");
    }

    public final Xgtqvk_8 KQgRr5e_0(String str, Xgtqvk_8 xgtqvk_8) {
        Fragment fragment;
        KQgRr5e_0 KQgRr5e_02 = KQgRr5e_0(str);
        if (this.f2351KQgRr5e_0 != KQgRr5e_02) {
            if (xgtqvk_8 == null) {
                xgtqvk_8 = this.f2348KQgRr5e_0.KQgRr5e_0();
            }
            KQgRr5e_0 kQgRr5e_0 = this.f2351KQgRr5e_0;
            if (kQgRr5e_0 != null && (fragment = kQgRr5e_0.f2353KQgRr5e_0) != null) {
                xgtqvk_8.QxJ9d_1(fragment);
            }
            if (KQgRr5e_02 != null) {
                Fragment fragment2 = KQgRr5e_02.f2353KQgRr5e_0;
                if (fragment2 == null) {
                    Fragment instantiate = Fragment.instantiate(this.f2349KQgRr5e_0, KQgRr5e_02.f2354KQgRr5e_0.getName(), KQgRr5e_02.KQgRr5e_0);
                    KQgRr5e_02.f2353KQgRr5e_0 = instantiate;
                    xgtqvk_8.KQgRr5e_0(this.KQgRr5e_0, instantiate, KQgRr5e_02.f2355KQgRr5e_0);
                } else {
                    xgtqvk_8.KQgRr5e_0(fragment2);
                }
            }
            this.f2351KQgRr5e_0 = KQgRr5e_02;
        }
        return xgtqvk_8;
    }

    public final KQgRr5e_0 KQgRr5e_0(String str) {
        int size = this.f2352KQgRr5e_0.size();
        for (int i = 0; i < size; i++) {
            KQgRr5e_0 kQgRr5e_0 = this.f2352KQgRr5e_0.get(i);
            if (kQgRr5e_0.f2355KQgRr5e_0.equals(str)) {
                return kQgRr5e_0;
            }
        }
        return null;
    }
}
