2021-06-27 20:44:35 +00:00
package androidx.viewpager2.adapter ;
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.annotation.CallSuper ;
import androidx.annotation.NonNull ;
import androidx.annotation.Nullable ;
import androidx.collection.ArraySet ;
import androidx.collection.LongSparseArray ;
import androidx.core.util.Preconditions ;
import androidx.core.view.ViewCompat ;
import androidx.fragment.app.Fragment ;
import androidx.fragment.app.FragmentActivity ;
import androidx.fragment.app.FragmentManager ;
import androidx.fragment.app.FragmentTransaction ;
import androidx.lifecycle.Lifecycle ;
import androidx.lifecycle.LifecycleEventObserver ;
import androidx.lifecycle.LifecycleOwner ;
import androidx.recyclerview.widget.RecyclerView ;
import androidx.viewpager2.widget.ViewPager2 ;
import c.d.b.a.a ;
public abstract class FragmentStateAdapter extends RecyclerView . Adapter < FragmentViewHolder > implements StatefulAdapter {
private static final long GRACE_WINDOW_TIME_MS = 10000 ;
private static final String KEY_PREFIX_FRAGMENT = " f# " ;
private static final String KEY_PREFIX_STATE = " s# " ;
public final FragmentManager mFragmentManager ;
private FragmentMaxLifecycleEnforcer mFragmentMaxLifecycleEnforcer ;
public final LongSparseArray < Fragment > mFragments ;
private boolean mHasStaleFragments ;
public boolean mIsInGracePeriod ;
private final LongSparseArray < Integer > mItemIdToViewHolder ;
public final Lifecycle mLifecycle ;
private final LongSparseArray < Fragment . SavedState > mSavedStates ;
/* renamed from: androidx.viewpager2.adapter.FragmentStateAdapter$1 reason: invalid class name */
public class AnonymousClass1 implements View . OnLayoutChangeListener {
public final /* synthetic */ FrameLayout val$container ;
public final /* synthetic */ FragmentViewHolder val$holder ;
public AnonymousClass1 ( FrameLayout frameLayout , FragmentViewHolder fragmentViewHolder ) {
this . val$container = frameLayout ;
this . val$holder = fragmentViewHolder ;
}
@Override // android.view.View.OnLayoutChangeListener
public void onLayoutChange ( View view , int i , int i2 , int i3 , int i4 , int i5 , int i6 , int i7 , int i8 ) {
if ( this . val$container . getParent ( ) ! = null ) {
this . val$container . removeOnLayoutChangeListener ( this ) ;
FragmentStateAdapter . this . placeFragmentInViewHolder ( this . val$holder ) ;
}
}
}
/* renamed from: androidx.viewpager2.adapter.FragmentStateAdapter$2 reason: invalid class name */
public class AnonymousClass2 implements LifecycleEventObserver {
public final /* synthetic */ FragmentViewHolder val$holder ;
public AnonymousClass2 ( FragmentViewHolder fragmentViewHolder ) {
this . val$holder = fragmentViewHolder ;
}
@Override // androidx.lifecycle.LifecycleEventObserver
public void onStateChanged ( @NonNull LifecycleOwner lifecycleOwner , @NonNull Lifecycle . Event event ) {
if ( ! FragmentStateAdapter . this . shouldDelayFragmentTransactions ( ) ) {
lifecycleOwner . getLifecycle ( ) . removeObserver ( this ) ;
if ( ViewCompat . isAttachedToWindow ( this . val$holder . getContainer ( ) ) ) {
FragmentStateAdapter . this . placeFragmentInViewHolder ( this . val$holder ) ;
}
}
}
}
/* renamed from: androidx.viewpager2.adapter.FragmentStateAdapter$3 reason: invalid class name */
public class AnonymousClass3 extends FragmentManager . FragmentLifecycleCallbacks {
public final /* synthetic */ FrameLayout val$container ;
public final /* synthetic */ Fragment val$fragment ;
public AnonymousClass3 ( Fragment fragment , FrameLayout frameLayout ) {
this . val$fragment = fragment ;
this . val$container = frameLayout ;
}
@Override // androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
public void onFragmentViewCreated ( @NonNull FragmentManager fragmentManager , @NonNull Fragment fragment , @NonNull View view , @Nullable Bundle bundle ) {
if ( fragment = = this . val$fragment ) {
fragmentManager . unregisterFragmentLifecycleCallbacks ( this ) ;
FragmentStateAdapter . this . addViewToContainer ( view , this . val$container ) ;
}
}
}
/* renamed from: androidx.viewpager2.adapter.FragmentStateAdapter$4 reason: invalid class name */
public class AnonymousClass4 implements Runnable {
public AnonymousClass4 ( ) {
}
@Override // java.lang.Runnable
public void run ( ) {
FragmentStateAdapter fragmentStateAdapter = FragmentStateAdapter . this ;
fragmentStateAdapter . mIsInGracePeriod = false ;
fragmentStateAdapter . gcFragments ( ) ;
}
}
/* renamed from: androidx.viewpager2.adapter.FragmentStateAdapter$5 reason: invalid class name */
public class AnonymousClass5 implements LifecycleEventObserver {
public final /* synthetic */ Handler val$handler ;
public final /* synthetic */ Runnable val$runnable ;
public AnonymousClass5 ( Handler handler , Runnable runnable ) {
this . val$handler = handler ;
this . val$runnable = runnable ;
}
@Override // androidx.lifecycle.LifecycleEventObserver
public void onStateChanged ( @NonNull LifecycleOwner lifecycleOwner , @NonNull Lifecycle . Event event ) {
if ( event = = Lifecycle . Event . ON_DESTROY ) {
this . val$handler . removeCallbacks ( this . val$runnable ) ;
lifecycleOwner . getLifecycle ( ) . removeObserver ( this ) ;
}
}
}
public static abstract class DataSetChangeObserver extends RecyclerView . AdapterDataObserver {
private DataSetChangeObserver ( ) {
}
public /* synthetic */ DataSetChangeObserver ( AnonymousClass1 r1 ) {
this ( ) ;
}
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
public abstract void onChanged ( ) ;
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
public final void onItemRangeChanged ( int i , int i2 ) {
onChanged ( ) ;
}
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
public final void onItemRangeChanged ( int i , int i2 , @Nullable Object obj ) {
onChanged ( ) ;
}
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
public final void onItemRangeInserted ( int i , int i2 ) {
onChanged ( ) ;
}
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
public final void onItemRangeMoved ( int i , int i2 , int i3 ) {
onChanged ( ) ;
}
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
public final void onItemRangeRemoved ( int i , int i2 ) {
onChanged ( ) ;
}
}
public class FragmentMaxLifecycleEnforcer {
private RecyclerView . AdapterDataObserver mDataObserver ;
private LifecycleEventObserver mLifecycleObserver ;
private ViewPager2 . OnPageChangeCallback mPageChangeCallback ;
private long mPrimaryItemId = - 1 ;
private ViewPager2 mViewPager ;
/* renamed from: androidx.viewpager2.adapter.FragmentStateAdapter$FragmentMaxLifecycleEnforcer$1 reason: invalid class name */
public class AnonymousClass1 extends ViewPager2 . OnPageChangeCallback {
public AnonymousClass1 ( ) {
}
@Override // androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
public void onPageScrollStateChanged ( int i ) {
FragmentMaxLifecycleEnforcer . this . updateFragmentMaxLifecycle ( false ) ;
}
@Override // androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
public void onPageSelected ( int i ) {
FragmentMaxLifecycleEnforcer . this . updateFragmentMaxLifecycle ( false ) ;
}
}
/* renamed from: androidx.viewpager2.adapter.FragmentStateAdapter$FragmentMaxLifecycleEnforcer$2 reason: invalid class name */
public class AnonymousClass2 extends DataSetChangeObserver {
public AnonymousClass2 ( ) {
super ( null ) ;
}
@Override // androidx.viewpager2.adapter.FragmentStateAdapter.DataSetChangeObserver, androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
public void onChanged ( ) {
FragmentMaxLifecycleEnforcer . this . updateFragmentMaxLifecycle ( true ) ;
}
}
/* renamed from: androidx.viewpager2.adapter.FragmentStateAdapter$FragmentMaxLifecycleEnforcer$3 reason: invalid class name */
public class AnonymousClass3 implements LifecycleEventObserver {
public AnonymousClass3 ( ) {
}
@Override // androidx.lifecycle.LifecycleEventObserver
public void onStateChanged ( @NonNull LifecycleOwner lifecycleOwner , @NonNull Lifecycle . Event event ) {
FragmentMaxLifecycleEnforcer . this . updateFragmentMaxLifecycle ( false ) ;
}
}
public FragmentMaxLifecycleEnforcer ( ) {
}
@NonNull
private ViewPager2 inferViewPager ( @NonNull RecyclerView recyclerView ) {
ViewParent parent = recyclerView . getParent ( ) ;
if ( parent instanceof ViewPager2 ) {
return ( ViewPager2 ) parent ;
}
throw new IllegalStateException ( " Expected ViewPager2 instance. Got: " + parent ) ;
}
public void register ( @NonNull RecyclerView recyclerView ) {
this . mViewPager = inferViewPager ( recyclerView ) ;
AnonymousClass1 r2 = new AnonymousClass1 ( ) ;
this . mPageChangeCallback = r2 ;
this . mViewPager . registerOnPageChangeCallback ( r2 ) ;
AnonymousClass2 r22 = new AnonymousClass2 ( ) ;
this . mDataObserver = r22 ;
FragmentStateAdapter . this . registerAdapterDataObserver ( r22 ) ;
AnonymousClass3 r23 = new AnonymousClass3 ( ) ;
this . mLifecycleObserver = r23 ;
FragmentStateAdapter . this . mLifecycle . addObserver ( r23 ) ;
}
public void unregister ( @NonNull RecyclerView recyclerView ) {
inferViewPager ( recyclerView ) . unregisterOnPageChangeCallback ( this . mPageChangeCallback ) ;
FragmentStateAdapter . this . unregisterAdapterDataObserver ( this . mDataObserver ) ;
FragmentStateAdapter . this . mLifecycle . removeObserver ( this . mLifecycleObserver ) ;
this . mViewPager = null ;
}
public void updateFragmentMaxLifecycle ( boolean z2 ) {
int currentItem ;
Fragment fragment ;
if ( ! FragmentStateAdapter . this . shouldDelayFragmentTransactions ( ) & & this . mViewPager . getScrollState ( ) = = 0 & & ! FragmentStateAdapter . this . mFragments . isEmpty ( ) & & FragmentStateAdapter . this . getItemCount ( ) ! = 0 & & ( currentItem = this . mViewPager . getCurrentItem ( ) ) < FragmentStateAdapter . this . getItemCount ( ) ) {
long itemId = FragmentStateAdapter . this . getItemId ( currentItem ) ;
if ( ( itemId ! = this . mPrimaryItemId | | z2 ) & & ( fragment = FragmentStateAdapter . this . mFragments . get ( itemId ) ) ! = null & & fragment . isAdded ( ) ) {
this . mPrimaryItemId = itemId ;
FragmentTransaction beginTransaction = FragmentStateAdapter . this . mFragmentManager . beginTransaction ( ) ;
Fragment fragment2 = null ;
for ( int i = 0 ; i < FragmentStateAdapter . this . mFragments . size ( ) ; i + + ) {
long keyAt = FragmentStateAdapter . this . mFragments . keyAt ( i ) ;
Fragment valueAt = FragmentStateAdapter . this . mFragments . valueAt ( i ) ;
if ( valueAt . isAdded ( ) ) {
if ( keyAt ! = this . mPrimaryItemId ) {
beginTransaction . setMaxLifecycle ( valueAt , Lifecycle . State . STARTED ) ;
} else {
fragment2 = valueAt ;
}
valueAt . setMenuVisibility ( keyAt = = this . mPrimaryItemId ) ;
}
}
if ( fragment2 ! = null ) {
beginTransaction . setMaxLifecycle ( fragment2 , Lifecycle . State . RESUMED ) ;
}
if ( ! beginTransaction . isEmpty ( ) ) {
beginTransaction . commitNow ( ) ;
}
}
}
}
}
public FragmentStateAdapter ( @NonNull Fragment fragment ) {
this ( fragment . getChildFragmentManager ( ) , fragment . getLifecycle ( ) ) ;
}
public FragmentStateAdapter ( @NonNull FragmentActivity fragmentActivity ) {
this ( fragmentActivity . getSupportFragmentManager ( ) , fragmentActivity . getLifecycle ( ) ) ;
}
public FragmentStateAdapter ( @NonNull FragmentManager fragmentManager , @NonNull Lifecycle lifecycle ) {
this . mFragments = new LongSparseArray < > ( ) ;
this . mSavedStates = new LongSparseArray < > ( ) ;
this . mItemIdToViewHolder = new LongSparseArray < > ( ) ;
this . mIsInGracePeriod = false ;
this . mHasStaleFragments = false ;
this . mFragmentManager = fragmentManager ;
this . mLifecycle = lifecycle ;
super . setHasStableIds ( true ) ;
}
@NonNull
private static String createKey ( @NonNull String str , long j ) {
2021-07-13 20:23:20 +00:00
return a . p ( str , j ) ;
2021-06-27 20:44:35 +00:00
}
private void ensureFragment ( int i ) {
long itemId = getItemId ( i ) ;
if ( ! this . mFragments . containsKey ( itemId ) ) {
Fragment createFragment = createFragment ( i ) ;
createFragment . setInitialSavedState ( this . mSavedStates . get ( itemId ) ) ;
this . mFragments . put ( itemId , createFragment ) ;
}
}
private boolean isFragmentViewBound ( long j ) {
View view ;
if ( this . mItemIdToViewHolder . containsKey ( j ) ) {
return true ;
}
Fragment fragment = this . mFragments . get ( j ) ;
return ( fragment = = null | | ( view = fragment . getView ( ) ) = = null | | view . getParent ( ) = = null ) ? false : true ;
}
private static boolean isValidKey ( @NonNull String str , @NonNull String str2 ) {
return str . startsWith ( str2 ) & & str . length ( ) > str2 . length ( ) ;
}
private Long itemForViewHolder ( int i ) {
Long l = null ;
for ( int i2 = 0 ; i2 < this . mItemIdToViewHolder . size ( ) ; i2 + + ) {
if ( this . mItemIdToViewHolder . valueAt ( i2 ) . intValue ( ) = = i ) {
if ( l = = null ) {
l = Long . valueOf ( this . mItemIdToViewHolder . keyAt ( i2 ) ) ;
} else {
throw new IllegalStateException ( " Design assumption violated: a ViewHolder can only be bound to one item at a time. " ) ;
}
}
}
return l ;
}
private static long parseIdFromKey ( @NonNull String str , @NonNull String str2 ) {
return Long . parseLong ( str . substring ( str2 . length ( ) ) ) ;
}
private void removeFragment ( long j ) {
ViewParent parent ;
Fragment fragment = this . mFragments . get ( j ) ;
if ( fragment ! = null ) {
if ( ! ( fragment . getView ( ) = = null | | ( parent = fragment . getView ( ) . getParent ( ) ) = = null ) ) {
( ( FrameLayout ) parent ) . removeAllViews ( ) ;
}
if ( ! containsItem ( j ) ) {
this . mSavedStates . remove ( j ) ;
}
if ( ! fragment . isAdded ( ) ) {
this . mFragments . remove ( j ) ;
} else if ( shouldDelayFragmentTransactions ( ) ) {
this . mHasStaleFragments = true ;
} else {
if ( fragment . isAdded ( ) & & containsItem ( j ) ) {
this . mSavedStates . put ( j , this . mFragmentManager . saveFragmentInstanceState ( fragment ) ) ;
}
this . mFragmentManager . beginTransaction ( ) . remove ( fragment ) . commitNow ( ) ;
this . mFragments . remove ( j ) ;
}
}
}
private void scheduleGracePeriodEnd ( ) {
Handler handler = new Handler ( Looper . getMainLooper ( ) ) ;
AnonymousClass4 r1 = new AnonymousClass4 ( ) ;
this . mLifecycle . addObserver ( new AnonymousClass5 ( handler , r1 ) ) ;
handler . postDelayed ( r1 , 10000 ) ;
}
private void scheduleViewAttach ( Fragment fragment , @NonNull FrameLayout frameLayout ) {
this . mFragmentManager . registerFragmentLifecycleCallbacks ( new AnonymousClass3 ( fragment , frameLayout ) , false ) ;
}
public void addViewToContainer ( @NonNull View view , @NonNull FrameLayout frameLayout ) {
if ( frameLayout . getChildCount ( ) > 1 ) {
throw new IllegalStateException ( " Design assumption violated. " ) ;
} else if ( view . getParent ( ) ! = frameLayout ) {
if ( frameLayout . getChildCount ( ) > 0 ) {
frameLayout . removeAllViews ( ) ;
}
if ( view . getParent ( ) ! = null ) {
( ( ViewGroup ) view . getParent ( ) ) . removeView ( view ) ;
}
frameLayout . addView ( view ) ;
}
}
public boolean containsItem ( long j ) {
return j > = 0 & & j < ( ( long ) getItemCount ( ) ) ;
}
@NonNull
public abstract Fragment createFragment ( int i ) ;
public void gcFragments ( ) {
if ( this . mHasStaleFragments & & ! shouldDelayFragmentTransactions ( ) ) {
ArraySet < Long > arraySet = new ArraySet ( ) ;
for ( int i = 0 ; i < this . mFragments . size ( ) ; i + + ) {
long keyAt = this . mFragments . keyAt ( i ) ;
if ( ! containsItem ( keyAt ) ) {
arraySet . add ( Long . valueOf ( keyAt ) ) ;
this . mItemIdToViewHolder . remove ( keyAt ) ;
}
}
if ( ! this . mIsInGracePeriod ) {
this . mHasStaleFragments = false ;
for ( int i2 = 0 ; i2 < this . mFragments . size ( ) ; i2 + + ) {
long keyAt2 = this . mFragments . keyAt ( i2 ) ;
if ( ! isFragmentViewBound ( keyAt2 ) ) {
arraySet . add ( Long . valueOf ( keyAt2 ) ) ;
}
}
}
for ( Long l : arraySet ) {
removeFragment ( l . longValue ( ) ) ;
}
}
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public long getItemId ( int i ) {
return ( long ) i ;
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
@CallSuper
public void onAttachedToRecyclerView ( @NonNull RecyclerView recyclerView ) {
Preconditions . checkArgument ( this . mFragmentMaxLifecycleEnforcer = = null ) ;
FragmentMaxLifecycleEnforcer fragmentMaxLifecycleEnforcer = new FragmentMaxLifecycleEnforcer ( ) ;
this . mFragmentMaxLifecycleEnforcer = fragmentMaxLifecycleEnforcer ;
fragmentMaxLifecycleEnforcer . register ( recyclerView ) ;
}
public final void onBindViewHolder ( @NonNull FragmentViewHolder fragmentViewHolder , int i ) {
long itemId = fragmentViewHolder . getItemId ( ) ;
int id2 = fragmentViewHolder . getContainer ( ) . getId ( ) ;
Long itemForViewHolder = itemForViewHolder ( id2 ) ;
if ( ! ( itemForViewHolder = = null | | itemForViewHolder . longValue ( ) = = itemId ) ) {
removeFragment ( itemForViewHolder . longValue ( ) ) ;
this . mItemIdToViewHolder . remove ( itemForViewHolder . longValue ( ) ) ;
}
this . mItemIdToViewHolder . put ( itemId , Integer . valueOf ( id2 ) ) ;
ensureFragment ( i ) ;
FrameLayout container = fragmentViewHolder . getContainer ( ) ;
if ( ViewCompat . isAttachedToWindow ( container ) ) {
if ( container . getParent ( ) = = null ) {
container . addOnLayoutChangeListener ( new AnonymousClass1 ( container , fragmentViewHolder ) ) ;
} else {
throw new IllegalStateException ( " Design assumption violated. " ) ;
}
}
gcFragments ( ) ;
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
@NonNull
public final FragmentViewHolder onCreateViewHolder ( @NonNull ViewGroup viewGroup , int i ) {
return FragmentViewHolder . create ( viewGroup ) ;
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
@CallSuper
public void onDetachedFromRecyclerView ( @NonNull RecyclerView recyclerView ) {
this . mFragmentMaxLifecycleEnforcer . unregister ( recyclerView ) ;
this . mFragmentMaxLifecycleEnforcer = null ;
}
public final boolean onFailedToRecycleView ( @NonNull FragmentViewHolder fragmentViewHolder ) {
return true ;
}
public final void onViewAttachedToWindow ( @NonNull FragmentViewHolder fragmentViewHolder ) {
placeFragmentInViewHolder ( fragmentViewHolder ) ;
gcFragments ( ) ;
}
public final void onViewRecycled ( @NonNull FragmentViewHolder fragmentViewHolder ) {
Long itemForViewHolder = itemForViewHolder ( fragmentViewHolder . getContainer ( ) . getId ( ) ) ;
if ( itemForViewHolder ! = null ) {
removeFragment ( itemForViewHolder . longValue ( ) ) ;
this . mItemIdToViewHolder . remove ( itemForViewHolder . longValue ( ) ) ;
}
}
public void placeFragmentInViewHolder ( @NonNull FragmentViewHolder fragmentViewHolder ) {
Fragment fragment = this . mFragments . get ( fragmentViewHolder . getItemId ( ) ) ;
if ( fragment ! = null ) {
FrameLayout container = fragmentViewHolder . getContainer ( ) ;
View view = fragment . getView ( ) ;
if ( ! fragment . isAdded ( ) & & view ! = null ) {
throw new IllegalStateException ( " Design assumption violated. " ) ;
} else if ( fragment . isAdded ( ) & & view = = null ) {
scheduleViewAttach ( fragment , container ) ;
} else if ( ! fragment . isAdded ( ) | | view . getParent ( ) = = null ) {
if ( fragment . isAdded ( ) ) {
addViewToContainer ( view , container ) ;
} else if ( ! shouldDelayFragmentTransactions ( ) ) {
scheduleViewAttach ( fragment , container ) ;
FragmentTransaction beginTransaction = this . mFragmentManager . beginTransaction ( ) ;
StringBuilder L = a . L ( " f " ) ;
L . append ( fragmentViewHolder . getItemId ( ) ) ;
beginTransaction . add ( fragment , L . toString ( ) ) . setMaxLifecycle ( fragment , Lifecycle . State . STARTED ) . commitNow ( ) ;
this . mFragmentMaxLifecycleEnforcer . updateFragmentMaxLifecycle ( false ) ;
} else if ( ! this . mFragmentManager . isDestroyed ( ) ) {
this . mLifecycle . addObserver ( new AnonymousClass2 ( fragmentViewHolder ) ) ;
}
} else if ( view . getParent ( ) ! = container ) {
addViewToContainer ( view , container ) ;
}
} else {
throw new IllegalStateException ( " Design assumption violated. " ) ;
}
}
@Override // androidx.viewpager2.adapter.StatefulAdapter
public final void restoreState ( @NonNull Parcelable parcelable ) {
if ( ! this . mSavedStates . isEmpty ( ) | | ! this . mFragments . isEmpty ( ) ) {
throw new IllegalStateException ( " Expected the adapter to be 'fresh' while restoring state. " ) ;
}
Bundle bundle = ( Bundle ) parcelable ;
if ( bundle . getClassLoader ( ) = = null ) {
bundle . setClassLoader ( getClass ( ) . getClassLoader ( ) ) ;
}
for ( String str : bundle . keySet ( ) ) {
if ( isValidKey ( str , " f# " ) ) {
this . mFragments . put ( parseIdFromKey ( str , " f# " ) , this . mFragmentManager . getFragment ( bundle , str ) ) ;
} else if ( isValidKey ( str , " s# " ) ) {
long parseIdFromKey = parseIdFromKey ( str , " s# " ) ;
Fragment . SavedState savedState = ( Fragment . SavedState ) bundle . getParcelable ( str ) ;
if ( containsItem ( parseIdFromKey ) ) {
this . mSavedStates . put ( parseIdFromKey , savedState ) ;
}
} else {
2021-07-13 20:23:20 +00:00
throw new IllegalArgumentException ( a . t ( " Unexpected key in savedState: " , str ) ) ;
2021-06-27 20:44:35 +00:00
}
}
if ( ! this . mFragments . isEmpty ( ) ) {
this . mHasStaleFragments = true ;
this . mIsInGracePeriod = true ;
gcFragments ( ) ;
scheduleGracePeriodEnd ( ) ;
}
}
@Override // androidx.viewpager2.adapter.StatefulAdapter
@NonNull
public final Parcelable saveState ( ) {
Bundle bundle = new Bundle ( this . mSavedStates . size ( ) + this . mFragments . size ( ) ) ;
for ( int i = 0 ; i < this . mFragments . size ( ) ; i + + ) {
long keyAt = this . mFragments . keyAt ( i ) ;
Fragment fragment = this . mFragments . get ( keyAt ) ;
if ( fragment ! = null & & fragment . isAdded ( ) ) {
this . mFragmentManager . putFragment ( bundle , createKey ( " f# " , keyAt ) , fragment ) ;
}
}
for ( int i2 = 0 ; i2 < this . mSavedStates . size ( ) ; i2 + + ) {
long keyAt2 = this . mSavedStates . keyAt ( i2 ) ;
if ( containsItem ( keyAt2 ) ) {
bundle . putParcelable ( createKey ( " s# " , keyAt2 ) , this . mSavedStates . get ( keyAt2 ) ) ;
}
}
return bundle ;
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public final void setHasStableIds ( boolean z2 ) {
throw new UnsupportedOperationException ( " Stable Ids are required for the adapter to function properly, and the adapter takes care of setting the flag. " ) ;
}
public boolean shouldDelayFragmentTransactions ( ) {
return this . mFragmentManager . isStateSaved ( ) ;
}
}