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

Commit 518ca460 authored by Toni Barzic's avatar Toni Barzic
Browse files

Optimize updating hotseat items in overflown taskbar

The logic for updating hotseat items in taskbar involved adding all
available recent items to the view, and then removing ones that
overflow. It also preemptively added overflow icon, and then removed it
when no overflow was detected.

This cl updates logic to stop adding recent items before they cause
overflow, and add overflow icon only when needed.

Bug: 368119679
Test: Keep opening apps until taskbar enters overflow, and verify that
expected number of app icons is displayed, and overflow icon is shown in
the correct place.
Flag: com.android.launcher3.taskbar_overflow

Change-Id: Icaad4386b54bbfccba8ace5876d7fe5c90cb7798
parent 9b093db2
Loading
Loading
Loading
Loading
+21 −42
Original line number Diff line number Diff line
@@ -412,13 +412,33 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
        if (mTaskbarDividerContainer != null && !recentTasks.isEmpty()) {
            addView(mTaskbarDividerContainer, nextViewIndex++);
            mAddedDividerForRecents = true;
            if (mTaskbarOverflowView != null) {
        }

        // At this point, the all apps button has not been added as a child view, but needs to be
        // accounted for when comparing current icon count to max number of icons.
        int nonTaskIconsToBeAdded = 1;

        boolean supportsOverflow = Flags.taskbarOverflow();
        if (supportsOverflow) {
            int numberOfSupportedRecents = 0;
            for (GroupTask task : recentTasks) {
                // TODO(b/343289567 and b/316004172): support app pairs and desktop mode.
                if (!task.hasMultipleTasks()) {
                    ++numberOfSupportedRecents;
                }
            }
            if (nextViewIndex + numberOfSupportedRecents + nonTaskIconsToBeAdded > mMaxNumIcons
                    && mTaskbarOverflowView != null) {
                addView(mTaskbarOverflowView, nextViewIndex++);
            }
        }

        // Add Recent/Running icons.
        for (GroupTask task : recentTasks) {
            if (supportsOverflow && nextViewIndex + nonTaskIconsToBeAdded >= mMaxNumIcons) {
                break;
            }

            // Replace any Recent views with the appropriate type if it's not already that type.
            final int expectedLayoutResId;
            boolean isCollection = false;
@@ -488,8 +508,6 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
            }
        }

        updateRecentAppsToFit();

        if (mActivityContext.getDeviceProfile().isQsbInline) {
            addView(mQsb, mIsRtl ? getChildCount() : 0);
            // Always set QSB to invisible after re-adding.
@@ -497,45 +515,6 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
        }
    }

    /**
     * Updates the recent apps portion of the taskbar by:
     * - Removing overflow affordance if overflow is not needed.
     * - Removing any recent apps that do not fit.
     */
    private void updateRecentAppsToFit() {
        if (!Flags.taskbarOverflow()) {
            return;
        }
        int indexOfFirstRecentApp = -1;
        int size = getChildCount();
        boolean removeOverflowView = true;

        for (int i = 0; i < size; ++i) {
            if (getChildAt(i).getTag() instanceof GroupTask) {
                indexOfFirstRecentApp = i;
                removeOverflowView = false;
                break;
            }
        }

        if (indexOfFirstRecentApp != -1) {
            // We pre-maturely added the overflow icon, so we can take it out of the count.
            int numRecentAppsToRemove = Math.max(0, getChildCount() - mMaxNumIcons + 1);
            if (numRecentAppsToRemove <= 1) {
                // We can fit all of the recent apps if we remove the overflow icon.
                removeOverflowView = true;
            } else {
                for (int i = 0; i < numRecentAppsToRemove; ++i) {
                    removeAndRecycle(getChildAt(indexOfFirstRecentApp));
                }
            }
        }

        if (removeOverflowView) {
            removeView(mTaskbarOverflowView);
        }
    }

    /** Binds the GroupTask to the BubbleTextView to be ready to present to the user. */
    public void applyGroupTaskToBubbleTextView(BubbleTextView btv, GroupTask groupTask) {
        // TODO(b/343289567): support app pairs.