Merge pull request #1294 from dluksza/fix-past-date-scheduling
Honor repeatInterval when rescheduling outdated notication
This commit is contained in:
commit
408f998407
|
@ -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.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);
|
newFireDate.add(Calendar.DATE, 1);
|
||||||
newFireDate.set(Calendar.HOUR_OF_DAY, currentFireDate.get(Calendar.HOUR_OF_DAY));
|
break;
|
||||||
newFireDate.set(Calendar.MINUTE, currentFireDate.get(Calendar.MINUTE));
|
case "week":
|
||||||
newFireDate.set(Calendar.SECOND, currentFireDate.get(Calendar.SECOND));
|
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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue