Commit 7c5eefd0 by PKnittel

Restructured LocalNotification.java

parent 1694a815
...@@ -81,18 +81,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -81,18 +81,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("add")) { if (action.equalsIgnoreCase("add")) {
cordova.getThreadPool().execute( new Runnable() { cordova.getThreadPool().execute( new Runnable() {
public void run() { public void run() {
JSONArray notifications = args.optJSONArray(0); add(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);
}
command.success(); command.success();
} }
}); });
...@@ -101,13 +90,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -101,13 +90,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("update")) { if (action.equalsIgnoreCase("update")) {
cordova.getThreadPool().execute( new Runnable() { cordova.getThreadPool().execute( new Runnable() {
public void run() { public void run() {
JSONArray updates = args.optJSONArray(0); update(args);
JSONObject updateContent;
for(int i=0;i<updates.length();i++){
updateContent = args.optJSONObject(i);
nWrapper.update(updateContent);
}
command.success(); command.success();
} }
}); });
...@@ -116,15 +99,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -116,15 +99,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("cancel")) { if (action.equalsIgnoreCase("cancel")) {
cordova.getThreadPool().execute( new Runnable() { cordova.getThreadPool().execute( new Runnable() {
public void run() { public void run() {
JSONArray ids = args.optJSONArray(0); cancel(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);
}
command.success(); command.success();
} }
...@@ -134,16 +109,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -134,16 +109,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("cancelAll")) { if (action.equalsIgnoreCase("cancelAll")) {
cordova.getThreadPool().execute( new Runnable() { cordova.getThreadPool().execute( new Runnable() {
public void run() { public void run() {
JSONArray options = manager.getAll(); cancelAll(args);
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);
}
command.success(); command.success();
} }
}); });
...@@ -152,15 +118,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -152,15 +118,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("clear")) { if (action.equalsIgnoreCase("clear")) {
cordova.getThreadPool().execute( new Runnable() { cordova.getThreadPool().execute( new Runnable() {
public void run() { public void run() {
JSONArray ids = args.optJSONArray(0); clear(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);
}
command.success(); command.success();
} }
}); });
...@@ -169,16 +127,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -169,16 +127,7 @@ public class LocalNotification extends CordovaPlugin {
if (action.equalsIgnoreCase("clearAll")) { if (action.equalsIgnoreCase("clearAll")) {
cordova.getThreadPool().execute( new Runnable() { cordova.getThreadPool().execute( new Runnable() {
public void run() { public void run() {
JSONArray options = manager.getAll(); clearAll(args);
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);
}
command.success(); command.success();
} }
}); });
...@@ -274,7 +223,113 @@ public class LocalNotification extends CordovaPlugin { ...@@ -274,7 +223,113 @@ public class LocalNotification extends CordovaPlugin {
return true; return true;
} }
//------------------------------------------------exec-Functions-----------------------------------------------
/**
* Schedule notifications contained in the args-Array
* @param args
*/
private void add(JSONArray args){
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);
}
}
/**
* Update existing notifications
* @param args
*/
private void update(JSONArray args){
JSONArray updates = args.optJSONArray(0);
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.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 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.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 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. * Calls all pending callbacks after the deviceready event has been fired.
*/ */
......
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