Commit 7f6c1ce0 authored by PKnittel's avatar PKnittel
Browse files

Added onupdate event on android, to update repeating notifications automaticaly.

Fixed Issue with date during convertProperties call in the update function.
parent b9bb89a9
Loading
Loading
Loading
Loading
+0 −5
Changes for src/android/LocalNotification.java: 0 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.LOG;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
@@ -40,7 +39,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.util.Log;
import android.annotation.TargetApi;

import de.appplant.cordova.plugin.notification.*;
@@ -236,7 +234,6 @@ public class LocalNotification extends CordovaPlugin {
    	JSONObject arguments;
    	for(int i=0;i<notifications.length();i++){
    		arguments = notifications.optJSONObject(i);
        	LOG.d("LocalNotification", arguments.toString());
    		arguments = asset.parseURIs(arguments);
    		Options options      = new Options(context).parse(arguments);
    		options.setInitDate();
@@ -415,7 +412,6 @@ public class LocalNotification extends CordovaPlugin {

        // webview may available, but callbacks needs to be executed
        // after deviceready
        Log.e("FireEvent","JS-String: "+ js);
        if (deviceready == false) {
            eventQueue.add(js);
        } else {
@@ -439,7 +435,6 @@ public class LocalNotification extends CordovaPlugin {
    
    	// webview may available, but callbacks needs to be executed
    	// after deviceready
    	Log.e("FireEvent","JS-String: "+ js);
    	if (deviceready == false) {
    		eventQueue.add(js);
    	} else {
+2 −0
Changes for src/android/Receiver.java: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ public class Receiver extends BroadcastReceiver {
        } else if (isFirstAlarmInFuture()) {
            return;
        } else {
        	JSONArray data = new JSONArray().put(options.getJSONObject());
        	LocalNotification.fireEvent("updateCall", options.getId(), options.getJSON(),data);
            nWrapper.schedule(options.moveDate());
        }
        if (!LocalNotification.isInBackground && options.getForegroundMode()){
+76 −1
Changes for www/local-notification.js: 76 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ exports.update = function (opts, callback, scope) {
    for (var i = 0; i < notifications.length; i++) {
        var properties = notifications[i];

        this.convertProperties(properties);
        this.convertUpdateProperties(properties);
    }

    this.exec('update', notifications, callback, scope);
@@ -559,6 +559,42 @@ exports.oncancel = function (id, state, json, data) {};
 */
exports.onclear = function (id, state, json, data) {};

/**
 * Get fired when a repeating notification should be updated.
 *
 * @param {String} id
 *      The ID of the notification
 * @param {String} state
 *      Either "foreground" or "background"
 * @param {String} json
 *      A custom (JSON) string
 * @param {Object} data
 *      The notification properties
 * @return {Object} JSONObject with updatevalues
 */
exports.onupdate = function (id, state, json, data) {
	return null;
};
	
/**
 * Is called from the native part to receive the onupdate resultarray and send it back to native.
 *
 * @param {String} id
 *      The ID of the notification
 * @param {String} state
 *      Either "foreground" or "background"
 * @param {String} json
 *      A custom (JSON) string
 * @param {Object} data
 *      The notification properties
 */
exports.onupdateCall = function (id, state, json, data) {
	var updates = exports.onupdate(id, state, json, data);
	if (updates != null){
		updates.id = id;
		update(updates,null,null);
	};
};

/**
 * @private
@@ -636,6 +672,45 @@ exports.convertProperties = function (options) {
    return options;
};

/**
 * @private
 *
 * Convert the passed values to their required type only for update function.
 *
 * @param {Object} options
 *      Set of custom values
 *
 * @retrun {Object}
 *      The converted property list
 */
exports.convertUpdateProperties = function (options) {

    options.id         = options.id.toString();
    options.title      = options.title.toString();
    options.message    = options.message.toString();
    options.autoCancel = options.autoCancel === true;

    if (isNaN(options.id)) {
        options.id = this.getDefaults().id;
    }

    if (isNaN(options.badge)) {
        options.badge = this.getDefaults().badge;
    }

    options.badge = Number(options.badge);

    if (typeof options.date == 'object') {
        options.date = Math.round(options.date.getTime()/1000);
    }

    if (typeof options.json == 'object') {
        options.json = JSON.stringify(options.json);
    }

    return options;
};

/**
 * @private
 *