Merge "Add GroupedTaskView to recents view only if needed" into sc-v2-dev
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 646312e..18387dc 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1278,7 +1278,8 @@
             while (getTaskViewCount() > requiredTaskViewCount) {
                 removeView(getChildAt(getChildCount() - 1));
             }
-            while (requiredGroupTaskViews > 0) {
+            int groupedTaskViewCount = getGroupedTaskViewCount();
+            while (requiredGroupTaskViews > groupedTaskViewCount) {
                 // Add to front of list
                 addView(getTaskViewFromPool(true), 0);
                 requiredGroupTaskViews--;
@@ -1405,6 +1406,16 @@
         return taskViewCount;
     }
 
+    public int getGroupedTaskViewCount() {
+        int groupViewCount = 0;
+        for (int i = 0; i < getChildCount(); i++) {
+            if (getChildAt(i) instanceof GroupedTaskView) {
+                groupViewCount++;
+            }
+        }
+        return groupViewCount;
+    }
+
     protected void onTaskStackUpdated() {
         // Lazily update the empty message only when the task stack is reapplied
         updateEmptyMessage();