mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Fix contact mobile-spec tests that were failing.
Also move contact operations back to background threads.
This commit is contained in:
parent
e562e4e7b9
commit
1bc032853c
@ -53,7 +53,7 @@ public class ContactManager extends CordovaPlugin {
|
|||||||
* @param callbackContext The callback context used when calling back into JavaScript.
|
* @param callbackContext The callback context used when calling back into JavaScript.
|
||||||
* @return True if the action was valid, false otherwise.
|
* @return True if the action was valid, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) {
|
||||||
/**
|
/**
|
||||||
* Check to see if we are on an Android 1.X device. If we are return an error as we
|
* Check to see if we are on an Android 1.X device. If we are return an error as we
|
||||||
* do not support this as of Cordova 1.0.
|
* do not support this as of Cordova 1.0.
|
||||||
@ -73,22 +73,47 @@ public class ContactManager extends CordovaPlugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (action.equals("search")) {
|
if (action.equals("search")) {
|
||||||
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
|
final JSONArray filter = args.getJSONArray(0);
|
||||||
callbackContext.success(res);
|
final JSONObject options = args.getJSONObject(1);
|
||||||
}
|
this.cordova.getThreadPool().execute(new Runnable() {
|
||||||
else if (action.equals("save")) {
|
public void run() {
|
||||||
String id = contactAccessor.save(args.getJSONObject(0));
|
JSONArray res = contactAccessor.search(filter, options);
|
||||||
if (id != null) {
|
|
||||||
JSONObject res = contactAccessor.getContactById(id);
|
|
||||||
if (res != null) {
|
|
||||||
callbackContext.success(res);
|
callbackContext.success(res);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
else if (action.equals("save")) {
|
||||||
|
final JSONObject contact = args.getJSONObject(0);
|
||||||
|
this.cordova.getThreadPool().execute(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
JSONObject res = null;
|
||||||
|
String id = contactAccessor.save(contact);
|
||||||
|
if (id != null) {
|
||||||
|
try {
|
||||||
|
res = contactAccessor.getContactById(id);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(LOG_TAG, "JSON fail.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (res != null) {
|
||||||
|
callbackContext.success(res);
|
||||||
|
} else {
|
||||||
|
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (action.equals("remove")) {
|
else if (action.equals("remove")) {
|
||||||
if (contactAccessor.remove(args.getString(0))) {
|
final String contactId = args.getString(0);
|
||||||
callbackContext.success();
|
this.cordova.getThreadPool().execute(new Runnable() {
|
||||||
}
|
public void run() {
|
||||||
|
if (contactAccessor.remove(contactId)) {
|
||||||
|
callbackContext.success();
|
||||||
|
} else {
|
||||||
|
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user