Sfoglia il codice sorgente

Fixes #732 loop between update and trigger

Sebastián Katzer 10 anni fa
parent
commit
3a2ed5dc3c

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo
 
 #### Version 0.8.3 (not yet released)
 - New "quarter" intervall for iOS & Android
+- Fixed #732 loop between update and trigger (Android)
 - Fixed #710 crash due to >500 notifications (Android)
 - Fixed crashing `get(ID)` if notification doesn't exist
 

+ 1 - 1
src/android/notification/AbstractTriggerReceiver.java

@@ -70,7 +70,7 @@ abstract public class AbstractTriggerReceiver extends BroadcastReceiver {
 
         Builder builder = new Builder(options);
         Notification notification = buildNotification(builder);
-        boolean updated = notification.isUpdate();
+        boolean updated = notification.isUpdate(false);
 
         onTrigger(notification, updated);
     }

+ 1 - 2
src/android/notification/Manager.java

@@ -31,7 +31,6 @@ import org.json.JSONException;
 import org.json.JSONObject;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -121,7 +120,7 @@ public class Manager {
                 notification.getOptions().getDict(), updates);
 
         try {
-            options.putOpt("updatedAt", new Date().getTime());
+            options.putOpt("updated", true);
         } catch (JSONException ignore) {}
 
         return schedule(options, receiver);

+ 10 - 8
src/android/notification/Notification.java

@@ -138,16 +138,18 @@ public class Notification {
 
     /**
      * If the notification is an update.
+     *
+     * @param keepFlag
+     *      Set to false to remove the flag from the option map
      */
-    protected boolean isUpdate () {
-
-        if (!options.getDict().has("updatedAt"))
-            return false;
+    protected boolean isUpdate (boolean keepFlag) {
+        boolean updated = options.getDict().optBoolean("updated", false);
 
-        long now       = new Date().getTime();
-        long updatedAt = options.getDict().optLong("updatedAt", now);
+        if (!keepFlag) {
+            options.getDict().remove("updated");
+        }
 
-        return (now - updatedAt) < 1000;
+        return updated;
     }
 
     /**
@@ -268,7 +270,7 @@ public class Notification {
         }
 
         json.remove("firstAt");
-        json.remove("updatedAt");
+        json.remove("updated");
         json.remove("soundUri");
         json.remove("iconUri");