瀏覽代碼

Fixed Bug with repeating notifications

PKnittel 11 年之前
父節點
當前提交
0fd4ac32d4
共有 1 個文件被更改,包括 28 次插入2 次删除
  1. 28 2
      src/android/DeleteIntentReceiver.java

+ 28 - 2
src/android/DeleteIntentReceiver.java

@@ -21,6 +21,8 @@
 
 package de.appplant.cordova.plugin.localnotification;
 
+import java.util.Date;
+
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -49,8 +51,32 @@ public class DeleteIntentReceiver extends BroadcastReceiver {
         // The context may got lost if the app was not running before
         LocalNotification.setContext(context);
         
-        LocalNotification.unpersist(options.getId());
-
+        Date now = new Date();
+		if ((options.getInterval()!=0)){
+			LocalNotification.persist(options.getId(), setInitDate(args));
+		}
+		else if((new Date(options.getDate()).before(now))){
+			LocalNotification.unpersist(options.getId());
+		}
+		
+		fireClearEvent(options);
 	}
+	
+	private JSONObject setInitDate(JSONObject arguments){
+    	long initialDate = arguments.optLong("date", 0) * 1000;
+    	try {
+    		arguments.put("initialDate", initialDate);
+		} catch (JSONException e) {
+			e.printStackTrace();
+		}
+    	return arguments;
+    }
+	
+    /**
+     * Fires onclear event.
+     */
+    private void fireClearEvent (Options options) {
+        LocalNotification.fireEvent("clear", options.getId(), options.getJSON());
+    }
 
 }