aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationDismissBroadcastReceiver.java
blob: a4b33b540108634e8c8c7623c9a3d188666c5eaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org.wordpress.android.ui.notifications;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationManagerCompat;

import org.wordpress.android.GCMMessageService;

/*
 * Clears the notification map when a user dismisses a notification
 */
public class NotificationDismissBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        int notificationId = intent.getIntExtra("notificationId", 0);
        if (notificationId == GCMMessageService.GROUP_NOTIFICATION_ID) {
            GCMMessageService.clearNotifications();
        } else {
            GCMMessageService.removeNotification(notificationId);
            // Dismiss the grouped notification if a user dismisses all notifications from a wear device
            if (!GCMMessageService.hasNotifications()) {
                NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
                notificationManager.cancel(GCMMessageService.GROUP_NOTIFICATION_ID);
            }
        }
    }
}