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

Commit e8701d3f authored by Michael Chan's avatar Michael Chan Committed by Android (Google) Code Review
Browse files

Merge "Fix swiping the digest notification." into jb-dev

parents ef4530b4 660f1b4a
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -316,7 +316,7 @@ public class AlertReceiver extends BroadcastReceiver {
     * Creates an expanding digest notification for expired events.
     */
    public static Notification makeDigestNotification(Context context,
            List<AlertService.NotificationInfo> notificationInfos, String digestTitle,
            ArrayList<AlertService.NotificationInfo> notificationInfos, String digestTitle,
            boolean expandable) {
        if (notificationInfos == null || notificationInfos.size() < 1) {
            return null;
@@ -324,6 +324,10 @@ public class AlertReceiver extends BroadcastReceiver {

        Resources res = context.getResources();
        int numEvents = notificationInfos.size();
        long[] eventIds = new long[notificationInfos.size()];
        for (int i = 0; i < notificationInfos.size(); i++) {
            eventIds[i] = notificationInfos.get(i).eventId;
        }

        // Create an intent triggered by clicking on the status icon that shows the alerts list.
        Intent clickIntent = new Intent();
@@ -337,7 +341,7 @@ public class AlertReceiver extends BroadcastReceiver {
        Intent deleteIntent = new Intent();
        deleteIntent.setClass(context, DismissAlarmsService.class);
        deleteIntent.setAction(DELETE_ALL_ACTION);
        deleteIntent.putExtra(AlertUtils.DELETE_EXPIRED_ONLY_KEY, true);
        deleteIntent.putExtra(AlertUtils.EVENT_IDS_KEY, eventIds);
        PendingIntent pendingDeleteIntent = PendingIntent.getService(context, 0, deleteIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public class AlertUtils {
    public static final String EVENT_START_KEY = "eventstart";
    public static final String EVENT_END_KEY = "eventend";
    public static final String NOTIFICATION_ID_KEY = "notificationid";
    public static final String DELETE_EXPIRED_ONLY_KEY = "expired";
    public static final String EVENT_IDS_KEY = "eventids";

    /**
     * Schedules an alarm intent with the system AlarmManager that will notify
+26 −12
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ public class DismissAlarmsService extends IntentService {
        long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
        long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
        boolean showEvent = intent.getBooleanExtra(AlertUtils.SHOW_EVENT_KEY, false);
        boolean expiredOnly = intent.getBooleanExtra(AlertUtils.DELETE_EXPIRED_ONLY_KEY, false);
        long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY);

        // The ID reserved for the expired notification digest should never be passed in
        // here, so use that as a default.
@@ -68,26 +68,19 @@ public class DismissAlarmsService extends IntentService {
        if (eventId != -1) {
            selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " +
            CalendarAlerts.EVENT_ID + "=" + eventId;
        } else if (eventIds != null && eventIds.length > 0) {
            selection = buildMultipleEventsQuery(eventIds);
        } else {
            selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
        }
        if (expiredOnly) {
            selection += " AND " + CalendarAlerts.END + "<" +
                    Long.toString(System.currentTimeMillis());
        }

        ContentResolver resolver = getContentResolver();
        ContentValues values = new ContentValues();
        values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
        resolver.update(uri, values, selection, null);

        // Remove from notification bar.
        NotificationManager nm =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        if (expiredOnly) {
            nm.cancel(AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID);
        } else if (notificationId != AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID) {
            nm.cancel(notificationId);
        }
        AlertService.updateAlertNotification(this);

        if (showEvent) {
            // Show event on Calendar app by building an intent and task stack to start
@@ -100,4 +93,25 @@ public class DismissAlarmsService extends IntentService {
        // Stop this service
        stopSelf();
    }

    private String buildMultipleEventsQuery(long[] eventIds) {
        StringBuilder selection = new StringBuilder();
        selection.append(CalendarAlerts.STATE);
        selection.append("=");
        selection.append(CalendarAlerts.STATE_FIRED);
        if (eventIds.length > 0) {
            selection.append(" AND (");
            selection.append(CalendarAlerts.EVENT_ID);
            selection.append("=");
            selection.append(eventIds[0]);
            for (int i = 1; i < eventIds.length; i++) {
                selection.append(" OR ");
                selection.append(CalendarAlerts.EVENT_ID);
                selection.append("=");
                selection.append(eventIds[i]);
            }
            selection.append(")");
        }
        return selection.toString();
    }
}