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

Commit 1eb82adf authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Fix work badge becoming black in groups

Also make sure the icons disappear in child notifications properly.

Fix: 376689932
Bug: 371174789
Test: post two notifications from the work profile so they get grouped,
check that the workbadge is still blue
Flag: android.app.notifications_redesign_app_icons

Change-Id: I30f878982b07e696caa792273968179e1a1ecd5c
parent 70d69921
Loading
Loading
Loading
Loading
+27 −27
Original line number Diff line number Diff line
@@ -61,15 +61,6 @@ public class NotificationGroupingUtil {
            return row.getEntry().getSbn().getNotification();
        }
    };
    private static final ResultApplicator GREY_APPLICATOR = new ResultApplicator() {
        @Override
        public void apply(View parent, View view, boolean apply, boolean reset) {
            CachingIconView icon = view.findViewById(com.android.internal.R.id.icon);
            if (icon != null) {
                icon.setGrayedOut(apply);
            }
        }
    };

    private final ExpandableNotificationRow mRow;
    private final ArrayList<Processor> mProcessors = new ArrayList<>();
@@ -78,14 +69,18 @@ public class NotificationGroupingUtil {
    public NotificationGroupingUtil(ExpandableNotificationRow row) {
        mRow = row;

        final IconComparator iconVisibilityComparator = new IconComparator(mRow) {
        final IconComparator iconVisibilityComparator = new IconComparator() {
            public boolean compare(View parent, View child, Object parentData,
                    Object childData) {
                if (Flags.notificationsRedesignAppIcons() && mRow.isShowingAppIcon()) {
                    // Icon is always the same when we're showing the app icon.
                    return true;
                }
                return hasSameIcon(parentData, childData)
                        && hasSameColor(parentData, childData);
            }
        };
        final IconComparator greyComparator = new IconComparator(mRow) {
        final IconComparator greyComparator = new IconComparator() {
            public boolean compare(View parent, View child, Object parentData,
                    Object childData) {
                if (Flags.notificationsRedesignAppIcons() && mRow.isShowingAppIcon()) {
@@ -95,6 +90,19 @@ public class NotificationGroupingUtil {
                        || hasSameColor(parentData, childData);
            }
        };
        final ResultApplicator greyApplicator = new ResultApplicator() {
            @Override
            public void apply(View parent, View view, boolean apply, boolean reset) {
                if (Flags.notificationsRedesignAppIcons() && mRow.isShowingAppIcon()) {
                    // Do nothing.
                    return;
                }
                CachingIconView icon = view.findViewById(com.android.internal.R.id.icon);
                if (icon != null) {
                    icon.setGrayedOut(apply);
                }
            }
        };

        // To hide the icons if they are the same and the color is the same
        mProcessors.add(new Processor(mRow,
@@ -107,7 +115,7 @@ public class NotificationGroupingUtil {
                com.android.internal.R.id.status_bar_latest_event_content,
                ICON_EXTRACTOR,
                greyComparator,
                GREY_APPLICATOR));
                greyApplicator));
        // To show the large icon on the left side instead if all the small icons are the same
        mProcessors.add(new Processor(mRow,
                com.android.internal.R.id.status_bar_latest_event_content,
@@ -326,6 +334,7 @@ public class NotificationGroupingUtil {
         * @return whether to views are the same
         */
        boolean compare(View parent, View child, Object parentData, Object childData);

        boolean isEmpty(View view);
    }

@@ -368,21 +377,12 @@ public class NotificationGroupingUtil {
    }

    private abstract static class IconComparator implements ViewComparator {
        private final ExpandableNotificationRow mRow;

        IconComparator(ExpandableNotificationRow row) {
            mRow = row;
        }

        @Override
        public boolean compare(View parent, View child, Object parentData, Object childData) {
            return false;
        }

        protected boolean hasSameIcon(Object parentData, Object childData) {
            if (Flags.notificationsRedesignAppIcons() && mRow.isShowingAppIcon()) {
                return true;
            }
            Icon parentIcon = getIcon((Notification) parentData);
            Icon childIcon = getIcon((Notification) childData);
            return parentIcon.sameAs(childIcon);