Skip to content

Commit

Permalink
fix(local-notifications): Checking for null schedule in notification …
Browse files Browse the repository at this point in the history
…JSObject (#258)

* Checking for null schedule in notification JSObject

* LocalNotificationSchedule constructor is passed a non null JSObject schedule, no need to do a null check

Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
  • Loading branch information
theproducer and jcesarmobile committed Feb 22, 2021
1 parent 6e447d5 commit 73cb416
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ public static LocalNotification buildNotificationFromJSObject(JSObject jsonObjec
localNotification.setAttachments(LocalNotificationAttachment.getAttachments(jsonObject));
localNotification.setGroupSummary(jsonObject.getBoolean("groupSummary", false));
localNotification.setChannelId(jsonObject.getString("channelId"));
localNotification.setSchedule(new LocalNotificationSchedule(jsonObject));

JSObject schedule = jsonObject.getJSObject("schedule");
if (schedule != null) {
localNotification.setSchedule(new LocalNotificationSchedule(schedule));
}

localNotification.setExtra(jsonObject.getJSObject("extra"));
localNotification.setOngoing(jsonObject.getBoolean("ongoing", false));
localNotification.setAutoCancel(jsonObject.getBoolean("autoCancel", true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ public class LocalNotificationSchedule {

private Boolean whileIdle;

public LocalNotificationSchedule(JSObject jsonNotification) throws ParseException {
JSObject schedule = jsonNotification.getJSObject("schedule");
if (schedule != null) {
// Every specific unit of time (always constant)
buildEveryElement(schedule);
// Count of units of time from every to repeat on
buildCountElement(schedule);
// At specific moment of time (with repeating option)
buildAtElement(schedule);
// Build on - recurring times. For e.g. every 1st day of the month at 8:30.
buildOnElement(schedule);

// Schedule this notification to fire even if app is idled (Doze)
this.whileIdle = schedule.getBoolean("allowWhileIdle", false);
}
public LocalNotificationSchedule(JSObject schedule) throws ParseException {
// Every specific unit of time (always constant)
buildEveryElement(schedule);
// Count of units of time from every to repeat on
buildCountElement(schedule);
// At specific moment of time (with repeating option)
buildAtElement(schedule);
// Build on - recurring times. For e.g. every 1st day of the month at 8:30.
buildOnElement(schedule);

// Schedule this notification to fire even if app is idled (Doze)
this.whileIdle = schedule.getBoolean("allowWhileIdle", false);
}

public LocalNotificationSchedule() {}
Expand Down

0 comments on commit 73cb416

Please sign in to comment.