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

Commit 84e9264f authored by Danny Baumann's avatar Danny Baumann Committed by Gerrit Code Review
Browse files

Update default public notification view on notification update.

When not doing that the notification view on lockscreen keeps outdated
icon, color and/or event time.

Change-Id: I5f042b80f68619a2c5b29b455294a0d928f9c33e
parent 0e9c897c
Loading
Loading
Loading
Loading
+58 −41
Original line number Diff line number Diff line
@@ -1427,49 +1427,12 @@ public abstract class BaseStatusBar extends SystemUI implements
                title.setText(entry.notification.getPackageName());
            }

            final ImageView icon = (ImageView) publicViewLocal.findViewById(R.id.icon);
            final ImageView profileBadge = (ImageView) publicViewLocal.findViewById(
                    R.id.profile_badge_line3);

            final StatusBarIcon ic = new StatusBarIcon(
                    entry.notification.getUser(),
                    entry.notification.getPackageName(),
                    entry.notification.getNotification().getSmallIcon(),
                    entry.notification.getNotification().iconLevel,
                    entry.notification.getNotification().number,
                    entry.notification.getNotification().tickerText);

            Drawable iconDrawable = StatusBarIconView.getIcon(mContext, ic);
            icon.setImageDrawable(iconDrawable);
            if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP
                    || mNotificationColorUtil.isGrayscaleIcon(iconDrawable)) {
                icon.setBackgroundResource(
                        com.android.internal.R.drawable.notification_icon_legacy_bg);
                int padding = mContext.getResources().getDimensionPixelSize(
                        com.android.internal.R.dimen.notification_large_icon_circle_padding);
                icon.setPadding(padding, padding, padding, padding);
                if (sbn.getNotification().color != Notification.COLOR_DEFAULT) {
                    icon.getBackground().setColorFilter(
                            sbn.getNotification().color, PorterDuff.Mode.SRC_ATOP);
                }
            }

            if (profileBadge != null) {
                Drawable profileDrawable = mContext.getPackageManager().getUserBadgeForDensity(
                        entry.notification.getUser(), 0);
                if (profileDrawable != null) {
                    profileBadge.setImageDrawable(profileDrawable);
                    profileBadge.setVisibility(View.VISIBLE);
                } else {
                    profileBadge.setVisibility(View.GONE);
                }
            }
            updatePublicViewProperties(publicViewLocal, entry);

            final View privateTime = contentViewLocal.findViewById(com.android.internal.R.id.time);
            final DateTimeView time = (DateTimeView) publicViewLocal.findViewById(R.id.time);
            if (privateTime != null && privateTime.getVisibility() == View.VISIBLE) {
                time.setVisibility(View.VISIBLE);
                time.setTime(entry.notification.getNotification().when);
            }

            final TextView text = (TextView) publicViewLocal.findViewById(R.id.text);
@@ -2075,6 +2038,7 @@ public abstract class BaseStatusBar extends SystemUI implements
        final Notification publicVersion = notification.getNotification().publicVersion;
        final RemoteViews publicContentView = publicVersion != null ? publicVersion.contentView
                : null;
        final View publicLocalView = entry.getPublicContentView();

        // Reapply the RemoteViews
        contentView.reapply(mContext, entry.getContentView(), mOnClickHandler);
@@ -2088,9 +2052,13 @@ public abstract class BaseStatusBar extends SystemUI implements
            headsUpContentView.reapply(notification.getPackageContext(mContext),
                    headsUpChild, mOnClickHandler);
        }
        if (publicContentView != null && entry.getPublicContentView() != null) {
        if (publicLocalView != null) {
            if (publicContentView != null) {
                publicContentView.reapply(notification.getPackageContext(mContext),
                    entry.getPublicContentView(), mOnClickHandler);
                        publicLocalView, mOnClickHandler);
            } else {
                updatePublicViewProperties(publicLocalView, entry);
            }
        }
        // update the contentIntent
        mNotificationClicker.register(entry.row, notification);
@@ -2105,6 +2073,55 @@ public abstract class BaseStatusBar extends SystemUI implements
        maybeEscalateHeadsUp();
    }

    private void updatePublicViewProperties(View publicView, Entry entry) {
        final StatusBarNotification n = entry.notification;
        final ImageView icon = (ImageView) publicView.findViewById(R.id.icon);
        final ImageView profileBadge =
                (ImageView) publicView.findViewById(R.id.profile_badge_line3);
        final DateTimeView time = (DateTimeView) publicView.findViewById(R.id.time);

        if (icon != null) {
            final StatusBarIcon ic = new StatusBarIcon(
                    n.getUser(), n.getPackageName(),
                    n.getNotification().getSmallIcon(),
                    n.getNotification().iconLevel,
                    n.getNotification().number,
                    n.getNotification().tickerText);

            Drawable iconDrawable = StatusBarIconView.getIcon(mContext, ic);
            icon.setImageDrawable(iconDrawable);
            if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP
                    || mNotificationColorUtil.isGrayscaleIcon(iconDrawable)) {
                icon.setBackgroundResource(
                        com.android.internal.R.drawable.notification_icon_legacy_bg);
                int padding = mContext.getResources().getDimensionPixelSize(
                        com.android.internal.R.dimen.notification_large_icon_circle_padding);
                icon.setPadding(padding, padding, padding, padding);
                if (n.getNotification().color != Notification.COLOR_DEFAULT) {
                    icon.getBackground().setColorFilter(
                            n.getNotification().color, PorterDuff.Mode.SRC_ATOP);
                }
            } else {
                icon.setBackgroundDrawable(null);
            }
         }

        if (time != null) {
            time.setTime(entry.notification.getNotification().when);
        }

        if (profileBadge != null) {
            Drawable profileDrawable = mContext.getPackageManager().getUserBadgeForDensity(
                    n.getUser(), 0);
            if (profileDrawable != null) {
                profileBadge.setImageDrawable(profileDrawable);
                profileBadge.setVisibility(View.VISIBLE);
            } else {
                profileBadge.setVisibility(View.GONE);
            }
        }
    }

    private boolean alertAgain(Entry oldEntry, Notification newNotification) {
        return oldEntry == null || !oldEntry.hasInterrupted()
                || (newNotification.flags & Notification.FLAG_ONLY_ALERT_ONCE) == 0;