Kaynağa Gözat

`onadd` was called each time after a repeating message was triggered

Sebastián Katzer 12 yıl önce
ebeveyn
işleme
404613066c

+ 4 - 1
README.md

@@ -46,11 +46,14 @@ or to use this exact version:
 More informations can be found [here](https://build.phonegap.com/plugins/413).
 
 ## Release Notes
+#### Version 0.7.2 (not yet released)
+- [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**.
+- [bugfix:] `onadd` was called each time after a repeating message was triggered (Android)
+
 #### Version 0.7.1 (31.01.2014)
 - [bugfix:] `ongoing` attribute was ignored.
 - [bugfix:] `oncancel` wasnt fired if `autoCancel` was set to true.
 - [bugfix:] App throwed an error at restart if a callback was registered.
-- [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**.
 
 #### Version 0.7.0 (22.01.2014)
 **Note:** The new way of callback registration will be not compatible with previous versions! See #62

+ 10 - 6
src/android/LocalNotification.java

@@ -72,11 +72,11 @@ public class LocalNotification extends CordovaPlugin {
         if (action.equalsIgnoreCase("add")) {
             cordova.getThreadPool().execute( new Runnable() {
                 public void run() {
-                    JSONObject arguments  = args.optJSONObject(0);
-                    Options options = new Options(context).parse(arguments);
+                    JSONObject arguments = args.optJSONObject(0);
+                    Options options      = new Options(context).parse(arguments);
 
                     persist(options.getId(), args);
-                    add(options);
+                    add(options, true);
                 }
             });
 
@@ -116,8 +116,10 @@ public class LocalNotification extends CordovaPlugin {
      *
      * @param options
      *            The options that can be specified per alarm.
+     * @param doFireEvent
+     *            If the onadd callback shall be called.
      */
-    public static void add (Options options) {
+    public static void add (Options options, boolean doFireEvent) {
         long triggerTime = options.getDate();
 
         Intent intent = new Intent(context, Receiver.class)
@@ -127,7 +129,9 @@ public class LocalNotification extends CordovaPlugin {
         AlarmManager am  = getAlarmManager();
         PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
 
-        fireEvent("add", options.getId(), options.getJSON());
+        if (doFireEvent) {
+            fireEvent("add", options.getId(), options.getJSON());
+        }
 
         am.set(AlarmManager.RTC_WAKEUP, triggerTime, pi);
     }
@@ -299,4 +303,4 @@ public class LocalNotification extends CordovaPlugin {
 
         callbackQueue.clear();
     }
-}
+}

+ 1 - 1
src/android/Receiver.java

@@ -79,7 +79,7 @@ public class Receiver extends BroadcastReceiver {
         } else if (isFirstAlarmInFuture()) {
             return;
         } else {
-            LocalNotification.add(options.moveDate());
+            LocalNotification.add(options.moveDate(), false);
         }
 
         Builder notification = buildNotification();

+ 1 - 1
src/android/Restore.java

@@ -59,7 +59,7 @@ public class Restore extends BroadcastReceiver {
                 /*
                  * If the trigger date was in the past, the notification will be displayed immediately.
                  */
-                LocalNotification.add(options);
+                LocalNotification.add(options, false);
 
             } catch (JSONException e) {}
         }