From 11ccbb42f6c45fcee094d51775873f4bb8b51bde Mon Sep 17 00:00:00 2001 From: Dariusz Luksza Date: Wed, 11 Jul 2018 17:05:27 +0200 Subject: [PATCH 1/3] Honor repeatInterval when rescheduling outdated notiication --- .../RNFirebaseNotificationManager.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java index 185dc4d5..a2e96e2d 100644 --- a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java +++ b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java @@ -365,11 +365,26 @@ public class RNFirebaseNotificationManager { Calendar currentFireDate = Calendar.getInstance(); currentFireDate.setTimeInMillis(fireDate); - newFireDate.add(Calendar.DATE, 1); + newFireDate.set(Calendar.DATE, currentFireDate.get(Calendar.DATE)); newFireDate.set(Calendar.HOUR_OF_DAY, currentFireDate.get(Calendar.HOUR_OF_DAY)); newFireDate.set(Calendar.MINUTE, currentFireDate.get(Calendar.MINUTE)); newFireDate.set(Calendar.SECOND, currentFireDate.get(Calendar.SECOND)); + switch (schedule.getString("repeatInterval")) { + case "minute": + newFireDate.add(Calendar.MINUTE, 1); + break; + case "hour": + newFireDate.add(Calendar.HOUR, 1); + break; + case "day": + newFireDate.add(Calendar.DATE, 1); + break; + case "week": + newFireDate.add(Calendar.DATE, 7); + break; + } + fireDate = newFireDate.getTimeInMillis(); } From 9144314eac825d92f8fa9b3bff7e4307cd58eeff Mon Sep 17 00:00:00 2001 From: Dariusz Luksza Date: Wed, 11 Jul 2018 17:39:32 +0200 Subject: [PATCH 2/3] Warn about changing notification schedule date --- .../firebase/notifications/RNFirebaseNotificationManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java index a2e96e2d..655fd61e 100644 --- a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java +++ b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java @@ -361,6 +361,7 @@ public class RNFirebaseNotificationManager { // If fireDate you specify is in the past, the alarm triggers immediately. // So we need to adjust the time for correct operation. if (fireDate < System.currentTimeMillis()) { + Log.w(TAG, "Scheduled notification date is in the past, will adjust it to be in future"); Calendar newFireDate = Calendar.getInstance(); Calendar currentFireDate = Calendar.getInstance(); currentFireDate.setTimeInMillis(fireDate); From c17cc502298548751acea0bc8e80cc68d89b2add Mon Sep 17 00:00:00 2001 From: Dariusz Luksza Date: Wed, 11 Jul 2018 18:11:56 +0200 Subject: [PATCH 3/3] Properly compute new schedule date when old is in past --- .../RNFirebaseNotificationManager.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java index 655fd61e..66451d95 100644 --- a/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java +++ b/android/src/main/java/io/invertase/firebase/notifications/RNFirebaseNotificationManager.java @@ -363,25 +363,28 @@ public class RNFirebaseNotificationManager { if (fireDate < System.currentTimeMillis()) { Log.w(TAG, "Scheduled notification date is in the past, will adjust it to be in future"); Calendar newFireDate = Calendar.getInstance(); - Calendar currentFireDate = Calendar.getInstance(); - currentFireDate.setTimeInMillis(fireDate); + Calendar pastFireDate = Calendar.getInstance(); + pastFireDate.setTimeInMillis(fireDate); - newFireDate.set(Calendar.DATE, currentFireDate.get(Calendar.DATE)); - newFireDate.set(Calendar.HOUR_OF_DAY, currentFireDate.get(Calendar.HOUR_OF_DAY)); - newFireDate.set(Calendar.MINUTE, currentFireDate.get(Calendar.MINUTE)); - newFireDate.set(Calendar.SECOND, currentFireDate.get(Calendar.SECOND)); + newFireDate.set(Calendar.SECOND, pastFireDate.get(Calendar.SECOND)); switch (schedule.getString("repeatInterval")) { case "minute": newFireDate.add(Calendar.MINUTE, 1); break; case "hour": + newFireDate.set(Calendar.MINUTE, pastFireDate.get(Calendar.MINUTE)); newFireDate.add(Calendar.HOUR, 1); break; case "day": + newFireDate.set(Calendar.MINUTE, pastFireDate.get(Calendar.MINUTE)); + newFireDate.set(Calendar.HOUR_OF_DAY, pastFireDate.get(Calendar.HOUR_OF_DAY)); newFireDate.add(Calendar.DATE, 1); break; case "week": + newFireDate.set(Calendar.MINUTE, pastFireDate.get(Calendar.MINUTE)); + newFireDate.set(Calendar.HOUR_OF_DAY, pastFireDate.get(Calendar.HOUR_OF_DAY)); + newFireDate.set(Calendar.DATE, pastFireDate.get(Calendar.DATE)); newFireDate.add(Calendar.DATE, 7); break; }