Update existing Folder items' ranks to match their pre-permutation layouts.

With the new Folder permutation logic, we change the position of the items
when they are added to a Folder. This means that existing Folders will
now appear in a different order than the user arranged them in.

This change makes sure that when a user upgrades, their existing Folders
will appear untouched.

Note: We decided to priotize restoring the original layout of the Folder,
      as opposed to making sure the preview items remain the same. This
      is less destructive of users' data (we're changing the window into
      the Folder, but not the location of items when the Folder is open).

Bug: 63115141
Bug: 35064148

Change-Id: Ib0a28b4b50be089878ffc3e40bced89832e125bc
This commit is contained in:
Jon Miranda
2017-06-28 15:15:12 -07:00
parent 59fbea393b
commit c4b296a50e
3 changed files with 113 additions and 11 deletions

View File

@@ -755,6 +755,10 @@ public class FolderPagedView extends PagedView {
return mMaxItemsPerPage;
}
public int getReadingOrderPosForRank(int rank) {
return getReadingOrderPosForRank(rank, mMaxItemsPerPage, mGridCountX, sTmpArray);
}
/**
* Returns the reading order position for a given rank.
*
@@ -763,34 +767,44 @@ public class FolderPagedView extends PagedView {
*
* R0 R1 R4
* R2 R3 R5
*
* @param outXY If notnull, we also return the cell X/Y position.
*/
public int getReadingOrderPosForRank(int rank) {
if (rank >= mMaxItemsPerPage) {
public static int getReadingOrderPosForRank(int rank, int maxItemsPerPage, int gridX,
int[] outXY) {
outXY = outXY == null ? sTmpArray : outXY;
getCellXYPositionForRank(rank, maxItemsPerPage, gridX, outXY);
if (rank >= maxItemsPerPage) {
return rank;
}
getCellXYPositionForRank(rank, sTmpArray);
return sTmpArray[0] + (mGridCountX * sTmpArray[1]);
return outXY[0] + (gridX * outXY[1]);
}
public void getCellXYPositionForRank(int rank, int[] outXY) {
getCellXYPositionForRank(rank, mMaxItemsPerPage, mGridCountX, outXY);
}
/**
* Returns the cell XY position for a Folder item with the given rank.
*/
public void getCellXYPositionForRank(int rank, int[] outXY) {
boolean onFirstPage = rank < mMaxItemsPerPage;
public static void getCellXYPositionForRank(int rank, int maxItemsPerPage, int gridX,
int[] outXY) {
boolean onFirstPage = rank < maxItemsPerPage;
if (onFirstPage && mGridCountX == 3) {
if (onFirstPage && gridX == 3) {
outXY[0] = FolderPermutation.THREE_COLS[rank][0];
outXY[1] = FolderPermutation.THREE_COLS[rank][1];
} else if (onFirstPage && mGridCountX == 4) {
} else if (onFirstPage && gridX == 4) {
outXY[0] = FolderPermutation.FOUR_COLS[rank][0];
outXY[1] = FolderPermutation.FOUR_COLS[rank][1];
} else if (onFirstPage && mGridCountX == 5) {
} else if (onFirstPage && gridX == 5) {
outXY[0] = FolderPermutation.FIVE_COLS[rank][0];
outXY[1] = FolderPermutation.FIVE_COLS[rank][1];
} else {
outXY[0] = (rank % mMaxItemsPerPage) % mGridCountX;
outXY[1] = (rank % mMaxItemsPerPage) / mGridCountX;
outXY[0] = (rank % maxItemsPerPage) % gridX;
outXY[1] = (rank % maxItemsPerPage) / gridX;
}
}