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

Commit 57dd943e authored by Sara Ting's avatar Sara Ting
Browse files

Notification fixes: fix duplicate notifications, and reverse digest ordering.

Changed notification hash ID to use eventId & startTime instead of alertId to avoid multiple notifications for the same event.  And reversed the digest order so newer events appear first.

Bug:6282451
Change-Id: I8cf4c4b4af1a5692a26bd4550f7cbfac05c69da0
parent 1946e278
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -304,7 +304,6 @@ public class AlertReceiver extends BroadcastReceiver {
        notificationBuilder.setSmallIcon(R.drawable.stat_notify_calendar);
        notificationBuilder.setContentIntent(pendingClickIntent);
        notificationBuilder.setDeleteIntent(pendingDeleteIntent);
        notificationBuilder.addKind(Notification.KIND_EVENT);

        String nEventsStr = res.getQuantityString(R.plurals.Nevents, numEvents, numEvents);
        notificationBuilder.setContentText(nEventsStr);
+18 −10
Original line number Diff line number Diff line
@@ -274,7 +274,7 @@ public class AlertService extends Service {
                // Don't count duplicate alerts for the same event
                if (eventIds.put(eventId, beginTime) == null) {
                    NotificationInfo notificationInfo = new NotificationInfo(eventName, location,
                            description, beginTime, endTime, eventId, allDay, alertId);
                            description, beginTime, endTime, eventId, allDay);

                    if ((beginTime <= currentTime) && (endTime >= currentTime)) {
                        currentEvents.add(notificationInfo);
@@ -282,13 +282,12 @@ public class AlertService extends Service {
                        futureEvents.add(notificationInfo);
                    } else {
                        // TODO: Prioritize by "primary" calendar
                        // Assumes alerts are sorted by begin time in reverse
                        expiredEvents.add(0, notificationInfo);
                        expiredEvents.add(notificationInfo);
                        if (!TextUtils.isEmpty(eventName)) {
                            if (expiredDigestTitle == null) {
                                expiredDigestTitle = eventName;
                            } else {
                                expiredDigestTitle = eventName + ", " + expiredDigestTitle;
                                expiredDigestTitle = expiredDigestTitle + ", " + eventName;
                            }
                        }
                    }
@@ -411,7 +410,7 @@ public class AlertService extends Service {
        boolean allDay;

        NotificationInfo(String eventName, String location, String description, long startMillis,
                long endMillis, long eventId, boolean allDay, long alertId) {
                long endMillis, long eventId, boolean allDay) {
            this.eventName = eventName;
            this.location = location;
            this.description = description;
@@ -419,14 +418,23 @@ public class AlertService extends Service {
            this.endMillis = endMillis;
            this.eventId = eventId;
            this.allDay = allDay;
            this.notificationId = getNotificationId(eventId, startMillis);
        }

            // Convert alert ID into the ID for posting notifications.  Use hash so we don't
            // have to worry about any limits (but handle the case of a collision with the ID
            // reserved for representing the expired notification digest).
            this.notificationId = Long.valueOf(alertId).hashCode();
        /*
         * Convert reminder into the ID for posting notifications.  Use hash so we don't
         * have to worry about any limits (but handle the case of a collision with the ID
         * reserved for representing the expired notification digest).
         */
        private static int getNotificationId(long eventId, long startMillis) {
            long result = 17;
            result = 37 * result + eventId;
            result = 37 * result + startMillis;
            int notificationId = Long.valueOf(result).hashCode();
            if (notificationId == AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID) {
                this.notificationId = Integer.MAX_VALUE;
                notificationId = Integer.MAX_VALUE;
            }
            return notificationId;
        }
    }