Commit 5cfb725c by Sebastián Katzer

Restore non-repeating notifications which havent been trigger yet [see #1449]

parent 6b2cc24e
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
package de.appplant.cordova.plugin.localnotification; package de.appplant.cordova.plugin.localnotification;
import android.content.Context;
import android.util.Log;
import java.util.Date;
import de.appplant.cordova.plugin.notification.Builder; import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Manager; import de.appplant.cordova.plugin.notification.Manager;
import de.appplant.cordova.plugin.notification.Notification; import de.appplant.cordova.plugin.notification.Notification;
...@@ -44,15 +49,19 @@ public class RestoreReceiver extends AbstractRestoreReceiver { ...@@ -44,15 +49,19 @@ public class RestoreReceiver extends AbstractRestoreReceiver {
*/ */
@Override @Override
public void onRestore (Request request, Notification toast) { public void onRestore (Request request, Notification toast) {
Manager mgr = Manager.getInstance(toast.getContext()); Date date = request.getTriggerDate();
boolean after = date != null && date.after(new Date());
if (toast.isHighPrio()) { if (!after && toast.isHighPrio()) {
toast.show(); toast.show();
} else { } else {
toast.clear(); toast.clear();
} }
if (toast.isRepeating()) { Context ctx = toast.getContext();
Manager mgr = Manager.getInstance(ctx);
if (after || toast.isRepeating()) {
mgr.schedule(request, TriggerReceiver.class); mgr.schedule(request, TriggerReceiver.class);
} }
} }
......
...@@ -138,7 +138,7 @@ public final class Request { ...@@ -138,7 +138,7 @@ public final class Request {
* *
* @return null if there's no trigger date. * @return null if there's no trigger date.
*/ */
Date getTriggerDate() { public Date getTriggerDate() {
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
if (triggerDate == null) if (triggerDate == null)
......
...@@ -37,6 +37,9 @@ import de.appplant.cordova.plugin.notification.Notification; ...@@ -37,6 +37,9 @@ import de.appplant.cordova.plugin.notification.Notification;
import de.appplant.cordova.plugin.notification.Options; import de.appplant.cordova.plugin.notification.Options;
import de.appplant.cordova.plugin.notification.Request; import de.appplant.cordova.plugin.notification.Request;
import static android.content.Intent.ACTION_BOOT_COMPLETED;
import static android.os.Build.VERSION.SDK_INT;
/** /**
* This class is triggered upon reboot of the device. It needs to re-register * This class is triggered upon reboot of the device. It needs to re-register
* the alarms with the AlarmManager since these alarms are lost in case of * the alarms with the AlarmManager since these alarms are lost in case of
...@@ -52,6 +55,11 @@ abstract public class AbstractRestoreReceiver extends BroadcastReceiver { ...@@ -52,6 +55,11 @@ abstract public class AbstractRestoreReceiver extends BroadcastReceiver {
*/ */
@Override @Override
public void onReceive (Context context, Intent intent) { public void onReceive (Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ACTION_BOOT_COMPLETED) && SDK_INT >= 24)
return;
Manager mgr = Manager.getInstance(context); Manager mgr = Manager.getInstance(context);
List<JSONObject> toasts = mgr.getOptions(); List<JSONObject> toasts = mgr.getOptions();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment