Browse Source

Fix getIds returns none existing notifications

Sebastián Katzer 10 năm trước cách đây
mục cha
commit
d74caf6801

+ 5 - 5
src/android/ClickActivity.java

@@ -44,13 +44,13 @@ public class ClickActivity extends de.appplant.cordova.plugin.notification.Click
     public void onClick(Notification notification) {
         LocalNotification.fireEvent("click", notification);
 
-        if (!notification.getOptions().isOngoing()) {
-            String event = notification.isRepeating() ? "clear" : "cancel";
+        super.onClick(notification);
 
-            LocalNotification.fireEvent(event, notification);
-        }
+        if (notification.getOptions().isOngoing())
+            return;
 
-        super.onClick(notification);
+        String event = notification.isRepeating() ? "clear" : "cancel";
+        LocalNotification.fireEvent(event, notification);
     }
 
     /**

+ 6 - 0
src/android/notification/ClickActivity.java

@@ -40,6 +40,12 @@ public class ClickActivity extends AbstractClickActivity {
     @Override
     public void onClick(Notification notification) {
         launchApp();
+
+        if (notification.isRepeating()) {
+            notification.clear();
+        } else {
+            notification.cancel();
+        }
     }
 
     /**

+ 5 - 13
src/android/notification/Notification.java

@@ -144,8 +144,7 @@ public class Notification {
         if (!options.getDict().has("updatedAt"))
             return false;
 
-        long now = new Date().getTime();
-
+        long now       = new Date().getTime();
         long updatedAt = options.getDict().optLong("updatedAt", now);
 
         return (now - updatedAt) < 1000;
@@ -184,14 +183,14 @@ public class Notification {
 
     /**
      * Clear the local notification without canceling repeating alarms.
-     *
      */
     public void clear () {
-        if (!isRepeating() && wasInThePast()) {
+
+        if (!isRepeating() && wasInThePast())
             unpersist();
-        } else {
+
+        if (!isRepeating())
             getNotMgr().cancel(getId());
-        }
     }
 
     /**
@@ -239,13 +238,6 @@ public class Notification {
         }
     }
 
-    /**
-     * Show as modal dialog when in foreground.
-     */
-    private void showDialog () {
-        // TODO
-    }
-
     /**
      * Count of triggers since schedule.
      */

+ 4 - 4
src/android/notification/Options.java

@@ -213,10 +213,10 @@ public class Options {
      * Trigger date in milliseconds.
      */
     public long getTriggerTime() {
-        return Math.max(
-                System.currentTimeMillis(),
-                options.optLong("at", 0) * 1000
-        );
+        //return Math.max(
+        //        System.currentTimeMillis(),
+                return options.optLong("at", 0) * 1000;
+        //);
     }
 
     /**