Skip to content

Commit

Permalink
Remove all notifications on clear blocked messages
Browse files Browse the repository at this point in the history
  • Loading branch information
apsun committed Jun 11, 2018
1 parent f5f0303 commit 1dd8fd2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private void clearAllMessages() {
Context context = getContext();
if (context == null) return;

NotificationHelper.cancelAllNotifications(context);
BlockedSmsLoader.get().deleteAll(context);
showSnackbar(R.string.cleared_blocked_messages);
}
Expand Down Expand Up @@ -180,7 +181,7 @@ public void showMessageDetailsDialog(final SmsMessageData messageData) {
if (context == null) return;

// Dismiss notification if present
NotificationHelper.removeNotification(context, messageData.getId());
NotificationHelper.cancelNotification(context, messageData.getId());

final long smsId = messageData.getId();
String sender = messageData.getSender();
Expand Down Expand Up @@ -224,7 +225,7 @@ private void restoreSms(long smsId) {
if (context == null) return;

// We've obviously seen the message, so remove the notification
NotificationHelper.removeNotification(context, smsId);
NotificationHelper.cancelNotification(context, smsId);

// Load message content (so we can undo)
final SmsMessageData messageData = BlockedSmsLoader.get().query(context, smsId);
Expand Down Expand Up @@ -272,7 +273,7 @@ private void deleteSms(long smsId) {
if (context == null) return;

// We've obviously seen the message, so remove the notification
NotificationHelper.removeNotification(context, smsId);
NotificationHelper.cancelNotification(context, smsId);

// Load message content (for undo), then delete it
final SmsMessageData messageData = BlockedSmsLoader.get().queryAndDelete(context, smsId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void onReceiveSms(Context context, Intent intent) {

private void onDeleteSms(Context context, Intent intent) {
Uri messageUri = intent.getData();
NotificationHelper.removeNotification(context, messageUri);
NotificationHelper.cancelNotification(context, messageUri);

boolean deleted = BlockedSmsLoader.get().delete(context, messageUri);
if (!deleted) {
Expand All @@ -38,7 +38,7 @@ private void onDeleteSms(Context context, Intent intent) {

private void onRestoreSms(Context context, Intent intent) {
Uri messageUri = intent.getData();
NotificationHelper.removeNotification(context, messageUri);
NotificationHelper.cancelNotification(context, messageUri);

// Always mark message as seen, even though we're deleting it,
// so even if we don't get to delete it, the seen flag still gets set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ private static Notification buildNotificationSingle(Context context, SmsMessageD
.build();
}

public static void removeNotification(Context context, Uri messageUri) {
public static void cancelNotification(Context context, long messageId) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(uriToNotificationId(messageUri));
notificationManager.cancel((int)messageId);
}

public static void cancelNotification(Context context, Uri messageUri) {
cancelNotification(context, uriToNotificationId(messageUri));
}

public static void removeNotification(Context context, long messageId) {
public static void cancelAllNotifications(Context context) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel((int)messageId);
notificationManager.cancelAll();
}

public static void displayNotification(Context context, Uri messageUri) {
Expand Down

0 comments on commit 1dd8fd2

Please sign in to comment.