package o; import android.os.Bundle; import android.os.Parcelable; import android.view.View; import android.view.ViewGroup; import androidx.fragment.app.Fragment; import java.util.ArrayList; import o.wdQ; @Deprecated /* loaded from: classes.dex */ public abstract class MoT extends WYJ { private final yRS a; private final int b; private boolean c; private AbstractC13482fbE d; private Fragment e; private ArrayList f; private ArrayList j; public abstract Fragment b(int i); @Deprecated public MoT(yRS yrs) { this(yrs, (byte) 0); } private MoT(yRS yrs, byte b) { this.d = null; this.f = new ArrayList<>(); this.j = new ArrayList<>(); this.e = null; this.a = yrs; this.b = 0; } @Override // o.WYJ public void startUpdate(ViewGroup viewGroup) { if (viewGroup.getId() != -1) { return; } StringBuilder sb = new StringBuilder("ViewPager with adapter "); sb.append(this); sb.append(" requires a view id"); throw new IllegalStateException(sb.toString()); } @Override // o.WYJ public Object instantiateItem(ViewGroup viewGroup, int i) { Fragment.LWm lWm; Fragment fragment; if (this.j.size() > i && (fragment = this.j.get(i)) != null) { return fragment; } if (this.d == null) { this.d = this.a.a(); } Fragment b = b(i); if (this.f.size() > i && (lWm = this.f.get(i)) != null) { b.setInitialSavedState(lWm); } while (this.j.size() <= i) { this.j.add(null); } b.setMenuVisibility(false); if (this.b == 0) { b.setUserVisibleHint(false); } this.j.set(i, b); this.d.b(viewGroup.getId(), b, null, 1); if (this.b == 1) { this.d.d(b, wdQ.IeS.STARTED); } return b; } @Override // o.WYJ public void destroyItem(ViewGroup viewGroup, int i, Object obj) { Fragment fragment = (Fragment) obj; if (this.d == null) { this.d = this.a.a(); } while (this.f.size() <= i) { this.f.add(null); } this.f.set(i, fragment.isAdded() ? this.a.k(fragment) : null); this.j.set(i, null); this.d.e(fragment); if (fragment.equals(this.e)) { this.e = null; } } @Override // o.WYJ public void setPrimaryItem(ViewGroup viewGroup, int i, Object obj) { Fragment fragment = (Fragment) obj; Fragment fragment2 = this.e; if (fragment != fragment2) { if (fragment2 != null) { fragment2.setMenuVisibility(false); if (this.b == 1) { if (this.d == null) { this.d = this.a.a(); } this.d.d(this.e, wdQ.IeS.STARTED); } else { this.e.setUserVisibleHint(false); } } fragment.setMenuVisibility(true); if (this.b == 1) { if (this.d == null) { this.d = this.a.a(); } this.d.d(fragment, wdQ.IeS.RESUMED); } else { fragment.setUserVisibleHint(true); } this.e = fragment; } } @Override // o.WYJ public void finishUpdate(ViewGroup viewGroup) { AbstractC13482fbE abstractC13482fbE = this.d; if (abstractC13482fbE != null) { if (!this.c) { try { this.c = true; abstractC13482fbE.e(); } finally { this.c = false; } } this.d = null; } } @Override // o.WYJ public boolean isViewFromObject(View view, Object obj) { return ((Fragment) obj).getView() == view; } @Override // o.WYJ public Parcelable saveState() { Bundle bundle; if (this.f.size() > 0) { bundle = new Bundle(); Fragment.LWm[] lWmArr = new Fragment.LWm[this.f.size()]; this.f.toArray(lWmArr); bundle.putParcelableArray("states", lWmArr); } else { bundle = null; } for (int i = 0; i < this.j.size(); i++) { Fragment fragment = this.j.get(i); if (fragment != null && fragment.isAdded()) { if (bundle == null) { bundle = new Bundle(); } this.a.yJ_(bundle, "f".concat(String.valueOf(i)), fragment); } } return bundle; } @Override // o.WYJ public void restoreState(Parcelable parcelable, ClassLoader classLoader) { if (parcelable != null) { Bundle bundle = (Bundle) parcelable; bundle.setClassLoader(classLoader); Parcelable[] parcelableArray = bundle.getParcelableArray("states"); this.f.clear(); this.j.clear(); if (parcelableArray != null) { for (Parcelable parcelable2 : parcelableArray) { this.f.add((Fragment.LWm) parcelable2); } } for (String str : bundle.keySet()) { if (str.startsWith("f")) { int parseInt = Integer.parseInt(str.substring(1)); Fragment yD_ = this.a.yD_(bundle, str); if (yD_ != null) { while (this.j.size() <= parseInt) { this.j.add(null); } yD_.setMenuVisibility(false); this.j.set(parseInt, yD_); } } } } } }