package androidx.fragment.app;

import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.f;
import androidx.lifecycle.n;
import java.util.ArrayList;

/* loaded from: classes.dex */
public abstract class i0 extends androidx.viewpager.widget.a {

    /* renamed from: c, reason: collision with root package name */
    private final z f4553c;

    /* renamed from: d, reason: collision with root package name */
    private final int f4554d;

    /* renamed from: e, reason: collision with root package name */
    private k0 f4555e = null;

    /* renamed from: f, reason: collision with root package name */
    private ArrayList f4556f = new ArrayList();

    /* renamed from: g, reason: collision with root package name */
    private ArrayList f4557g = new ArrayList();

    /* renamed from: h, reason: collision with root package name */
    private f f4558h = null;

    /* renamed from: i, reason: collision with root package name */
    private boolean f4559i;

    public i0(z zVar, int i10) {
        this.f4553c = zVar;
        this.f4554d = i10;
    }

    @Override // androidx.viewpager.widget.a
    public void a(ViewGroup viewGroup, int i10, Object obj) {
        f fVar = (f) obj;
        if (this.f4555e == null) {
            this.f4555e = this.f4553c.p();
        }
        while (this.f4556f.size() <= i10) {
            this.f4556f.add(null);
        }
        this.f4556f.set(i10, fVar.isAdded() ? this.f4553c.A1(fVar) : null);
        this.f4557g.set(i10, null);
        this.f4555e.r(fVar);
        if (fVar.equals(this.f4558h)) {
            this.f4558h = null;
        }
    }

    @Override // androidx.viewpager.widget.a
    public void b(ViewGroup viewGroup) {
        k0 k0Var = this.f4555e;
        if (k0Var != null) {
            if (!this.f4559i) {
                try {
                    this.f4559i = true;
                    k0Var.l();
                } finally {
                    this.f4559i = false;
                }
            }
            this.f4555e = null;
        }
    }

    @Override // androidx.viewpager.widget.a
    public Object g(ViewGroup viewGroup, int i10) {
        f.o oVar;
        f fVar;
        if (this.f4557g.size() > i10 && (fVar = (f) this.f4557g.get(i10)) != null) {
            return fVar;
        }
        if (this.f4555e == null) {
            this.f4555e = this.f4553c.p();
        }
        f p10 = p(i10);
        if (this.f4556f.size() > i10 && (oVar = (f.o) this.f4556f.get(i10)) != null) {
            p10.setInitialSavedState(oVar);
        }
        while (this.f4557g.size() <= i10) {
            this.f4557g.add(null);
        }
        p10.setMenuVisibility(false);
        if (this.f4554d == 0) {
            p10.setUserVisibleHint(false);
        }
        this.f4557g.set(i10, p10);
        this.f4555e.b(viewGroup.getId(), p10);
        if (this.f4554d == 1) {
            this.f4555e.v(p10, n.b.STARTED);
        }
        return p10;
    }

    @Override // androidx.viewpager.widget.a
    public boolean h(View view, Object obj) {
        return ((f) obj).getView() == view;
    }

    @Override // androidx.viewpager.widget.a
    public void j(Parcelable parcelable, ClassLoader classLoader) {
        if (parcelable != null) {
            Bundle bundle = (Bundle) parcelable;
            bundle.setClassLoader(classLoader);
            Parcelable[] parcelableArray = bundle.getParcelableArray("states");
            this.f4556f.clear();
            this.f4557g.clear();
            if (parcelableArray != null) {
                for (Parcelable parcelable2 : parcelableArray) {
                    this.f4556f.add((f.o) parcelable2);
                }
            }
            for (String str : bundle.keySet()) {
                if (str.startsWith("f")) {
                    int parseInt = Integer.parseInt(str.substring(1));
                    f v02 = this.f4553c.v0(bundle, str);
                    if (v02 != null) {
                        while (this.f4557g.size() <= parseInt) {
                            this.f4557g.add(null);
                        }
                        v02.setMenuVisibility(false);
                        this.f4557g.set(parseInt, v02);
                    } else {
                        Log.w("FragmentStatePagerAdapt", "Bad fragment at key " + str);
                    }
                }
            }
        }
    }

    @Override // androidx.viewpager.widget.a
    public Parcelable k() {
        Bundle bundle;
        if (this.f4556f.size() > 0) {
            bundle = new Bundle();
            f.o[] oVarArr = new f.o[this.f4556f.size()];
            this.f4556f.toArray(oVarArr);
            bundle.putParcelableArray("states", oVarArr);
        } else {
            bundle = null;
        }
        for (int i10 = 0; i10 < this.f4557g.size(); i10++) {
            f fVar = (f) this.f4557g.get(i10);
            if (fVar != null && fVar.isAdded()) {
                if (bundle == null) {
                    bundle = new Bundle();
                }
                this.f4553c.n1(bundle, "f" + i10, fVar);
            }
        }
        return bundle;
    }

    @Override // androidx.viewpager.widget.a
    public void l(ViewGroup viewGroup, int i10, Object obj) {
        f fVar = (f) obj;
        f fVar2 = this.f4558h;
        if (fVar != fVar2) {
            if (fVar2 != null) {
                fVar2.setMenuVisibility(false);
                if (this.f4554d == 1) {
                    if (this.f4555e == null) {
                        this.f4555e = this.f4553c.p();
                    }
                    this.f4555e.v(this.f4558h, n.b.STARTED);
                } else {
                    this.f4558h.setUserVisibleHint(false);
                }
            }
            fVar.setMenuVisibility(true);
            if (this.f4554d == 1) {
                if (this.f4555e == null) {
                    this.f4555e = this.f4553c.p();
                }
                this.f4555e.v(fVar, n.b.RESUMED);
            } else {
                fVar.setUserVisibleHint(true);
            }
            this.f4558h = fVar;
        }
    }

    @Override // androidx.viewpager.widget.a
    public void n(ViewGroup viewGroup) {
        if (viewGroup.getId() != -1) {
            return;
        }
        throw new IllegalStateException("ViewPager with adapter " + this + " requires a view id");
    }

    public abstract f p(int i10);
}
