Skip to content

Commit

Permalink
feat(android): add option to make a notification ongoing (#3165)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDutchDev authored Jul 10, 2020
1 parent 2a39a7d commit 1ee51cd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class LocalNotification {
private String actionTypeId;
private String group;
private boolean groupSummary;
private boolean ongoing;
private boolean autoCancel;
private JSObject extra;
private List<LocalNotificationAttachment> attachments;
private LocalNotificationSchedule schedule;
Expand Down Expand Up @@ -152,6 +154,22 @@ public void setGroupSummary(boolean groupSummary) {
this.groupSummary = groupSummary;
}

public boolean isOngoing() {
return ongoing;
}

public void setOngoing(boolean ongoing) {
this.ongoing = ongoing;
}

public boolean isAutoCancel() {
return autoCancel;
}

public void setAutoCancel(boolean autoCancel) {
this.autoCancel = autoCancel;
}

public String getChannelId() {
return channelId;
}
Expand Down Expand Up @@ -186,7 +204,7 @@ public static List<LocalNotification> buildNotificationList(PluginCall call) {
call.error("Invalid JSON object sent to NotificationPlugin", e);
return null;
}

try {
LocalNotification activeLocalNotification = buildNotificationFromJSObject(notification);
resultLocalNotifications.add(activeLocalNotification);
Expand Down Expand Up @@ -214,6 +232,8 @@ public static LocalNotification buildNotificationFromJSObject(JSObject jsonObjec
localNotification.setChannelId(jsonObject.getString("channelId"));
localNotification.setSchedule(new LocalNotificationSchedule(jsonObject));
localNotification.setExtra(jsonObject.getJSObject("extra"));
localNotification.setOngoing(jsonObject.getBoolean("ongoing", false));
localNotification.setAutoCancel(jsonObject.getBoolean("autoCancel", true));

return localNotification;
}
Expand Down Expand Up @@ -288,6 +308,8 @@ public String toString() {
", attachments=" + attachments +
", schedule=" + schedule +
", groupSummary=" + groupSummary +
", ongoing=" + ongoing +
", autoCancel=" + autoCancel +
'}';
}

Expand All @@ -311,6 +333,8 @@ public boolean equals(Object o) {
if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null)
return false;
if (groupSummary != that.groupSummary) return false;
if( ongoing != that.ongoing ) return false;
if( autoCancel != that.autoCancel ) return false;
return schedule != null ? schedule.equals(that.schedule) : that.schedule == null;
}

Expand All @@ -325,6 +349,8 @@ public int hashCode() {
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 + Boolean.hashCode( ongoing );
result = 31 * result + Boolean.hashCode( autoCancel );
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 @@ -174,8 +174,8 @@ private void buildNotification(NotificationManagerCompat notificationManager, Lo
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this.context, channelId)
.setContentTitle(localNotification.getTitle())
.setContentText(localNotification.getBody())
.setAutoCancel(true)
.setOngoing(false)
.setAutoCancel( localNotification.isAutoCancel( ) )
.setOngoing( localNotification.isOngoing( ) )
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setGroupSummary(localNotification.isGroupSummary());

Expand Down
9 changes: 9 additions & 0 deletions core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,15 @@ export interface LocalNotification {
* notification will not fire. If not provided, it will use the default channel.
*/
channelId?: string;
/**
* Android only: set the notification ongoing.
* If set to true the notification can't be swiped away.
*/
ongoing?: boolean;
/**
* Android only: set the notification to be removed automatically when the user clicks on it
*/
autoCancel?: boolean;
}

export interface LocalNotificationSchedule {
Expand Down

0 comments on commit 1ee51cd

Please sign in to comment.