diff options
author | Adam Cohen <adamcohen@google.com> | 2011-06-23 15:38:03 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2011-06-23 18:52:18 -0700 |
commit | afb01ee74243cede19088e694ca82cea5983c603 (patch) | |
tree | 12186d5aadd2cca5cd7b5170ba12ebb1bca24846 /src | |
parent | 4e076545e4ccdbd3c045a3fa33869a2b7519a0cc (diff) | |
download | android_packages_apps_Trebuchet-afb01ee74243cede19088e694ca82cea5983c603.tar.gz android_packages_apps_Trebuchet-afb01ee74243cede19088e694ca82cea5983c603.tar.bz2 android_packages_apps_Trebuchet-afb01ee74243cede19088e694ca82cea5983c603.zip |
Folder auto-destroys itself when there is only one item left.
Change-Id: I4ea41e0730e3dc474a518eba0a04c11167b5c1df
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/Folder.java | 41 | ||||
-rw-r--r-- | src/com/android/launcher2/LauncherModel.java | 26 |
2 files changed, 62 insertions, 5 deletions
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java index 029b89f60..1324a08ed 100644 --- a/src/com/android/launcher2/Folder.java +++ b/src/com/android/launcher2/Folder.java @@ -329,7 +329,7 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL mItemsInvalidated = true; mInfo.addListener(this); - if (sDefaultFolderName != mInfo.title) { + if (!sDefaultFolderName.contentEquals(mInfo.title)) { mFolderName.setText(mInfo.title); } else { mFolderName.setText(""); @@ -784,6 +784,42 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL setupContentForNumItems(getItemCount()); mRearrangeOnClose = false; } + if (getItemCount() <= 1) { + replaceFolderWithFinalItem(); + } + } + + private void replaceFolderWithFinalItem() { + ItemInfo finalItem = null; + + if (getItemCount() == 1) { + finalItem = mInfo.contents.get(0); + } + + // Remove the folder completely + final CellLayout cellLayout = (CellLayout) + mLauncher.getWorkspace().getChildAt(mInfo.screen); + cellLayout.removeView(mFolderIcon); + if (mFolderIcon instanceof DropTarget) { + mDragController.removeDropTarget((DropTarget) mFolderIcon); + } + mLauncher.removeFolder(mInfo); + + if (finalItem != null) { + LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, + LauncherSettings.Favorites.CONTAINER_DESKTOP, mInfo.screen, + mInfo.cellX, mInfo.cellY); + } + LauncherModel.deleteFolderContentsFromDatabase(mLauncher, mInfo, true); + + // Add the last remaining child to the workspace in place of the folder + if (finalItem != null) { + View child = mLauncher.createShortcut(R.layout.application, cellLayout, + (ShortcutInfo) finalItem); + + mLauncher.getWorkspace().addInScreen(child, mInfo.screen, mInfo.cellX, mInfo.cellY, + mInfo.spanX, mInfo.spanY); + } } public void onDrop(DragObject d) { @@ -833,6 +869,9 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL } else { setupContentForNumItems(getItemCount()); } + if (getItemCount() <= 1) { + replaceFolderWithFinalItem(); + } } public void onItemsChanged() { diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index 7cfab2a17..a79a968dc 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -380,15 +380,33 @@ public class LauncherModel extends BroadcastReceiver { }); } + static void deleteFolderContentsFromDatabase(Context context, final FolderInfo info) { + deleteFolderContentsFromDatabase(context, info, false); + } + /** * Remove the contents of the specified folder from the database */ - static void deleteFolderContentsFromDatabase(Context context, FolderInfo info) { + static void deleteFolderContentsFromDatabase(Context context, final FolderInfo info, + boolean post) { + // TODO: this post flag is temporary to fix an ordering of commands issue. In future, + // all db operations will be moved to the worker thread, so this can be discarded at + // that time. final ContentResolver cr = context.getContentResolver(); - cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null); - cr.delete(LauncherSettings.Favorites.CONTENT_URI, - LauncherSettings.Favorites.CONTAINER + "=" + info.id, null); + if (!post) { + cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null); + cr.delete(LauncherSettings.Favorites.CONTENT_URI, + LauncherSettings.Favorites.CONTAINER + "=" + info.id, null); + } else { + sWorker.post(new Runnable() { + public void run() { + cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null); + cr.delete(LauncherSettings.Favorites.CONTENT_URI, + LauncherSettings.Favorites.CONTAINER + "=" + info.id, null); + } + }); + } } /** |