Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Android)Added option to make a notification ongoing(so it can't be swiped away) #3165

Merged
merged 5 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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