@@ -50,11 +50,6 @@ public class FanLayoutManager extends RecyclerView.LayoutManager {
5050 */
5151 private final FanLayoutManagerSettings mSettings ;
5252
53- /**
54- * Map with view (card) rotations. This need to save bounce rotations for views.
55- * {@link #updateArcViewPositions}
56- */
57- private final SparseArray <Float > mViewRotationsMap = new SparseArray <>();
5853 /**
5954 * Map with view cache.
6055 */
@@ -73,6 +68,12 @@ public class FanLayoutManager extends RecyclerView.LayoutManager {
7368 */
7469 private final Random mRandom = new Random ();
7570
71+ /**
72+ * Map with view (card) rotations. This need to save bounce rotations for views.
73+ * {@link #updateArcViewPositions}
74+ */
75+ private SparseArray <Float > mViewRotationsMap = new SparseArray <>();
76+
7677 /**
7778 * Helper module need to implement 'open','close', 'shift' views functionality.
7879 * By default using {@link AnimationHelperImpl}
@@ -145,6 +146,7 @@ public class FanLayoutManager extends RecyclerView.LayoutManager {
145146
146147 public FanLayoutManager (@ NonNull Context context ) {
147148 this (context , null );
149+ mAnimationHelper = new AnimationHelperImpl ();
148150 }
149151
150152 public FanLayoutManager (@ NonNull Context context , @ Nullable FanLayoutManagerSettings settings ) {
@@ -175,7 +177,7 @@ public void saveState() {
175177 // save collapsed state for views
176178 mPendingSavedState .isCollapsed = mIsCollapsed ;
177179 // center view position
178- mScrollToPosition = mPendingSavedState . mCenterItemPosition ;
180+ mPendingSavedState . mRotation = mViewRotationsMap ;
179181 }
180182
181183 @ Override
@@ -184,6 +186,8 @@ public Parcelable onSaveInstanceState() {
184186 return mPendingSavedState ;
185187 }
186188
189+ // I'm sure in all casts
190+ @ SuppressWarnings ("unchecked" )
187191 @ Override
188192 public void onRestoreInstanceState (Parcelable state ) {
189193 if (state != null && state instanceof FanLayoutManager .SavedState ) {
@@ -196,6 +200,8 @@ public void onRestoreInstanceState(Parcelable state) {
196200 mIsSelected = mPendingSavedState .isSelected ;
197201 // collapsed state
198202 mIsCollapsed = mPendingSavedState .isCollapsed ;
203+ // rotation state
204+ mViewRotationsMap = mPendingSavedState .mRotation ;
199205 }
200206 }
201207
@@ -325,12 +331,18 @@ public boolean canScrollHorizontally() {
325331
326332 @ Override
327333 public int scrollHorizontallyBy (int dx , RecyclerView .Recycler recycler , RecyclerView .State state ) {
328-
329334 // after fillRightFromCenter(...) we don't need this param.
330335 mScrollToPosition = RecyclerView .NO_POSITION ;
331- // after fillRightFromCenter(...) we don't need this param.
336+ // // after fillRightFromCenter(...) we don't need this param.
332337 mPendingSavedState = null ;
333338
339+ if (dx == RecyclerView .NO_POSITION ) {
340+ int delta = scrollHorizontallyInternal (dx );
341+ offsetChildrenHorizontal (-delta );
342+ fill (recycler );
343+ return delta ;
344+ }
345+
334346 if (mSelectedItemPosition != RecyclerView .NO_POSITION && !mIsSelectAnimationInProcess && !mIsDeselectAnimationInProcess &&
335347 !mIsWaitingToDeselectAnimation && !mIsWaitingToSelectAnimation ) {
336348 // if item selected and any animation isn't in progress
@@ -340,7 +352,6 @@ public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, Recycler
340352 if (mIsDeselectAnimationInProcess || mIsSelectAnimationInProcess || mIsViewCollapsing ) {
341353 return 0 ;
342354 }
343- //
344355 int delta = scrollHorizontallyInternal (dx );
345356 offsetChildrenHorizontal (-delta );
346357 fill (recycler );
@@ -662,7 +673,6 @@ public boolean isItemSelected() {
662673
663674
664675 private void selectItem (final int position , int delay ) {
665-
666676 if (mSelectedItemPosition == position ) {
667677 // if select already selected item
668678 deselectItem (mSelectedItemPosition );
@@ -789,6 +799,8 @@ public void onAnimationEnd(Animator animator) {
789799 */
790800
791801 private void closeItem (final RecyclerView recyclerView , final int position , final int scrollToPosition , final int delay ) {
802+ // wait for start deselect animation
803+ mIsWaitingToDeselectAnimation = true ;
792804 // search view by position
793805 View viewToDeselect = null ;
794806 for (int count = getChildCount (), i = 0 ; i < count ; i ++) {
@@ -809,9 +821,6 @@ private void closeItem(final RecyclerView recyclerView, final int position, fina
809821 return ;
810822 }
811823
812- // wait for start deselect animation
813- mIsWaitingToDeselectAnimation = true ;
814-
815824 // close item animation
816825 mAnimationHelper .closeItem (viewToDeselect , delay , new SimpleAnimatorListener () {
817826 @ Override
@@ -1014,6 +1023,8 @@ public void restoreBaseRotationSelectedItem(final Animator.AnimatorListener list
10141023 }
10151024
10161025 if (viewToRotate != null ) {
1026+ // save state
1027+ mIsSelectedItemStraightenedInProcess = true ;
10171028
10181029 // start straight animation
10191030 mAnimationHelper .rotateView (viewToRotate , baseViewRotation , new Animator .AnimatorListener () {
@@ -1050,9 +1061,6 @@ public void onAnimationRepeat(Animator animation) {
10501061 }
10511062 }
10521063 });
1053-
1054- // save state
1055- mIsSelectedItemStraightenedInProcess = true ;
10561064 }
10571065 }
10581066
@@ -1225,6 +1233,7 @@ public FanLayoutManager.SavedState[] newArray(int size) {
12251233 int mCenterItemPosition = RecyclerView .NO_POSITION ;
12261234 boolean isCollapsed ;
12271235 boolean isSelected ;
1236+ SparseArray mRotation ;
12281237
12291238 public SavedState () {
12301239
@@ -1234,24 +1243,28 @@ public SavedState() {
12341243 mCenterItemPosition = in .readInt ();
12351244 isCollapsed = in .readInt () == 1 ;
12361245 isSelected = in .readInt () == 1 ;
1246+ mRotation = in .readSparseArray (getClass ().getClassLoader ());
12371247 }
12381248
12391249 public SavedState (FanLayoutManager .SavedState other ) {
12401250 mCenterItemPosition = other .mCenterItemPosition ;
12411251 isCollapsed = other .isCollapsed ;
12421252 isSelected = other .isSelected ;
1253+ mRotation = other .mRotation ;
12431254 }
12441255
12451256 @ Override
12461257 public int describeContents () {
12471258 return 0 ;
12481259 }
12491260
1261+ @ SuppressWarnings ("unchecked" )
12501262 @ Override
12511263 public void writeToParcel (Parcel dest , int flags ) {
12521264 dest .writeInt (mCenterItemPosition );
12531265 dest .writeInt (isCollapsed ? 1 : 0 );
12541266 dest .writeInt (isSelected ? 1 : 0 );
1267+ dest .writeSparseArray (mRotation );
12551268 }
12561269 }
12571270
0 commit comments