Commit 0fd4ac32 authored by PKnittel's avatar PKnittel
Browse files

Fixed Bug with repeating notifications

parent fd76e891
Loading
Loading
Loading
Loading
+26 −0
Changes for src/android/DeleteIntentReceiver.java: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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);
        
        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());
    }

}