package o; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Parcelable; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import android.widget.FrameLayout; import androidx.core.view.ViewCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager2.widget.ViewPager2; import java.util.Iterator; import o.InterfaceC16541pFg; import o.Oym; import o.VEt; import o.wdQ; import o.yRS; /* loaded from: classes.dex */ public abstract class Oym extends RecyclerView.Sts implements Dyg { boolean a; final wdQ b; private LWm c; final C0667Ltg d; public final yRS e; private final C0667Ltg f; private final C0667Ltg h; private boolean j; public abstract Fragment a(int i); @Override // androidx.recyclerview.widget.RecyclerView.Sts public long getItemId(int i) { return i; } @Override // androidx.recyclerview.widget.RecyclerView.Sts public /* synthetic */ void onBindViewHolder(VEt vEt, int i) { VEt vEt2 = vEt; long itemId = vEt2.getItemId(); int id = ((FrameLayout) vEt2.itemView).getId(); Long e = e(id); if (e != null && e.longValue() != itemId) { e(e.longValue()); this.f.e(e.longValue()); } this.f.c(itemId, Integer.valueOf(id)); long itemId2 = getItemId(i); if (!this.d.d(itemId2)) { Fragment a = a(i); a.setInitialSavedState(this.h.c(itemId2)); this.d.c(itemId2, a); } FrameLayout frameLayout = (FrameLayout) vEt2.itemView; if (ViewCompat.H(frameLayout)) { if (frameLayout.getParent() != null) { throw new IllegalStateException("Design assumption violated."); } frameLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener(this, frameLayout, vEt2) { // from class: o.Oym.1 final Oym a; final FrameLayout b; final VEt d; { this.a = this; this.b = frameLayout; this.d = vEt2; } @Override // android.view.View.OnLayoutChangeListener public final void onLayoutChange(View view, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9) { if (this.b.getParent() != null) { this.b.removeOnLayoutChangeListener(this); this.a.c(this.d); } } }); } c(); } @Override // androidx.recyclerview.widget.RecyclerView.Sts public /* bridge */ /* synthetic */ boolean onFailedToRecycleView(VEt vEt) { return true; } @Override // androidx.recyclerview.widget.RecyclerView.Sts public /* synthetic */ void onViewAttachedToWindow(VEt vEt) { c(vEt); c(); } @Override // androidx.recyclerview.widget.RecyclerView.Sts public /* synthetic */ void onViewRecycled(VEt vEt) { Long e = e(((FrameLayout) vEt.itemView).getId()); if (e != null) { e(e.longValue()); this.f.e(e.longValue()); } } public Oym(FragmentActivity fragmentActivity) { this(fragmentActivity.getSupportFragmentManager(), fragmentActivity.getLifecycle()); } public Oym(Fragment fragment) { this(fragment.getChildFragmentManager(), fragment.getLifecycle()); } private Oym(yRS yrs, wdQ wdq) { this.d = new C0667Ltg<>(); this.h = new C0667Ltg<>(); this.f = new C0667Ltg<>(); this.a = false; this.j = false; this.e = yrs; this.b = wdq; super.setHasStableIds(true); } @Override // androidx.recyclerview.widget.RecyclerView.Sts public void onAttachedToRecyclerView(RecyclerView recyclerView) { if (this.c == null) { final LWm lWm = new LWm(this); this.c = lWm; lWm.b = LWm.b(recyclerView); ViewPager2.IeS ieS = new ViewPager2.IeS(lWm) { // from class: o.Oym.LWm.5 final LWm d; { this.d = lWm; } @Override // androidx.viewpager2.widget.ViewPager2.IeS public final void b(int i) { this.d.a(false); } @Override // androidx.viewpager2.widget.ViewPager2.IeS public final void c(int i) { this.d.a(false); } }; lWm.c = ieS; lWm.b.a.e.add(ieS); Sts sts = new Sts(lWm) { // from class: o.Oym.LWm.1 final LWm b; { this.b = lWm; } @Override // androidx.recyclerview.widget.RecyclerView.LWm public final void c() { this.b.a(true); } }; lWm.e = sts; lWm.a.registerAdapterDataObserver(sts); lWm.d = new InterfaceC3451axm(lWm) { // from class: androidx.viewpager2.adapter.FragmentStateAdapter$FragmentMaxLifecycleEnforcer$3 final Oym.LWm c; { this.c = lWm; } @Override // o.InterfaceC3451axm public final void c(InterfaceC16541pFg interfaceC16541pFg, wdQ.HBt hBt) { this.c.a(false); } }; lWm.a.b.e(lWm.d); return; } throw new IllegalArgumentException(); } final void c() { Fragment c; View view; if (!this.j || this.e.A()) { return; } wnv wnvVar = new wnv(); int i = 0; int i2 = 0; while (true) { C0667Ltg c0667Ltg = this.d; if (c0667Ltg.b) { c0667Ltg.c(); } if (i2 >= c0667Ltg.a) { break; } C0667Ltg c0667Ltg2 = this.d; if (c0667Ltg2.b) { c0667Ltg2.c(); } long j = c0667Ltg2.e[i2]; if (j < 0 || j >= getItemCount()) { wnvVar.add(Long.valueOf(j)); this.f.e(j); } i2++; } if (!this.a) { this.j = false; while (true) { C0667Ltg c0667Ltg3 = this.d; if (c0667Ltg3.b) { c0667Ltg3.c(); } if (i >= c0667Ltg3.a) { break; } C0667Ltg c0667Ltg4 = this.d; if (c0667Ltg4.b) { c0667Ltg4.c(); } long j2 = c0667Ltg4.e[i]; if (!this.f.d(j2) && ((c = this.d.c(j2)) == null || (view = c.getView()) == null || view.getParent() == null)) { wnvVar.add(Long.valueOf(j2)); } i++; } } Iterator it = wnvVar.iterator(); while (it.hasNext()) { e(((Long) it.next()).longValue()); } } private Long e(int i) { Long l = null; int i2 = 0; while (true) { C0667Ltg c0667Ltg = this.f; if (c0667Ltg.b) { c0667Ltg.c(); } if (i2 >= c0667Ltg.a) { return l; } C0667Ltg c0667Ltg2 = this.f; if (c0667Ltg2.b) { c0667Ltg2.c(); } if (((Integer) c0667Ltg2.c[i2]).intValue() == i) { if (l != null) { throw new IllegalStateException("Design assumption violated: a ViewHolder can only be bound to one item at a time."); } C0667Ltg c0667Ltg3 = this.f; if (c0667Ltg3.b) { c0667Ltg3.c(); } l = Long.valueOf(c0667Ltg3.e[i2]); } i2++; } } public final void c(final VEt vEt) { Fragment c = this.d.c(vEt.getItemId()); if (c == null) { throw new IllegalStateException("Design assumption violated."); } FrameLayout frameLayout = (FrameLayout) vEt.itemView; View view = c.getView(); if (!c.isAdded() && view != null) { throw new IllegalStateException("Design assumption violated."); } if (!c.isAdded() || view != null) { if (c.isAdded() && view.getParent() != null) { if (view.getParent() != frameLayout) { Cd_(view, frameLayout); return; } return; } if (c.isAdded()) { Cd_(view, frameLayout); return; } if (this.e.A()) { if (this.e.B()) { return; } this.b.e(new InterfaceC3451axm(this, vEt) { // from class: androidx.viewpager2.adapter.FragmentStateAdapter$2 final VEt b; final Oym d; { this.d = this; this.b = vEt; } @Override // o.InterfaceC3451axm public final void c(InterfaceC16541pFg interfaceC16541pFg, wdQ.HBt hBt) { if (this.d.e.A()) { return; } interfaceC16541pFg.getLifecycle().a(this); if (ViewCompat.H((FrameLayout) this.b.itemView)) { this.d.c(this.b); } } }); return; } this.e.e(new yRS.LWm(this, c, frameLayout) { // from class: o.Oym.3 final Oym a; final Fragment b; final FrameLayout c; { this.a = this; this.b = c; this.c = frameLayout; } @Override // o.yRS.LWm public final void e(yRS yrs, Fragment fragment, View view2) { if (fragment == this.b) { yrs.b(this); Oym.Cd_(view2, this.c); } } }); AbstractC13482fbE a = this.e.a(); StringBuilder sb = new StringBuilder("f"); sb.append(vEt.getItemId()); a.b(0, c, sb.toString(), 1); a.d(c, wdQ.IeS.STARTED).d(); this.c.a(false); return; } this.e.e(new yRS.LWm(this, c, frameLayout) { // from class: o.Oym.3 final Oym a; final Fragment b; final FrameLayout c; { this.a = this; this.b = c; this.c = frameLayout; } @Override // o.yRS.LWm public final void e(yRS yrs, Fragment fragment, View view2) { if (fragment == this.b) { yrs.b(this); Oym.Cd_(view2, this.c); } } }); } static void Cd_(View view, FrameLayout frameLayout) { if (frameLayout.getChildCount() > 1) { throw new IllegalStateException("Design assumption violated."); } if (view.getParent() == frameLayout) { return; } if (frameLayout.getChildCount() > 0) { frameLayout.removeAllViews(); } if (view.getParent() != null) { ((ViewGroup) view.getParent()).removeView(view); } frameLayout.addView(view); } @Override // androidx.recyclerview.widget.RecyclerView.Sts public final void setHasStableIds(boolean z) { throw new UnsupportedOperationException("Stable Ids are required for the adapter to function properly, and the adapter takes care of setting the flag."); } @Override // o.Dyg public final Parcelable Ci_() { Bundle bundle = new Bundle(this.d.a() + this.h.a()); int i = 0; int i2 = 0; while (true) { C0667Ltg c0667Ltg = this.d; if (c0667Ltg.b) { c0667Ltg.c(); } if (i2 >= c0667Ltg.a) { break; } C0667Ltg c0667Ltg2 = this.d; if (c0667Ltg2.b) { c0667Ltg2.c(); } long j = c0667Ltg2.e[i2]; Fragment c = this.d.c(j); if (c != null && c.isAdded()) { StringBuilder sb = new StringBuilder(); sb.append("f#"); sb.append(j); this.e.yJ_(bundle, sb.toString(), c); } i2++; } while (true) { C0667Ltg c0667Ltg3 = this.h; if (c0667Ltg3.b) { c0667Ltg3.c(); } if (i >= c0667Ltg3.a) { return bundle; } C0667Ltg c0667Ltg4 = this.h; if (c0667Ltg4.b) { c0667Ltg4.c(); } long j2 = c0667Ltg4.e[i]; if (j2 >= 0 && j2 < getItemCount()) { StringBuilder sb2 = new StringBuilder(); sb2.append("s#"); sb2.append(j2); bundle.putParcelable(sb2.toString(), this.h.c(j2)); } i++; } } /* loaded from: classes.dex */ public class LWm { final Oym a; ViewPager2 b; ViewPager2.IeS c; InterfaceC3451axm d; RecyclerView.LWm e; private long g = -1; LWm(Oym oym) { this.a = oym; } public final void a(boolean z) { int i; Fragment c; if (!this.a.e.A() && this.b.i.c == 0) { C0667Ltg c0667Ltg = this.a.d; if (c0667Ltg.b) { c0667Ltg.c(); } if (c0667Ltg.a == 0 || this.a.getItemCount() == 0 || (i = this.b.d) >= this.a.getItemCount()) { return; } long itemId = this.a.getItemId(i); if ((itemId != this.g || z) && (c = this.a.d.c(itemId)) != null && c.isAdded()) { this.g = itemId; AbstractC13482fbE a = this.a.e.a(); Fragment fragment = null; int i2 = 0; while (true) { C0667Ltg c0667Ltg2 = this.a.d; if (c0667Ltg2.b) { c0667Ltg2.c(); } if (i2 >= c0667Ltg2.a) { break; } C0667Ltg c0667Ltg3 = this.a.d; if (c0667Ltg3.b) { c0667Ltg3.c(); } long j = c0667Ltg3.e[i2]; C0667Ltg c0667Ltg4 = this.a.d; if (c0667Ltg4.b) { c0667Ltg4.c(); } Fragment fragment2 = (Fragment) c0667Ltg4.c[i2]; if (fragment2.isAdded()) { if (j != this.g) { a.d(fragment2, wdQ.IeS.STARTED); } else { fragment = fragment2; } fragment2.setMenuVisibility(j == this.g); } i2++; } if (fragment != null) { a.d(fragment, wdQ.IeS.RESUMED); } if (a.f()) { return; } a.d(); } } } static ViewPager2 b(RecyclerView recyclerView) { ViewParent parent = recyclerView.getParent(); if (parent instanceof ViewPager2) { return (ViewPager2) parent; } throw new IllegalStateException("Expected ViewPager2 instance. Got: ".concat(String.valueOf(parent))); } } /* loaded from: classes.dex */ static abstract class Sts extends RecyclerView.LWm { private Sts() { } /* synthetic */ Sts(byte b) { this(); } @Override // androidx.recyclerview.widget.RecyclerView.LWm public final void c(int i, int i2) { c(); } @Override // androidx.recyclerview.widget.RecyclerView.LWm public final void c(int i, int i2, Object obj) { c(); } @Override // androidx.recyclerview.widget.RecyclerView.LWm public final void b(int i, int i2) { c(); } @Override // androidx.recyclerview.widget.RecyclerView.LWm public final void a(int i, int i2) { c(); } @Override // androidx.recyclerview.widget.RecyclerView.LWm public final void d(int i, int i2) { c(); } } private void e(long j) { ViewParent parent; Fragment c = this.d.c(j); if (c == null) { return; } if (c.getView() != null && (parent = c.getView().getParent()) != null) { ((FrameLayout) parent).removeAllViews(); } if (j < 0 || j >= getItemCount()) { this.h.e(j); } if (!c.isAdded()) { this.d.e(j); return; } if (this.e.A()) { this.j = true; return; } if (c.isAdded() && j >= 0 && j < getItemCount()) { this.h.c(j, this.e.k(c)); } this.e.a().e(c).d(); this.d.e(j); } @Override // androidx.recyclerview.widget.RecyclerView.Sts public /* synthetic */ VEt onCreateViewHolder(ViewGroup viewGroup, int i) { return VEt.Cg_(viewGroup); } @Override // androidx.recyclerview.widget.RecyclerView.Sts public void onDetachedFromRecyclerView(RecyclerView recyclerView) { LWm lWm = this.c; ViewPager2 b = LWm.b(recyclerView); b.a.e.remove(lWm.c); lWm.a.unregisterAdapterDataObserver(lWm.e); lWm.a.b.a(lWm.d); lWm.b = null; this.c = null; } @Override // o.Dyg public final void Ch_(Parcelable parcelable) { C0667Ltg c0667Ltg = this.h; if (c0667Ltg.b) { c0667Ltg.c(); } if (c0667Ltg.a == 0) { C0667Ltg c0667Ltg2 = this.d; if (c0667Ltg2.b) { c0667Ltg2.c(); } if (c0667Ltg2.a == 0) { Bundle bundle = (Bundle) parcelable; if (bundle.getClassLoader() == null) { bundle.setClassLoader(getClass().getClassLoader()); } for (String str : bundle.keySet()) { if (str.startsWith("f#") && str.length() > 2) { this.d.c(Long.parseLong(str.substring(2)), this.e.yD_(bundle, str)); } else { if (!str.startsWith("s#") || str.length() <= 2) { throw new IllegalArgumentException("Unexpected key in savedState: ".concat(String.valueOf(str))); } long parseLong = Long.parseLong(str.substring(2)); Fragment.LWm lWm = (Fragment.LWm) bundle.getParcelable(str); if (parseLong >= 0 && parseLong < getItemCount()) { this.h.c(parseLong, lWm); } } } C0667Ltg c0667Ltg3 = this.d; if (c0667Ltg3.b) { c0667Ltg3.c(); } if (c0667Ltg3.a == 0) { return; } this.j = true; this.a = true; c(); final Handler handler = new Handler(Looper.getMainLooper()); final Runnable runnable = new Runnable(this) { // from class: o.Oym.4 final Oym c; { this.c = this; } @Override // java.lang.Runnable public final void run() { this.c.a = false; this.c.c(); } }; this.b.e(new InterfaceC3451axm(this, handler, runnable) { // from class: androidx.viewpager2.adapter.FragmentStateAdapter$5 final Handler a; final Runnable c; final Oym d; { this.d = this; this.a = handler; this.c = runnable; } @Override // o.InterfaceC3451axm public final void c(InterfaceC16541pFg interfaceC16541pFg, wdQ.HBt hBt) { if (hBt == wdQ.HBt.ON_DESTROY) { this.a.removeCallbacks(this.c); interfaceC16541pFg.getLifecycle().a(this); } } }); handler.postDelayed(runnable, 10000L); return; } } throw new IllegalStateException("Expected the adapter to be 'fresh' while restoring state."); } }