You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by al...@apache.org on 2015/12/09 16:18:36 UTC

cordova-plugin-contacts git commit: CB-10131 Fixed null contact creation. This closes #98

Repository: cordova-plugin-contacts
Updated Branches:
  refs/heads/master f0314d710 -> c7043c9e2


CB-10131 Fixed null contact creation. This closes #98


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/c7043c9e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/c7043c9e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/c7043c9e

Branch: refs/heads/master
Commit: c7043c9e2ba448de64e86076517f74fe33bf39c6
Parents: f0314d7
Author: Alexander Sorokin <al...@akvelon.com>
Authored: Fri Dec 4 12:52:43 2015 +0300
Committer: Alexander Sorokin <al...@akvelon.com>
Committed: Wed Dec 9 18:16:51 2015 +0300

----------------------------------------------------------------------
 src/android/ContactAccessorSdk5.java | 39 ++++++++++++++-----------------
 1 file changed, 18 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/c7043c9e/src/android/ContactAccessorSdk5.java
----------------------------------------------------------------------
diff --git a/src/android/ContactAccessorSdk5.java b/src/android/ContactAccessorSdk5.java
index 9a82cfe..bd43bf1 100644
--- a/src/android/ContactAccessorSdk5.java
+++ b/src/android/ContactAccessorSdk5.java
@@ -178,10 +178,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
             searchTerm = "%";
         }
 
-        //Log.d(LOG_TAG, "Search Term = " + searchTerm);
-        //Log.d(LOG_TAG, "Field Length = " + fields.length());
-        //Log.d(LOG_TAG, "Fields = " + fields.toString());
-
         // Loop through the fields the user provided to see what data should be returned.
         HashMap<String, Boolean> populate = buildPopulationSet(options);
 
@@ -843,6 +839,9 @@ public class ContactAccessorSdk5 extends ContactAccessor {
             if (!TextUtils.isEmpty(honorificSuffix)) {
                 formatted.append(" " + honorificSuffix);
             }
+            if (TextUtils.isEmpty(formatted)) {
+                formatted = null;
+            }
 
             contactName.put("familyName", familyName);
             contactName.put("givenName", givenName);
@@ -1679,23 +1678,21 @@ public class ContactAccessorSdk5 extends ContactAccessor {
                 .build());
 
         // Add name
-        try {
-            JSONObject name = contact.optJSONObject("name");
-            String displayName = contact.getString("displayName");
-            if (displayName != null || name != null) {
-                ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
-                        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
-                        .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
-                        .withValue(CommonDataKinds.StructuredName.DISPLAY_NAME, displayName)
-                        .withValue(CommonDataKinds.StructuredName.FAMILY_NAME, getJsonString(name, "familyName"))
-                        .withValue(CommonDataKinds.StructuredName.MIDDLE_NAME, getJsonString(name, "middleName"))
-                        .withValue(CommonDataKinds.StructuredName.GIVEN_NAME, getJsonString(name, "givenName"))
-                        .withValue(CommonDataKinds.StructuredName.PREFIX, getJsonString(name, "honorificPrefix"))
-                        .withValue(CommonDataKinds.StructuredName.SUFFIX, getJsonString(name, "honorificSuffix"))
-                        .build());
-            }
-        } catch (JSONException e) {
-            Log.d(LOG_TAG, "Could not get name object");
+        JSONObject name = contact.optJSONObject("name");
+        String displayName = getJsonString(contact, "displayName");
+        if (displayName != null || name != null) {
+            ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
+                    .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+                    .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
+                    .withValue(CommonDataKinds.StructuredName.DISPLAY_NAME, displayName)
+                    .withValue(CommonDataKinds.StructuredName.FAMILY_NAME, getJsonString(name, "familyName"))
+                    .withValue(CommonDataKinds.StructuredName.MIDDLE_NAME, getJsonString(name, "middleName"))
+                    .withValue(CommonDataKinds.StructuredName.GIVEN_NAME, getJsonString(name, "givenName"))
+                    .withValue(CommonDataKinds.StructuredName.PREFIX, getJsonString(name, "honorificPrefix"))
+                    .withValue(CommonDataKinds.StructuredName.SUFFIX, getJsonString(name, "honorificSuffix"))
+                    .build());
+        } else {
+            Log.d(LOG_TAG, "Both \"name\" and \"displayName\" properties are empty");
         }
 
         //Add phone numbers


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org