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

Commit be7f84d5 authored by Sebastian Franco's avatar Sebastian Franco
Browse files

Adding a case when there is only 1 system shortcut on the Popup Container

When there is only 1 system shortcut the Popup Container looks weird
because it shows the icon without text and it has a lot of space.

We already have a view to show the sorcuts with text and icons so I
reused that view and show it only if there is 1 system shortcut.

I also did a small refactor separating the sortcuts into
widgetShortcuts and nonWidgetShortcuts. The way I did it is not the
most efficient because it uses two passes, but I think it is easier to
read this way and we'll never have too many shortcuts.

Fix: 229356716
Test: Long press on the app icons in the workspace and in the
app drawer. Try different app some with one shortcut like the phone
app and some with multiple like.

Change-Id: Ie054af546758d0686914fc934772a76a3c690fe5
parent c6df6eda
Loading
Loading
Loading
Loading
+46 −29
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
@@ -244,23 +245,32 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
                mNotificationContainer);
    }

    private void initializeSystemShortcuts(List<SystemShortcut> shortcuts) {
        if (shortcuts.isEmpty()) {
            return;
        }
        // If there is only 1 shortcut, add it to its own container so it can show text and icon
        if (shortcuts.size() == 1) {
            initializeSystemShortcut(R.layout.system_shortcut, this, shortcuts.get(0));
            return;
        }
        mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons, this);
        for (SystemShortcut shortcut : shortcuts) {
            initializeSystemShortcut(
                    R.layout.system_shortcut_icon_only, mSystemShortcutContainer,
                    shortcut);
        }
    }

    @TargetApi(Build.VERSION_CODES.P)
    public void populateAndShow(final BubbleTextView originalIcon, int shortcutCount,
            final List<NotificationKeyData> notificationKeys, List<SystemShortcut> systemShortcuts) {
            final List<NotificationKeyData> notificationKeys, List<SystemShortcut> shortcuts) {
        mNumNotifications = notificationKeys.size();
        mOriginalIcon = originalIcon;

        boolean hasDeepShortcuts = shortcutCount > 0;
        mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width);

        // if there are deep shortcuts, we might want to increase the width of shortcuts to fit
        // horizontally laid out system shortcuts.
        if (hasDeepShortcuts) {
            mContainerWidth = Math.max(mContainerWidth,
                    systemShortcuts.size() * getResources()
                            .getDimensionPixelSize(R.dimen.system_shortcut_header_icon_touch_size)
            );
        }
        // Add views
        if (mNumNotifications > 0) {
            // Add notification entries
@@ -279,6 +289,24 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
            mDeepShortcutContainer = findViewById(R.id.deep_shortcuts_container);
        }
        if (hasDeepShortcuts) {
            // Remove the widget shortcut fom the list
            List<SystemShortcut> systemShortcuts = shortcuts
                    .stream()
                    .filter(shortcut -> !(shortcut instanceof SystemShortcut.Widgets))
                    .collect(Collectors.toList());
            Optional<SystemShortcut.Widgets> widgetShortcutOpt = shortcuts
                    .stream()
                    .filter(shortcut -> shortcut instanceof SystemShortcut.Widgets)
                    .map(SystemShortcut.Widgets.class::cast)
                    .findFirst();

            // if there are deep shortcuts, we might want to increase the width of shortcuts to fit
            // horizontally laid out system shortcuts.
            mContainerWidth = Math.max(mContainerWidth,
                    systemShortcuts.size() * getResources()
                            .getDimensionPixelSize(R.dimen.system_shortcut_header_icon_touch_size)
            );

            mDeepShortcutContainer.setVisibility(View.VISIBLE);

            for (int i = shortcutCount; i > 0; i--) {
@@ -288,30 +316,19 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
            }
            updateHiddenShortcuts();

            if (!systemShortcuts.isEmpty()) {
                for (SystemShortcut shortcut : systemShortcuts) {
                    if (shortcut instanceof SystemShortcut.Widgets) {
            if (widgetShortcutOpt.isPresent()) {
                if (mWidgetContainer == null) {
                    mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container,
                            this);
                }
                        initializeWidgetShortcut(mWidgetContainer, shortcut);
                initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get());
            }
                }
                mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons, this);

                for (SystemShortcut shortcut : systemShortcuts) {
                    if (!(shortcut instanceof SystemShortcut.Widgets)) {
                        initializeSystemShortcut(
                                R.layout.system_shortcut_icon_only, mSystemShortcutContainer,
                                shortcut);
                    }
                }
            }
            initializeSystemShortcuts(systemShortcuts);
        } else {
            mDeepShortcutContainer.setVisibility(View.GONE);
            if (!systemShortcuts.isEmpty()) {
                for (SystemShortcut shortcut : systemShortcuts) {
            if (!shortcuts.isEmpty()) {
                for (SystemShortcut shortcut : shortcuts) {
                    initializeSystemShortcut(R.layout.system_shortcut, this, shortcut);
                }
            }