Merge "Revert "Introduce `mTaskViewCount` inside the RecentsView"" into main
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index a382a05..770a659 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -849,8 +849,6 @@
 
     private final Matrix mTmpMatrix = new Matrix();
 
-    private int mTaskViewCount = 0;
-
     @Nullable
     public TaskView getFirstTaskView() {
         return mUtils.getFirstTaskView();
@@ -1253,11 +1251,9 @@
         // - It's the initial taskview for entering split screen, we only pretend to dismiss the
         // task
         // - It's the focused task to be moved to the front, we immediately re-add the task
-        if (child instanceof TaskView) {
-            mTaskViewCount = Math.max(0, --mTaskViewCount);
-            if (child != mSplitHiddenTaskView && child != mMovingTaskView) {
-                clearAndRecycleTaskView((TaskView) child);
-            }
+        if (child instanceof TaskView && child != mSplitHiddenTaskView
+                && child != mMovingTaskView) {
+            clearAndRecycleTaskView((TaskView) child);
         }
     }
 
@@ -1278,9 +1274,6 @@
     @Override
     public void onViewAdded(View child) {
         super.onViewAdded(child);
-        if (child instanceof TaskView) {
-            mTaskViewCount++;
-        }
         child.setAlpha(mContentAlpha);
         // RecentsView is set to RTL in the constructor when system is using LTR. Here we set the
         // child direction back to match system settings.
@@ -2095,7 +2088,11 @@
     }
 
     public int getTaskViewCount() {
-        return mTaskViewCount;
+        int taskViewCount = getChildCount();
+        if (indexOfChild(mClearAllButton) != -1) {
+            taskViewCount--;
+        }
+        return taskViewCount;
     }
 
     /**
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index b05a46d..0ec3b79 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -903,14 +903,12 @@
     @Override
     public void onViewAdded(View child) {
         super.onViewAdded(child);
-        mPageScrolls = null;
         dispatchPageCountChanged();
     }
 
     @Override
     public void onViewRemoved(View child) {
         super.onViewRemoved(child);
-        mPageScrolls = null;
         runOnPageScrollsInitialized(() -> {
             mCurrentPage = validateNewPage(mCurrentPage);
             mCurrentScrollOverPage = mCurrentPage;