You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/07/09 19:08:20 UTC

git commit: CB-4084 Delete email entries with empty value

Updated Branches:
  refs/heads/master 6c7ffaba8 -> e0958ce31


CB-4084 Delete email entries with empty value


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/e0958ce3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/e0958ce3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/e0958ce3

Branch: refs/heads/master
Commit: e0958ce3147e223f7d31ba232ea6a15e50563d2e
Parents: 6c7ffab
Author: David Kemp <dr...@chromium.org>
Authored: Mon Jul 8 08:18:38 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jul 9 13:07:46 2013 -0400

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


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/e0958ce3/src/android/ContactAccessorSdk5.java
----------------------------------------------------------------------
diff --git a/src/android/ContactAccessorSdk5.java b/src/android/ContactAccessorSdk5.java
index 6c66326..228b8f5 100644
--- a/src/android/ContactAccessorSdk5.java
+++ b/src/android/ContactAccessorSdk5.java
@@ -951,12 +951,11 @@ public class ContactAccessorSdk5 extends ContactAccessor {
         }
 
         String id = getJsonString(contact, "id");
-        // Create new contact
         if (id == null) {
+            // Create new contact
             return createNewContact(contact, accountType, accountName);
-        }
-        // Modify existing contact
-        else {
+        } else {
+            // Modify existing contact
             return modifyContact(id, contact, accountType, accountName);
         }
     }
@@ -1101,13 +1100,22 @@ public class ContactAccessorSdk5 extends ContactAccessor {
                         }
                         // This is an existing email so do a DB update
                         else {
-                            ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
+                        	String emailValue=getJsonString(email, "value");
+                        	if(!emailValue.isEmpty()) {
+                                ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
                                     .withSelection(ContactsContract.CommonDataKinds.Email._ID + "=? AND " +
                                             ContactsContract.Data.MIMETYPE + "=?",
                                             new String[] { emailId, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE })
                                     .withValue(ContactsContract.CommonDataKinds.Email.DATA, getJsonString(email, "value"))
                                     .withValue(ContactsContract.CommonDataKinds.Email.TYPE, getContactType(getJsonString(email, "type")))
                                     .build());
+                        	} else {
+                                ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
+                                        .withSelection(ContactsContract.CommonDataKinds.Email._ID + "=? AND " +
+                                                ContactsContract.Data.MIMETYPE + "=?",
+                                                new String[] { emailId, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE })
+                                        .build());
+                        	}
                         }
                     }
                 }