Commit 01ffae10 by Sebastián Katzer

Update example

parent aa24cd44
......@@ -10,8 +10,8 @@
</intent-filter>
</activity>
<service android:name="de.appplant.cordova.plugin.background.ForegroundService" />
<receiver android:name="de.appplant.cordova.plugin.localnotification.Receiver" />
<receiver android:name="de.appplant.cordova.plugin.localnotification.DeleteIntentReceiver" />
<receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.Receiver" />
<receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.DeleteIntentReceiver" />
<receiver android:name="de.appplant.cordova.plugin.localnotification.Restore">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
......
......@@ -12,6 +12,7 @@ module.exports = [
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [
"cordova.plugins.notification.local",
"plugin.notification.local"
]
},
......
......@@ -159,7 +159,7 @@ exports.update = function (opts, callback, scope) {
exports.clear = function (ids, callback, scope) {
ids = Array.isArray(ids) ? ids : [ids];
ids = this.convertIds(ids);
ids = this.convertIds(ids);
this.exec('clear', ids, callback, scope);
};
......@@ -488,12 +488,22 @@ exports.onclear = function (id, state, json, data) {};
exports.mergeWithDefaults = function (options) {
var defaults = this.getDefaults();
options.date = this.getValueFor(options, 'date', 'at', 'firstAt');
options.repeat = this.getValueFor(options, 'repeat', 'every');
options.message = this.getValueFor(options, 'message', 'text');
for (var key in defaults) {
if (options[key] === undefined) {
if (options[key] === null || options[key] === undefined) {
options[key] = defaults[key];
}
}
for (key in options) {
if (!defaults.hasOwnProperty(key)) {
delete options[key];
}
}
return options;
};
......@@ -509,24 +519,24 @@ exports.mergeWithDefaults = function (options) {
* The converted property list
*/
exports.convertProperties = function (options) {
if (options.id) {
options.id = options.id.toString();
}
if (options.date === undefined) {
options.date = new Date();
}
options.id = options.id.toString();
options.title = options.title.toString();
options.message = options.message.toString();
options.autoCancel = options.autoCancel === true;
if (options.title) {
options.title = options.title.toString();
if (isNaN(options.id)) {
options.id = this.getDefaults().id;
}
if (options.message) {
options.message = options.message.toString();
if (isNaN(options.badge)) {
options.badge = this.getDefaults().badge;
}
if (options.text) {
options.message = options.text.toString();
options.badge = Number(options.badge);
if (options.date === undefined || options.date === null) {
options.date = new Date();
}
if (typeof options.date == 'object') {
......@@ -613,6 +623,27 @@ exports.convertIds = function (ids) {
/**
* @private
*
* Return the first found value for the given keys.
*
* @param {Object} options
* Object with key-value properties
*
* @param {String[]} keys*
* Key list
*/
exports.getValueFor = function (options) {
var keys = Array.apply(null, arguments).slice(1);
for (var key in keys) {
if (options.hasOwnProperty(key)) {
return options[key];
}
}
};
/**
* @private
*
* Executes the native counterpart.
*
* @param {String} action
......
......@@ -81,18 +81,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("add")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray notifications = args.optJSONArray(0);
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();
nWrapper.schedule(options);
JSONArray data = new JSONArray().put(options.getJSONObject());
fireEvent("add", options.getId(), options.getJSON(), data);
}
add(args);
command.success();
}
});
......@@ -101,13 +90,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("update")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray updates = args.optJSONArray(0);
JSONObject updateContent;
for(int i=0;i<updates.length();i++){
updateContent = args.optJSONObject(i);
nWrapper.update(updateContent);
}
update(args);
command.success();
}
});
......@@ -116,15 +99,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("cancel")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray ids = args.optJSONArray(0);
String id;
for(int i=0;i<ids.length();i++){
id = args.optString(i);
nWrapper.cancel(id);
JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId));
fireEvent("cancel", id, "",data);
}
cancel(args);
command.success();
}
......@@ -134,16 +109,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("cancelAll")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray options = manager.getAll();
nWrapper.cancelAll();
String id;
JSONObject arguments;
for(int i=0;i<options.length();i++){
arguments= (JSONObject) options.opt(i);
JSONArray data = new JSONArray().put(arguments);
id = arguments.optString("id");
fireEvent("cancel", id, "",data);
}
cancelAll(args);
command.success();
}
});
......@@ -152,15 +118,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("clear")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray ids = args.optJSONArray(0);
String id;
for(int i=0;i<ids.length();i++){
id = args.optString(i);
nWrapper.clear(id);
JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId));
fireEvent("clear", id, "",data);
}
clear(args);
command.success();
}
});
......@@ -169,16 +127,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("clearAll")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray options = manager.getAll();
nWrapper.clearAll();
String id;
JSONObject arguments;
for(int i=0;i<options.length();i++){
arguments= (JSONObject) options.opt(i);
JSONArray data = new JSONArray().put(arguments);
id = arguments.optString("id");
fireEvent("clear", id, "",data);
}
clearAll(args);
command.success();
}
});
......@@ -274,7 +223,113 @@ public class LocalNotification extends CordovaPlugin {
return true;
}
//------------------------------------------------exec-Functions-----------------------------------------------
/**
* Schedule notifications contained in the args-Array
* @param args
*/
private void add(JSONArray args){
JSONArray notifications = args;
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();
nWrapper.schedule(options);
JSONArray data = new JSONArray().put(options.getJSONObject());
fireEvent("add", options.getId(), options.getJSON(), data);
}
}
/**
* Update existing notifications
* @param args
*/
private void update(JSONArray args){
JSONArray updates = args;
JSONObject updateContent;
for(int i=0;i<updates.length();i++){
updateContent = args.optJSONObject(i);
nWrapper.update(updateContent);
}
}
/**
* Cancel scheduled Notifications
* @param args
*/
private void cancel(JSONArray args){
JSONArray ids = args;
String id;
for(int i=0;i<ids.length();i++){
id = args.optString(i);
nWrapper.cancel(id);
JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId));
fireEvent("cancel", id, "",data);
}
}
/**
* Cancel all scheduled notifications
* @param args
*/
public void cancelAll(JSONArray args){
JSONArray options = manager.getAll();
nWrapper.cancelAll();
String id;
JSONObject arguments;
for(int i=0;i<options.length();i++){
arguments= (JSONObject) options.opt(i);
JSONArray data = new JSONArray().put(arguments);
id = arguments.optString("id");
fireEvent("cancel", id, "",data);
}
}
/**
* Clear triggered notifications without cancel repeating.
* @param args
*/
public void clear(JSONArray args){
JSONArray ids = args;
String id;
for(int i=0;i<ids.length();i++){
id = args.optString(i);
nWrapper.clear(id);
JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId));
fireEvent("clear", id, "",data);
}
}
/**
* Clear all triggered notifications without cancel repeating.
* @param args
*/
public void clearAll(JSONArray args){
JSONArray options = manager.getAll();
nWrapper.clearAll();
String id;
JSONObject arguments;
for(int i=0;i<options.length();i++){
arguments= (JSONObject) options.opt(i);
JSONArray data = new JSONArray().put(arguments);
id = arguments.optString("id");
fireEvent("clear", id, "",data);
}
}
//-------------------------------------------------------------------------------------------------------------
/**
* Calls all pending callbacks after the deviceready event has been fired.
*/
......
......@@ -32,6 +32,8 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat.Builder;
import de.appplant.cordova.plugin.notification.*;
/**
......@@ -80,12 +82,12 @@ public class Receiver extends BroadcastReceiver {
if (options.getInterval() == 0) {
LocalNotification.unpersist(options.getId());
}
builder.showNotificationToast();
nWrapper.showNotificationToast(options);
fireTriggerEvent();
} else {
builder.buildNotification();
Builder notification = builder.buildNotification();
builder.showNotification();
nWrapper.showNotification(notification, options);
}
}
......
......@@ -43,13 +43,12 @@
7E7966E71810823500FA85AD /* icon-small@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7E7966DD1810823500FA85AD /* icon-small@2x.png */; };
9E1A68381A55FA1B00FBCA66 /* beep.caf in Resources */ = {isa = PBXBuildFile; fileRef = 9E1A68371A55FA1B00FBCA66 /* beep.caf */; };
9E5A62291A52DE07002E41A3 /* (null) in Sources */ = {isa = PBXBuildFile; };
9EE7232C1A5939070081D0D2 /* AppDelegate+APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EE7232B1A5939070081D0D2 /* AppDelegate+APPLocalNotification.m */; };
D4A0D8761607E02300AEF8BB /* Default-568h@2x~iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = D4A0D8751607E02300AEF8BB /* Default-568h@2x~iphone.png */; };
CA0BCB16FD114E5D98BB8665 /* APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = B7A9F628139346BE899623CA /* APPLocalNotification.m */; };
8D642299F02F486292B3C76E /* APPLocalNotificationOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = EEBC8449D0FA45AD8BED33D9 /* APPLocalNotificationOptions.m */; };
210AC435FA28427D89EF30B0 /* AppDelegate+APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 05D703B6E20A498E8D8AE569 /* AppDelegate+APPLocalNotification.m */; };
9D4370C7345340D7A4AA7847 /* UIApplication+APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = C8655474DBF6499D9A190B41 /* UIApplication+APPLocalNotification.m */; };
915750F942AB41089D8C019C /* UILocalNotification+APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C3C8CF254E4643AA6619F8 /* UILocalNotification+APPLocalNotification.m */; };
90D59C90545F4506982554E8 /* APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = EE4654C98F394A8DBDE0AC57 /* APPLocalNotification.m */; };
BD757B0D44BE440083918077 /* APPLocalNotificationOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 37095E752E9D455C853BE373 /* APPLocalNotificationOptions.m */; };
244C5454167242FABDACC376 /* AppDelegate+APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 028AC353A09C4EA79A266646 /* AppDelegate+APPLocalNotification.m */; };
F809B57D91144ACBA4D15DE6 /* UIApplication+APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4288BC92A44887AE839CAE /* UIApplication+APPLocalNotification.m */; };
F378B9146F0E46C2BD460ED2 /* UILocalNotification+APPLocalNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E55360F8342488798514532 /* UILocalNotification+APPLocalNotification.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -118,16 +117,16 @@
EB87FDF41871DAF40020F90C /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = ../../config.xml; sourceTree = "<group>"; };
F042F1C3B49D4E2699FF5E1D /* CDVDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVDevice.h; path = org.apache.cordova.device/CDVDevice.h; sourceTree = "<group>"; };
F840E1F0165FE0F500CFE078 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = NotificationExample/config.xml; sourceTree = "<group>"; };
B7A9F628139346BE899623CA /* APPLocalNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "APPLocalNotification.m"; path = "de.appplant.cordova.plugin.local-notification/APPLocalNotification.m"; sourceTree = "<group>"; fileEncoding = 4; };
EEBC8449D0FA45AD8BED33D9 /* APPLocalNotificationOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "APPLocalNotificationOptions.m"; path = "de.appplant.cordova.plugin.local-notification/APPLocalNotificationOptions.m"; sourceTree = "<group>"; fileEncoding = 4; };
05D703B6E20A498E8D8AE569 /* AppDelegate+APPLocalNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "AppDelegate+APPLocalNotification.m"; path = "de.appplant.cordova.plugin.local-notification/AppDelegate+APPLocalNotification.m"; sourceTree = "<group>"; fileEncoding = 4; };
C8655474DBF6499D9A190B41 /* UIApplication+APPLocalNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "UIApplication+APPLocalNotification.m"; path = "de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.m"; sourceTree = "<group>"; fileEncoding = 4; };
84C3C8CF254E4643AA6619F8 /* UILocalNotification+APPLocalNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "UILocalNotification+APPLocalNotification.m"; path = "de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.m"; sourceTree = "<group>"; fileEncoding = 4; };
127A135649D64CABB0063273 /* APPLocalNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "APPLocalNotification.h"; path = "de.appplant.cordova.plugin.local-notification/APPLocalNotification.h"; sourceTree = "<group>"; fileEncoding = 4; };
B3D907064563496780573DE7 /* APPLocalNotificationOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "APPLocalNotificationOptions.h"; path = "de.appplant.cordova.plugin.local-notification/APPLocalNotificationOptions.h"; sourceTree = "<group>"; fileEncoding = 4; };
FB8D07B5AA2E400F9E8F513D /* AppDelegate+APPLocalNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "AppDelegate+APPLocalNotification.h"; path = "de.appplant.cordova.plugin.local-notification/AppDelegate+APPLocalNotification.h"; sourceTree = "<group>"; fileEncoding = 4; };
D98538C2D7AC4EDC9D924184 /* UIApplication+APPLocalNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UIApplication+APPLocalNotification.h"; path = "de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.h"; sourceTree = "<group>"; fileEncoding = 4; };
EF204AFEDEC24A64A5F26DF6 /* UILocalNotification+APPLocalNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UILocalNotification+APPLocalNotification.h"; path = "de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.h"; sourceTree = "<group>"; fileEncoding = 4; };
EE4654C98F394A8DBDE0AC57 /* APPLocalNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "APPLocalNotification.m"; path = "de.appplant.cordova.plugin.local-notification/APPLocalNotification.m"; sourceTree = "<group>"; fileEncoding = 4; };
37095E752E9D455C853BE373 /* APPLocalNotificationOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "APPLocalNotificationOptions.m"; path = "de.appplant.cordova.plugin.local-notification/APPLocalNotificationOptions.m"; sourceTree = "<group>"; fileEncoding = 4; };
028AC353A09C4EA79A266646 /* AppDelegate+APPLocalNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "AppDelegate+APPLocalNotification.m"; path = "de.appplant.cordova.plugin.local-notification/AppDelegate+APPLocalNotification.m"; sourceTree = "<group>"; fileEncoding = 4; };
4C4288BC92A44887AE839CAE /* UIApplication+APPLocalNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "UIApplication+APPLocalNotification.m"; path = "de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.m"; sourceTree = "<group>"; fileEncoding = 4; };
5E55360F8342488798514532 /* UILocalNotification+APPLocalNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "UILocalNotification+APPLocalNotification.m"; path = "de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.m"; sourceTree = "<group>"; fileEncoding = 4; };
C37D37FB86E04E16BA8047EE /* APPLocalNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "APPLocalNotification.h"; path = "de.appplant.cordova.plugin.local-notification/APPLocalNotification.h"; sourceTree = "<group>"; fileEncoding = 4; };
B22193F3CC42466498BF03A8 /* APPLocalNotificationOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "APPLocalNotificationOptions.h"; path = "de.appplant.cordova.plugin.local-notification/APPLocalNotificationOptions.h"; sourceTree = "<group>"; fileEncoding = 4; };
2C2F7D7BF58F46B4ADDA1E7E /* AppDelegate+APPLocalNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "AppDelegate+APPLocalNotification.h"; path = "de.appplant.cordova.plugin.local-notification/AppDelegate+APPLocalNotification.h"; sourceTree = "<group>"; fileEncoding = 4; };
EF7CC58EF6424BB183C2CE58 /* UIApplication+APPLocalNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UIApplication+APPLocalNotification.h"; path = "de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.h"; sourceTree = "<group>"; fileEncoding = 4; };
CAD9B6E7C8424F74AF0AA068 /* UILocalNotification+APPLocalNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UILocalNotification+APPLocalNotification.h"; path = "de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.h"; sourceTree = "<group>"; fileEncoding = 4; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -231,16 +230,16 @@
212EBD1D7BCB4409838CD818 /* CDVDevice.m */,
3C888438876C480D8B36E11A /* APPBackgroundMode.h */,
DDDFCE9D76CA4692A1F4A984 /* APPBackgroundMode.m */,
B7A9F628139346BE899623CA /* APPLocalNotification.m */,
EEBC8449D0FA45AD8BED33D9 /* APPLocalNotificationOptions.m */,
05D703B6E20A498E8D8AE569 /* AppDelegate+APPLocalNotification.m */,
C8655474DBF6499D9A190B41 /* UIApplication+APPLocalNotification.m */,
84C3C8CF254E4643AA6619F8 /* UILocalNotification+APPLocalNotification.m */,
127A135649D64CABB0063273 /* APPLocalNotification.h */,
B3D907064563496780573DE7 /* APPLocalNotificationOptions.h */,
FB8D07B5AA2E400F9E8F513D /* AppDelegate+APPLocalNotification.h */,
D98538C2D7AC4EDC9D924184 /* UIApplication+APPLocalNotification.h */,
EF204AFEDEC24A64A5F26DF6 /* UILocalNotification+APPLocalNotification.h */,
EE4654C98F394A8DBDE0AC57 /* APPLocalNotification.m */,
37095E752E9D455C853BE373 /* APPLocalNotificationOptions.m */,
028AC353A09C4EA79A266646 /* AppDelegate+APPLocalNotification.m */,
4C4288BC92A44887AE839CAE /* UIApplication+APPLocalNotification.m */,
5E55360F8342488798514532 /* UILocalNotification+APPLocalNotification.m */,
C37D37FB86E04E16BA8047EE /* APPLocalNotification.h */,
B22193F3CC42466498BF03A8 /* APPLocalNotificationOptions.h */,
2C2F7D7BF58F46B4ADDA1E7E /* AppDelegate+APPLocalNotification.h */,
EF7CC58EF6424BB183C2CE58 /* UIApplication+APPLocalNotification.h */,
CAD9B6E7C8424F74AF0AA068 /* UILocalNotification+APPLocalNotification.h */,
);
name = Plugins;
path = NotificationExample/Plugins;
......@@ -427,16 +426,16 @@
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
1D3623260D0F684500981E51 /* AppDelegate.m in Sources */,
302D95F114D2391D003F00A1 /* MainViewController.m in Sources */,
9EE7232C1A5939070081D0D2 /* AppDelegate+APPLocalNotification.m in Sources */,
9E5A62291A52DE07002E41A3 /* (null) in Sources */,
0B33C5FC1B224A91B96FDE79 /* CDVDevice.m in Sources */,
3DBE1CCC022B412AA9E356AF /* APPBackgroundMode.m in Sources */,
0FFC7382D3B74FADB62619F0 /* UIApplication+APPLocalNotification.h in Sources */,
CA0BCB16FD114E5D98BB8665 /* APPLocalNotification.m in Sources */,
8D642299F02F486292B3C76E /* APPLocalNotificationOptions.m in Sources */,
210AC435FA28427D89EF30B0 /* AppDelegate+APPLocalNotification.m in Sources */,
9D4370C7345340D7A4AA7847 /* UIApplication+APPLocalNotification.m in Sources */,
915750F942AB41089D8C019C /* UILocalNotification+APPLocalNotification.m in Sources */,
90D59C90545F4506982554E8 /* APPLocalNotification.m in Sources */,
BD757B0D44BE440083918077 /* APPLocalNotificationOptions.m in Sources */,
244C5454167242FABDACC376 /* AppDelegate+APPLocalNotification.m in Sources */,
F809B57D91144ACBA4D15DE6 /* UIApplication+APPLocalNotification.m in Sources */,
F378B9146F0E46C2BD460ED2 /* UILocalNotification+APPLocalNotification.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -604,13 +604,16 @@
NSString* json = notification.options.json;
NSString* args = [notification encodeToJSON];
json = [json stringByReplacingOccurrencesOfString:@"'"
withString:@"\\\\\\'"];
params = [NSString stringWithFormat:
@"\"%@\",\"%@\",\\'%@\\',JSON.parse(\\'%@\\')",
id, self.applicationState, json, args];
}
js = [NSString stringWithFormat:
@"setTimeout('plugin.notification.local.on%@(%@)',0)",
@"setTimeout('cordova.plugins.notification.local.on%@(%@)',0)",
event, params];
if (deviceready) {
......
......@@ -12,6 +12,7 @@ module.exports = [
"file": "plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js",
"id": "de.appplant.cordova.plugin.local-notification.LocalNotification",
"clobbers": [
"cordova.plugins.notification.local",
"plugin.notification.local"
]
},
......
......@@ -129,11 +129,7 @@
};
schedule = function () {
plugin.notification.local.add({
id: id,
message: 'Test Message ' + (++counter),
json: { test:id }
});
window.plugin.notification.local.add({message: 'Great app!'});
};
scheduleMultiple = function () {
......@@ -229,18 +225,22 @@
<script type="text/javascript">
document.addEventListener('deviceready', function () {
plugin.notification.local.onadd = function (id, state, json) {
console.log(arguments);
alert('on add\n' + Array.apply(null, arguments).join("\n"));
};
plugin.notification.local.ontrigger = function (id, state, json) {
console.log(arguments);
alert('on trigger\n' + Array.apply(null, arguments).join("\n"));
};
plugin.notification.local.onclick = function (id, state, json) {
console.log(arguments);
alert('on click\n' + Array.apply(null, arguments).join("\n"));
};
plugin.notification.local.oncancel = function (id, state, json) {
console.log(arguments);
alert('on cancel\n' + Array.apply(null, arguments).join("\n"));
};
}, false);
......
......@@ -159,7 +159,7 @@ exports.update = function (opts, callback, scope) {
exports.clear = function (ids, callback, scope) {
ids = Array.isArray(ids) ? ids : [ids];
ids = this.convertIds(ids);
ids = this.convertIds(ids);
this.exec('clear', ids, callback, scope);
};
......@@ -488,12 +488,22 @@ exports.onclear = function (id, state, json, data) {};
exports.mergeWithDefaults = function (options) {
var defaults = this.getDefaults();
options.date = this.getValueFor(options, 'date', 'at', 'firstAt');
options.repeat = this.getValueFor(options, 'repeat', 'every');
options.message = this.getValueFor(options, 'message', 'text');
for (var key in defaults) {
if (options[key] === undefined) {
if (options[key] === null || options[key] === undefined) {
options[key] = defaults[key];
}
}
for (key in options) {
if (!defaults.hasOwnProperty(key)) {
delete options[key];
}
}
return options;
};
......@@ -509,24 +519,24 @@ exports.mergeWithDefaults = function (options) {
* The converted property list
*/
exports.convertProperties = function (options) {
if (options.id) {
options.id = options.id.toString();
}
if (options.date === undefined) {
options.date = new Date();
}
options.id = options.id.toString();
options.title = options.title.toString();
options.message = options.message.toString();
options.autoCancel = options.autoCancel === true;
if (options.title) {
options.title = options.title.toString();
if (isNaN(options.id)) {
options.id = this.getDefaults().id;
}
if (options.message) {
options.message = options.message.toString();
if (isNaN(options.badge)) {
options.badge = this.getDefaults().badge;
}
if (options.text) {
options.message = options.text.toString();
options.badge = Number(options.badge);
if (options.date === undefined || options.date === null) {
options.date = new Date();
}
if (typeof options.date == 'object') {
......@@ -613,6 +623,29 @@ exports.convertIds = function (ids) {
/**
* @private
*
* Return the first found value for the given keys.
*
* @param {Object} options
* Object with key-value properties
*
* @param {String[]} keys*
* Key list
*/
exports.getValueFor = function (options) {
var keys = Array.apply(null, arguments).slice(1);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (options.hasOwnProperty(key)) {
return options[key];
}
}
};
/**
* @private
*
* Executes the native counterpart.
*
* @param {String} action
......
......@@ -35,11 +35,11 @@
"count": 1
},
{
"xml": "<receiver android:name=\"de.appplant.cordova.plugin.localnotification.Receiver\" />",
"xml": "<receiver android:exported=\"false\" android:name=\"de.appplant.cordova.plugin.localnotification.Receiver\" />",
"count": 1
},
{
"xml": "<receiver android:name=\"de.appplant.cordova.plugin.localnotification.DeleteIntentReceiver\" />",
"xml": "<receiver android:exported=\"false\" android:name=\"de.appplant.cordova.plugin.localnotification.DeleteIntentReceiver\" />",
"count": 1
},
{
......
......@@ -21,6 +21,7 @@
<dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device" />
<js-module src="www/local-notification.js" name="LocalNotification">
<clobbers target="cordova.plugins.notification.local" />
<clobbers target="plugin.notification.local" />
</js-module>
......@@ -64,13 +65,13 @@
* Android notification bar. The notification uses the default notification
* sound and it vibrates the phone.
-->
<receiver android:name="de.appplant.cordova.plugin.localnotification.Receiver" />
<receiver android:name="de.appplant.cordova.plugin.localnotification.Receiver" android:exported="false" />
<!--
* The delete intent receiver is triggered when the user clears a notification
* manually. It unpersists the cleared notification from the shared preferences.
-->
<receiver android:name="de.appplant.cordova.plugin.localnotification.DeleteIntentReceiver" />
<receiver android:name="de.appplant.cordova.plugin.localnotification.DeleteIntentReceiver" android:exported="false"/>
<!--
* This class is triggered upon reboot of the device. It needs to re-register
......
......@@ -81,18 +81,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("add")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray notifications = args.optJSONArray(0);
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();
nWrapper.schedule(options);
JSONArray data = new JSONArray().put(options.getJSONObject());
fireEvent("add", options.getId(), options.getJSON(), data);
}
add(args);
command.success();
}
});
......@@ -101,13 +90,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("update")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray updates = args.optJSONArray(0);
JSONObject updateContent;
for(int i=0;i<updates.length();i++){
updateContent = args.optJSONObject(i);
nWrapper.update(updateContent);
}
update(args);
command.success();
}
});
......@@ -116,15 +99,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("cancel")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray ids = args.optJSONArray(0);
String id;
for(int i=0;i<ids.length();i++){
id = args.optString(i);
nWrapper.cancel(id);
JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId));
fireEvent("cancel", id, "",data);
}
cancel(args);
command.success();
}
......@@ -134,16 +109,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("cancelAll")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray options = manager.getAll();
nWrapper.cancelAll();
String id;
JSONObject arguments;
for(int i=0;i<options.length();i++){
arguments= (JSONObject) options.opt(i);
JSONArray data = new JSONArray().put(arguments);
id = arguments.optString("id");
fireEvent("cancel", id, "",data);
}
cancelAll(args);
command.success();
}
});
......@@ -152,15 +118,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("clear")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray ids = args.optJSONArray(0);
String id;
for(int i=0;i<ids.length();i++){
id = args.optString(i);
nWrapper.clear(id);
JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId));
fireEvent("clear", id, "",data);
}
clear(args);
command.success();
}
});
......@@ -169,16 +127,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("clearAll")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
JSONArray options = manager.getAll();
nWrapper.clearAll();
String id;
JSONObject arguments;
for(int i=0;i<options.length();i++){
arguments= (JSONObject) options.opt(i);
JSONArray data = new JSONArray().put(arguments);
id = arguments.optString("id");
fireEvent("clear", id, "",data);
}
clearAll(args);
command.success();
}
});
......@@ -274,7 +223,113 @@ public class LocalNotification extends CordovaPlugin {
return true;
}
//------------------------------------------------exec-Functions-----------------------------------------------
/**
* Schedule notifications contained in the args-Array
* @param args
*/
private void add(JSONArray args){
JSONArray notifications = args;
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();
nWrapper.schedule(options);
JSONArray data = new JSONArray().put(options.getJSONObject());
fireEvent("add", options.getId(), options.getJSON(), data);
}
}
/**
* Update existing notifications
* @param args
*/
private void update(JSONArray args){
JSONArray updates = args;
JSONObject updateContent;
for(int i=0;i<updates.length();i++){
updateContent = args.optJSONObject(i);
nWrapper.update(updateContent);
}
}
/**
* Cancel scheduled Notifications
* @param args
*/
private void cancel(JSONArray args){
JSONArray ids = args;
String id;
for(int i=0;i<ids.length();i++){
id = args.optString(i);
nWrapper.cancel(id);
JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId));
fireEvent("cancel", id, "",data);
}
}
/**
* Cancel all scheduled notifications
* @param args
*/
public void cancelAll(JSONArray args){
JSONArray options = manager.getAll();
nWrapper.cancelAll();
String id;
JSONObject arguments;
for(int i=0;i<options.length();i++){
arguments= (JSONObject) options.opt(i);
JSONArray data = new JSONArray().put(arguments);
id = arguments.optString("id");
fireEvent("cancel", id, "",data);
}
}
/**
* Clear triggered notifications without cancel repeating.
* @param args
*/
public void clear(JSONArray args){
JSONArray ids = args;
String id;
for(int i=0;i<ids.length();i++){
id = args.optString(i);
nWrapper.clear(id);
JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId));
fireEvent("clear", id, "",data);
}
}
/**
* Clear all triggered notifications without cancel repeating.
* @param args
*/
public void clearAll(JSONArray args){
JSONArray options = manager.getAll();
nWrapper.clearAll();
String id;
JSONObject arguments;
for(int i=0;i<options.length();i++){
arguments= (JSONObject) options.opt(i);
JSONArray data = new JSONArray().put(arguments);
id = arguments.optString("id");
fireEvent("clear", id, "",data);
}
}
//-------------------------------------------------------------------------------------------------------------
/**
* Calls all pending callbacks after the deviceready event has been fired.
*/
......
......@@ -32,6 +32,8 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat.Builder;
import de.appplant.cordova.plugin.notification.*;
/**
......@@ -80,12 +82,12 @@ public class Receiver extends BroadcastReceiver {
if (options.getInterval() == 0) {
LocalNotification.unpersist(options.getId());
}
builder.showNotificationToast();
nWrapper.showNotificationToast(options);
fireTriggerEvent();
} else {
builder.buildNotification();
Builder notification = builder.buildNotification();
builder.showNotification();
nWrapper.showNotification(notification, options);
}
}
......
......@@ -604,6 +604,9 @@
NSString* json = notification.options.json;
NSString* args = [notification encodeToJSON];
json = [json stringByReplacingOccurrencesOfString:@"'"
withString:@"\\\\\\'"];
params = [NSString stringWithFormat:
@"\"%@\",\"%@\",\\'%@\\',JSON.parse(\\'%@\\')",
id, self.applicationState, json, args];
......
......@@ -159,7 +159,7 @@ exports.update = function (opts, callback, scope) {
exports.clear = function (ids, callback, scope) {
ids = Array.isArray(ids) ? ids : [ids];
ids = this.convertIds(ids);
ids = this.convertIds(ids);
this.exec('clear', ids, callback, scope);
};
......@@ -488,12 +488,22 @@ exports.onclear = function (id, state, json, data) {};
exports.mergeWithDefaults = function (options) {
var defaults = this.getDefaults();
options.date = this.getValueFor(options, 'date', 'at', 'firstAt');
options.repeat = this.getValueFor(options, 'repeat', 'every');
options.message = this.getValueFor(options, 'message', 'text');
for (var key in defaults) {
if (options[key] === undefined) {
if (options[key] === null || options[key] === undefined) {
options[key] = defaults[key];
}
}
for (key in options) {
if (!defaults.hasOwnProperty(key)) {
delete options[key];
}
}
return options;
};
......@@ -509,24 +519,24 @@ exports.mergeWithDefaults = function (options) {
* The converted property list
*/
exports.convertProperties = function (options) {
if (options.id) {
options.id = options.id.toString();
}
if (options.date === undefined) {
options.date = new Date();
}
options.id = options.id.toString();
options.title = options.title.toString();
options.message = options.message.toString();
options.autoCancel = options.autoCancel === true;
if (options.title) {
options.title = options.title.toString();
if (isNaN(options.id)) {
options.id = this.getDefaults().id;
}
if (options.message) {
options.message = options.message.toString();
if (isNaN(options.badge)) {
options.badge = this.getDefaults().badge;
}
if (options.text) {
options.message = options.text.toString();
options.badge = Number(options.badge);
if (options.date === undefined || options.date === null) {
options.date = new Date();
}
if (typeof options.date == 'object') {
......@@ -613,6 +623,27 @@ exports.convertIds = function (ids) {
/**
* @private
*
* Return the first found value for the given keys.
*
* @param {Object} options
* Object with key-value properties
*
* @param {String[]} keys*
* Key list
*/
exports.getValueFor = function (options) {
var keys = Array.apply(null, arguments).slice(1);
for (var key in keys) {
if (options.hasOwnProperty(key)) {
return options[key];
}
}
};
/**
* @private
*
* Executes the native counterpart.
*
* @param {String} action
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment