Skip to content

Commit

Permalink
feat(android): add group and groupSummary to LocalNotifications (#2385)
Browse files Browse the repository at this point in the history
  • Loading branch information
p7g authored Feb 3, 2020
1 parent 181d564 commit 8e8a157
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public void getDeliveredNotifications(PluginCall call) {
if (notification != null) {
jsNotif.put("title", notification.extras.getCharSequence(Notification.EXTRA_TITLE));
jsNotif.put("body", notification.extras.getCharSequence(Notification.EXTRA_TEXT));
jsNotif.put("group", notification.getGroup());
jsNotif.put("groupSummary", 0 != (notification.flags & Notification.FLAG_GROUP_SUMMARY));

JSObject extras = new JSObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class LocalNotification {
private String sound;
private String smallIcon;
private String actionTypeId;
private String group;
private boolean groupSummary;
private JSObject extra;
private List<LocalNotificationAttachment> attachments;
private LocalNotificationSchedule schedule;
Expand Down Expand Up @@ -89,6 +91,14 @@ public void setActionTypeId(String actionTypeId) {
this.actionTypeId = actionTypeId;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public JSObject getExtra() {
return extra;
}
Expand All @@ -105,6 +115,14 @@ public void setId(Integer id) {
this.id = id;
}

public boolean isGroupSummary() {
return groupSummary;
}

public void setGroupSummary(boolean groupSummary) {
this.groupSummary = groupSummary;
}

/**
* Build list of the notifications from remote plugin call
*/
Expand Down Expand Up @@ -136,10 +154,12 @@ public static List<LocalNotification> buildNotificationList(PluginCall call) {
activeLocalNotification.setId(notification.getInteger("id"));
activeLocalNotification.setBody(notification.getString("body"));
activeLocalNotification.setActionTypeId(notification.getString("actionTypeId"));
activeLocalNotification.setGroup(notification.getString("group"));
activeLocalNotification.setSound(notification.getString("sound"));
activeLocalNotification.setTitle(notification.getString("title"));
activeLocalNotification.setSmallIcon(notification.getString("smallIcon"));
activeLocalNotification.setAttachments(LocalNotificationAttachment.getAttachments(notification));
activeLocalNotification.setGroupSummary(notification.getBoolean("groupSummary", false));
try {
activeLocalNotification.setSchedule(new LocalNotificationSchedule(notification));
} catch (ParseException e) {
Expand Down Expand Up @@ -234,9 +254,11 @@ public String toString() {
", sound='" + sound + '\'' +
", smallIcon='" + smallIcon + '\'' +
", actionTypeId='" + actionTypeId + '\'' +
", group='" + group + '\'' +
", extra=" + extra +
", attachments=" + attachments +
", schedule=" + schedule +
", groupSummary=" + groupSummary +
'}';
}

Expand All @@ -254,9 +276,11 @@ public boolean equals(Object o) {
if (smallIcon != null ? !smallIcon.equals(that.smallIcon) : that.smallIcon != null) return false;
if (actionTypeId != null ? !actionTypeId.equals(that.actionTypeId) : that.actionTypeId != null)
return false;
if (group != null ? !group.equals(that.group) : that.group != null) return false;
if (extra != null ? !extra.equals(that.extra) : that.extra != null) return false;
if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null)
return false;
if (groupSummary != that.groupSummary) return false;
return schedule != null ? schedule.equals(that.schedule) : that.schedule == null;
}

Expand All @@ -268,6 +292,8 @@ public int hashCode() {
result = 31 * result + (sound != null ? sound.hashCode() : 0);
result = 31 * result + (smallIcon != null ? smallIcon.hashCode() : 0);
result = 31 * result + (actionTypeId != null ? actionTypeId.hashCode() : 0);
result = 31 * result + (group != null ? group.hashCode() : 0);
result = 31 * result + Boolean.hashCode(groupSummary);
result = 31 * result + (extra != null ? extra.hashCode() : 0);
result = 31 * result + (attachments != null ? attachments.hashCode() : 0);
result = 31 * result + (schedule != null ? schedule.hashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private void buildNotification(NotificationManagerCompat notificationManager, Lo
.setAutoCancel(true)
.setOngoing(false)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setGroupSummary(localNotification.isGroupSummary())
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);

String sound = localNotification.getSound();
Expand All @@ -161,6 +162,11 @@ private void buildNotification(NotificationManagerCompat notificationManager, Lo
mBuilder.setSound(soundUri);
}

String group = localNotification.getGroup();
if (group != null) {
mBuilder.setGroup(group);
}

mBuilder.setVisibility(Notification.VISIBILITY_PRIVATE);
mBuilder.setOnlyAlertOnce(true);

Expand Down
20 changes: 20 additions & 0 deletions core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,16 @@ export interface LocalNotification {
* iOS 12+ only: set the summary argument for notification grouping
*/
summaryArgument?: string;
/**
* Android only: set the group identifier for notification grouping, like
* threadIdentifier on iOS.
*/
group?: string;
/**
* Android only: designate this notification as the summary for a group
* (should be used with the `group` property).
*/
groupSummary?: boolean;
}

export interface LocalNotificationSchedule {
Expand Down Expand Up @@ -1437,6 +1447,16 @@ export interface PushNotification {
data: any;
click_action?: string;
link?: string;
/**
* Android only: set the group identifier for notification grouping, like
* threadIdentifier on iOS.
*/
group?: string;
/**
* Android only: designate this notification as the summary for a group
* (should be used with the `group` property).
*/
groupSummary?: boolean;
}

export interface PushNotificationActionPerformed {
Expand Down

0 comments on commit 8e8a157

Please sign in to comment.