Merge pull request #1294 from dluksza/fix-past-date-scheduling

Honor repeatInterval when rescheduling outdated notication
This commit is contained in:
Michael Diarmid 2018-07-20 11:14:02 +01:00 committed by GitHub
commit 408f998407
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 6 deletions

View File

@ -361,14 +361,33 @@ public class RNFirebaseNotificationManager {
// If fireDate you specify is in the past, the alarm triggers immediately. // If fireDate you specify is in the past, the alarm triggers immediately.
// So we need to adjust the time for correct operation. // So we need to adjust the time for correct operation.
if (fireDate < System.currentTimeMillis()) { 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 newFireDate = Calendar.getInstance();
Calendar currentFireDate = Calendar.getInstance(); Calendar pastFireDate = Calendar.getInstance();
currentFireDate.setTimeInMillis(fireDate); pastFireDate.setTimeInMillis(fireDate);
newFireDate.add(Calendar.DATE, 1); newFireDate.set(Calendar.SECOND, pastFireDate.get(Calendar.SECOND));
newFireDate.set(Calendar.HOUR_OF_DAY, currentFireDate.get(Calendar.HOUR_OF_DAY));
newFireDate.set(Calendar.MINUTE, currentFireDate.get(Calendar.MINUTE)); switch (schedule.getString("repeatInterval")) {
newFireDate.set(Calendar.SECOND, currentFireDate.get(Calendar.SECOND)); 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;
}
fireDate = newFireDate.getTimeInMillis(); fireDate = newFireDate.getTimeInMillis();
} }