Commit d1e0d942 by Sebastián Katzer

Patch to add notification without blocking the ui thread on Android.

parent f5c49b06
...@@ -43,21 +43,19 @@ public class LocalNotification extends CordovaPlugin { ...@@ -43,21 +43,19 @@ public class LocalNotification extends CordovaPlugin {
@Override @Override
public boolean execute (String action, JSONArray args, CallbackContext callbackContext) throws JSONException { public boolean execute (String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
JSONObject arguments = args.getJSONObject(0);
LocalNotificationOptions options = new LocalNotificationOptions(arguments);
String alarmId = options.getId();
rememberCordovaVarsForStaticUse(); rememberCordovaVarsForStaticUse();
if (action.equalsIgnoreCase("add")) { if (action.equalsIgnoreCase("add")) {
persist(alarmId, args); addWithoutBlocking(args);
add(options);
return true; return true;
} }
if (action.equalsIgnoreCase("cancel")) { if (action.equalsIgnoreCase("cancel")) {
JSONObject arguments = args.getJSONObject(0);
LocalNotificationOptions options = new LocalNotificationOptions(arguments);
String alarmId = options.getId();
cancel(alarmId); cancel(alarmId);
unpersist(alarmId); unpersist(alarmId);
...@@ -75,6 +73,18 @@ public class LocalNotification extends CordovaPlugin { ...@@ -75,6 +73,18 @@ public class LocalNotification extends CordovaPlugin {
return false; return false;
} }
private static void addWithoutBlocking (final JSONArray args) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
JSONObject arguments = args.optJSONObject(0);
LocalNotificationOptions options = new LocalNotificationOptions(arguments);
persist(options.getId(), args);
add(options);
}
});
}
/** /**
* Set an alarm * Set an alarm
* *
......
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