Fixing task start index not getting updated on all View add/remove calls
Change-Id: Icbd3cd7e9cee33d2f91546ff4efcf6abfa474e1e
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
index 5e8c232..2bf522b 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -508,6 +508,29 @@
mHasVisibleTaskData.delete(taskView.getTask().key.id);
mTaskViewPool.recycle(taskView);
}
+ updateTaskStartIndex(child);
+ }
+
+ @Override
+ public void onViewAdded(View child) {
+ super.onViewAdded(child);
+ 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.
+ child.setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_LTR : View.LAYOUT_DIRECTION_RTL);
+ updateTaskStartIndex(child);
+ }
+
+ private void updateTaskStartIndex(View affectingView) {
+ if (!(affectingView instanceof TaskView) && !(affectingView instanceof ClearAllButton)) {
+ int childCount = getChildCount();
+
+ mTaskViewStartIndex = 0;
+ while (mTaskViewStartIndex < childCount
+ && !(getChildAt(mTaskViewStartIndex) instanceof TaskView)) {
+ mTaskViewStartIndex++;
+ }
+ }
}
public boolean isTaskViewVisible(TaskView tv) {
@@ -1556,12 +1579,6 @@
return mOrientationHandler;
}
- @Override
- public void onViewAdded(View child) {
- super.onViewAdded(child);
- child.setAlpha(mContentAlpha);
- }
-
@Nullable
public TaskView getNextTaskView() {
return getTaskViewAtByAbsoluteIndex(getRunningTaskIndex() + 1);
@@ -2069,37 +2086,11 @@
}
}
- @Override
- public void addView(View child, int index) {
- // RecentsView is set to RTL in the constructor when system is using LTR. Here we set the
- // child direction back to match system settings.
- child.setLayoutDirection(
- Utilities.isRtl(getResources())
- ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
- super.addView(child, index);
- if (isExtraCardView(child, index)) {
- mTaskViewStartIndex++;
- }
- }
-
- @Override
- public void removeView(View view) {
- if (isExtraCardView(view, indexOfChild(view))) {
- mTaskViewStartIndex--;
- }
- super.removeView(view);
- }
-
@Nullable
protected DepthController getDepthController() {
return null;
}
- private boolean isExtraCardView(View view, int index) {
- return !(view instanceof TaskView) && !(view instanceof ClearAllButton)
- && index <= mTaskViewStartIndex;
- }
-
/**
* Used to register callbacks for when our empty message state changes.
*