Trying to track down corrupt database / items disappearing

-> Adding logs for all database transactions
-> Adding sanity checks for items in folders, throwing exceptions
   if they are violated
-> Reducing database upates when re-arranging items, only
   update if values have changed
-> Removed some dead code from ItemInfo (isGesture?)

Change-Id: Ia5cd57d92082f633dbf4aa5d64612cbae2d82bb4
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java
index 84c815e..ae7ee6e 100644
--- a/src/com/android/launcher2/Folder.java
+++ b/src/com/android/launcher2/Folder.java
@@ -951,16 +951,6 @@
             public void run() {
                 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen);
 
-                if (getItemCount() <= 1) {
-                    // Remove the folder
-                    LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
-                    cellLayout.removeView(mFolderIcon);
-                    if (mFolderIcon instanceof DropTarget) {
-                        mDragController.removeDropTarget((DropTarget) mFolderIcon);
-                    }
-                    mLauncher.removeFolder(mInfo);
-                }
-
                 // Move the item from the folder to the workspace, in the position of the folder
                 if (getItemCount() == 1) {
                     ShortcutInfo finalItem = mInfo.contents.get(0);
@@ -973,6 +963,15 @@
                             mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
                 }
 
+                if (getItemCount() <= 1) {
+                    // Remove the folder
+                    LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
+                    cellLayout.removeView(mFolderIcon);
+                    if (mFolderIcon instanceof DropTarget) {
+                        mDragController.removeDropTarget((DropTarget) mFolderIcon);
+                    }
+                    mLauncher.removeFolder(mInfo);
+                }
             }
         };
         View finalChild = getItemAt(0);