Skip to content

Commit

Permalink
fix(local-notifications): Make getPending not return already fired no…
Browse files Browse the repository at this point in the history
…tifications (#256)

* Set visibility flag on LocalNotification, filter pendingNotification list

* Removing visible flag, just delete notification if its not rescheduled

Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
  • Loading branch information
theproducer and jcesarmobile authored Feb 23, 2021
1 parent 73cb416 commit fb96f8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class LocalNotification {
private List<LocalNotificationAttachment> attachments;
private LocalNotificationSchedule schedule;
private String channelId;

private String source;

public String getTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public void onReceive(Context context, Intent intent) {
JSObject notificationJson = storage.getSavedNotificationAsJSObject(Integer.toString(id));
LocalNotificationsPlugin.fireReceived(notificationJson);
notificationManager.notify(id, notification);
rescheduleNotificationIfNeeded(context, intent, id);
if (!rescheduleNotificationIfNeeded(context, intent, id)) {
storage.deleteNotification(Integer.toString(id));
}
}

private void rescheduleNotificationIfNeeded(Context context, Intent intent, int id) {
private boolean rescheduleNotificationIfNeeded(Context context, Intent intent, int id) {
String dateString = intent.getStringExtra(CRON_KEY);
if (dateString != null) {
DateMatch date = DateMatch.fromMatchString(dateString);
Expand All @@ -50,6 +52,9 @@ private void rescheduleNotificationIfNeeded(Context context, Intent intent, int
alarmManager.setExact(AlarmManager.RTC, trigger, pendingIntent);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Logger.debug(Logger.tags("LN"), "notification " + id + " will next fire at " + sdf.format(new Date(trigger)));
return true;
}

return false;
}
}

0 comments on commit fb96f8a

Please sign in to comment.