Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15a12f3a authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing task start index not getting updated on all View add/remove calls

Change-Id: Icbd3cd7e9cee33d2f91546ff4efcf6abfa474e1e
parent 59431db5
Loading
Loading
Loading
Loading
+23 −32
Original line number Diff line number Diff line
@@ -508,6 +508,29 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
            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 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        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 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        }
    }

    @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.
     *