Sync prediction client and folders

- Notifies prediction client when a folder is converted into workspace
item as a result of losing all items but one.
- Notifies predction client when a folder is created from an item in the
workspace with no duplicates.

Bug: 148749638
Test: Manual
Change-Id: Ifd51a6fe2a40c8baf4d88e2dba1e5bdc925e1608
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d250658..89c3b93 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -100,6 +100,7 @@
 import com.android.launcher3.dragndrop.DragController;
 import com.android.launcher3.dragndrop.DragLayer;
 import com.android.launcher3.dragndrop.DragView;
+import com.android.launcher3.folder.Folder;
 import com.android.launcher3.folder.FolderGridOrganizer;
 import com.android.launcher3.folder.FolderIcon;
 import com.android.launcher3.graphics.RotationMode;
@@ -1718,8 +1719,8 @@
     /**
      * Creates and adds new folder to CellLayout
      */
-    public FolderIcon addFolder(CellLayout layout, WorkspaceItemInfo info, int container,
-            final int screenId, int cellX, int cellY) {
+    public FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX,
+            int cellY) {
         final FolderInfo folderInfo = new FolderInfo();
         folderInfo.title = "";
 
@@ -1737,6 +1738,16 @@
     }
 
     /**
+     * Called when a workspace item is converted into a folder
+     */
+    public void folderCreatedFromItem(Folder folder, WorkspaceItemInfo itemInfo){}
+
+    /**
+     * Called when a folder is converted into a workspace item
+     */
+    public void folderConvertedToItem(Folder folder, WorkspaceItemInfo itemInfo) {}
+
+    /**
      * Unbinds the view for the specified item, and removes the item and all its children.
      *
      * @param v the view being removed.
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index b725002..b7f8547 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1702,8 +1702,8 @@
             float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation);
             target.removeView(v);
 
-            FolderIcon fi = mLauncher.addFolder(target, sourceInfo, container, screenId,
-                    targetCell[0], targetCell[1]);
+            FolderIcon fi = mLauncher.addFolder(target, container, screenId, targetCell[0],
+                    targetCell[1]);
             destInfo.cellX = -1;
             destInfo.cellY = -1;
             sourceInfo.cellX = -1;
@@ -1722,6 +1722,7 @@
                 fi.addItem(destInfo);
                 fi.addItem(sourceInfo);
             }
+            mLauncher.folderCreatedFromItem(fi.getFolder(), destInfo);
             return true;
         }
         return false;
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 024c7dd..8e80916 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -1109,13 +1109,14 @@
                 int itemCount = getItemCount();
                 if (itemCount <= 1) {
                     View newIcon = null;
+                    WorkspaceItemInfo finalItem = null;
 
                     if (itemCount == 1) {
                         // Move the item from the folder to the workspace, in the position of the
                         // folder
                         CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container,
                                 mInfo.screenId);
-                        WorkspaceItemInfo finalItem = mInfo.contents.remove(0);
+                        finalItem =  mInfo.contents.remove(0);
                         newIcon = mLauncher.createShortcut(cellLayout, finalItem);
                         mLauncher.getModelWriter().addOrMoveItemInDatabase(finalItem,
                                 mInfo.container, mInfo.screenId, mInfo.cellX, mInfo.cellY);
@@ -1136,6 +1137,9 @@
                         // Focus the newly created child
                         newIcon.requestFocus();
                     }
+                    if (finalItem != null) {
+                        mLauncher.folderConvertedToItem(mFolderIcon.getFolder(), finalItem);
+                    }
                 }
             }
         };