package androidx.fragment.app;

import android.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
@Deprecated
public class FragmentTabHost extends TabHost implements TabHost.OnTabChangeListener {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public FrameLayout f2294b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Context f2295c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public d1 f2296d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f2297e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public TabHost.OnTabChangeListener f2298f;

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

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

    @Deprecated
    public FragmentTabHost(@NonNull Context context) {
        super(context, null);
        this.f2293a = new ArrayList();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(null, new int[]{R.attr.inflatedId}, 0, 0);
        this.f2297e = typedArrayObtainStyledAttributes.getResourceId(0, 0);
        typedArrayObtainStyledAttributes.recycle();
        super.setOnTabChangedListener(this);
    }

    @Nullable
    private r1 doTabChanged(@Nullable String str, @Nullable r1 r1Var) {
        e0 e0Var;
        p1 tabInfoForTag = getTabInfoForTag(str);
        if (this.f2299g != tabInfoForTag) {
            if (r1Var == null) {
                d1 d1Var = this.f2296d;
                d1Var.getClass();
                r1Var = new a(d1Var);
            }
            p1 p1Var = this.f2299g;
            if (p1Var != null && (e0Var = p1Var.f2545c) != null) {
                r1Var.f(e0Var);
            }
            if (tabInfoForTag != null) {
                e0 e0Var2 = tabInfoForTag.f2545c;
                if (e0Var2 == null) {
                    m0 m0VarD = this.f2296d.D();
                    this.f2295c.getClassLoader();
                    e0 e0VarA = m0VarD.a(tabInfoForTag.f2544b.getName());
                    tabInfoForTag.f2545c = e0VarA;
                    e0VarA.setArguments(tabInfoForTag.args);
                    r1Var.add(this.f2297e, tabInfoForTag.f2545c, tabInfoForTag.f2543a);
                } else {
                    r1Var.b(new q1(e0Var2, 7));
                }
            }
            this.f2299g = tabInfoForTag;
        }
        return r1Var;
    }

    @Nullable
    private p1 getTabInfoForTag(String str) {
        ArrayList arrayList = this.f2293a;
        int size = arrayList.size();
        for (int i10 = 0; i10 < size; i10++) {
            p1 p1Var = (p1) arrayList.get(i10);
            if (p1Var.f2543a.equals(str)) {
                return p1Var;
            }
        }
        return null;
    }

    public final void a() {
        if (this.f2294b == null) {
            FrameLayout frameLayout = (FrameLayout) findViewById(this.f2297e);
            this.f2294b = frameLayout;
            if (frameLayout != null) {
                return;
            }
            throw new IllegalStateException("No tab content FrameLayout found for id " + this.f2297e);
        }
    }

    @Deprecated
    public void addTab(@NonNull TabHost.TabSpec tabSpec, @NonNull Class<?> cls, @Nullable Bundle bundle) {
        tabSpec.setContent(new n1(this.f2295c));
        String tag = tabSpec.getTag();
        p1 p1Var = new p1(tag, cls, bundle);
        if (this.f2300h) {
            e0 e0VarFindFragmentByTag = this.f2296d.findFragmentByTag(tag);
            p1Var.f2545c = e0VarFindFragmentByTag;
            if (e0VarFindFragmentByTag != null && !e0VarFindFragmentByTag.isDetached()) {
                d1 d1Var = this.f2296d;
                d1Var.getClass();
                a aVar = new a(d1Var);
                aVar.f(p1Var.f2545c);
                aVar.i(false);
            }
        }
        this.f2293a.add(p1Var);
        addTab(tabSpec);
    }

    public final void b(Context context) {
        if (findViewById(R.id.tabs) == null) {
            LinearLayout linearLayout = new LinearLayout(context);
            linearLayout.setOrientation(1);
            addView(linearLayout, new FrameLayout.LayoutParams(-1, -1));
            TabWidget tabWidget = new TabWidget(context);
            tabWidget.setId(R.id.tabs);
            tabWidget.setOrientation(0);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(-1, -2, 0.0f));
            FrameLayout frameLayout = new FrameLayout(context);
            frameLayout.setId(R.id.tabcontent);
            linearLayout.addView(frameLayout, new LinearLayout.LayoutParams(0, 0, 0.0f));
            FrameLayout frameLayout2 = new FrameLayout(context);
            this.f2294b = frameLayout2;
            frameLayout2.setId(this.f2297e);
            linearLayout.addView(frameLayout2, new LinearLayout.LayoutParams(-1, 0, 1.0f));
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        String currentTabTag = getCurrentTabTag();
        ArrayList arrayList = this.f2293a;
        int size = arrayList.size();
        a aVar = null;
        for (int i10 = 0; i10 < size; i10++) {
            p1 p1Var = (p1) arrayList.get(i10);
            e0 e0VarFindFragmentByTag = this.f2296d.findFragmentByTag(p1Var.f2543a);
            p1Var.f2545c = e0VarFindFragmentByTag;
            if (e0VarFindFragmentByTag != null && !e0VarFindFragmentByTag.isDetached()) {
                if (p1Var.f2543a.equals(currentTabTag)) {
                    this.f2299g = p1Var;
                } else {
                    if (aVar == null) {
                        d1 d1Var = this.f2296d;
                        d1Var.getClass();
                        aVar = new a(d1Var);
                    }
                    aVar.f(p1Var.f2545c);
                }
            }
        }
        this.f2300h = true;
        r1 r1VarDoTabChanged = doTabChanged(currentTabTag, aVar);
        if (r1VarDoTabChanged != null) {
            r1VarDoTabChanged.c();
            d1 d1Var2 = this.f2296d;
            d1Var2.x(true);
            d1Var2.A();
        }
    }

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

    @Override // android.view.View
    public final void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof o1)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        o1 o1Var = (o1) parcelable;
        super.onRestoreInstanceState(o1Var.getSuperState());
        setCurrentTabByTag(o1Var.f2541a);
    }

    @Override // android.view.View
    public final Parcelable onSaveInstanceState() {
        o1 o1Var = new o1(super.onSaveInstanceState());
        o1Var.f2541a = getCurrentTabTag();
        return o1Var;
    }

    @Override // android.widget.TabHost.OnTabChangeListener
    @Deprecated
    public void onTabChanged(@Nullable String str) {
        r1 r1VarDoTabChanged;
        if (this.f2300h && (r1VarDoTabChanged = doTabChanged(str, null)) != null) {
            r1VarDoTabChanged.c();
        }
        TabHost.OnTabChangeListener onTabChangeListener = this.f2298f;
        if (onTabChangeListener != null) {
            onTabChangeListener.onTabChanged(str);
        }
    }

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

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

    @Deprecated
    public void setup(@NonNull Context context, @NonNull d1 d1Var) {
        b(context);
        super.setup();
        this.f2295c = context;
        this.f2296d = d1Var;
        a();
    }

    @Deprecated
    public void setup(@NonNull Context context, @NonNull d1 d1Var, int i10) {
        b(context);
        super.setup();
        this.f2295c = context;
        this.f2296d = d1Var;
        this.f2297e = i10;
        a();
        this.f2294b.setId(i10);
        if (getId() == -1) {
            setId(R.id.tabhost);
        }
    }

    @Deprecated
    public FragmentTabHost(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f2293a = new ArrayList();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{R.attr.inflatedId}, 0, 0);
        this.f2297e = typedArrayObtainStyledAttributes.getResourceId(0, 0);
        typedArrayObtainStyledAttributes.recycle();
        super.setOnTabChangedListener(this);
    }
}
