From 4045eb736e76374ec8b53b4cea2eaea47c72db4a Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Thu, 6 Oct 2011 11:44:26 -0700 Subject: [PATCH] Fixing folder order persistence, issue 5422712 Change-Id: I72d99274b581a803f01042e1de979c59faa4684b --- src/com/android/launcher2/Folder.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java index 8a198f8757..019ac70000 100644 --- a/src/com/android/launcher2/Folder.java +++ b/src/com/android/launcher2/Folder.java @@ -678,6 +678,20 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mCurrentDragInfo = null; mCurrentDragView = null; mSuppressOnAdd = false; + + // Reordering may have occured, and we need to save the new item locations. We do this once + // at the end to prevent unnecessary database operations. + updateItemLocationsInDatabase(); + } + + private void updateItemLocationsInDatabase() { + ArrayList list = getItemsInReadingOrder(); + for (int i = 0; i < list.size(); i++) { + View v = list.get(i); + ItemInfo info = (ItemInfo) v.getTag(); + LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0, + info.cellX, info.cellY); + } } public void notifyDrop() { @@ -694,7 +708,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList return null; } - private void setupContentDimension(int count) { + private void setupContentDimensions(int count) { ArrayList list = getItemsInReadingOrder(); int countX = mContent.getCountX(); @@ -783,7 +797,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } private void setupContentForNumItems(int count) { - setupContentDimension(count); + setupContentDimensions(count); DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); if (lp == null) { @@ -933,7 +947,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mCurrentDragView.setVisibility(VISIBLE); } mItemsInvalidated = true; - setupContentDimension(getItemCount()); + setupContentDimensions(getItemCount()); mSuppressOnAdd = true; } mInfo.add(item);