-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Several Fixes with updateContact #349
Conversation
I maintained the structure used for other updates for address update. The bugs/blemishes in the structure will be fixed in the followup commits.
two problems. 1. it wasn't working properly because it was using contact_id as a reference as opposed to raw_contact_id 2. it will delete all phones/emails even if phones/emails do not exists as keys in the argument for updateContact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I started working on the custom labels and took a slightly different approach. So I only took a look at the custom labels part. I requested some changes regarding code style (the tabbing :)).
.withValue(ContactsContract.Data.RAW_CONTACT_ID, String.valueOf(rawContactId)) | ||
.withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE) | ||
.withValue(CommonDataKinds.Email.ADDRESS, emails[i]) | ||
.withValue(CommonDataKinds.Email.TYPE, emailsTypes[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if TYPE
== TYPE_WORK
? Since the label is then already defined by the TYPE, essentially .withValue(CommonDataKinds.Email.LABEL, emailsLabels[i]);
becomes redundant right? How does android behave in this case, will it add double labels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Android will have type trump label. It only uses label if type is custom. No double labels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also have a few other thoughts about how default labels work as well.
When I started working on it, it only matched all lowercase inputs to the default labels, and I kept it that way. (For example: {label: work}
will give you {TYPE: TYPE_WORK}
, and {label: "Work"}
will give you {TYPE: TYPE_CUSTOM, LABEL: "Work"}
)
I'm not sure whether converting the input label to all lowercase for type matching should be on the user's end or react-native-contact's end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah cool thanks that clears it up for me! 👍
@@ -314,15 +314,18 @@ public void addContact(ReadableMap contact, Callback callback) { | |||
ReadableArray phoneNumbers = contact.hasKey("phoneNumbers") ? contact.getArray("phoneNumbers") : null; | |||
int numOfPhones = 0; | |||
String[] phones = null; | |||
Integer[] phonesLabels = null; | |||
Integer[] phonesTypes = null; | |||
String[] phonesLabels = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove tab
if (phoneNumbers != null) { | ||
numOfPhones = phoneNumbers.size(); | ||
phones = new String[numOfPhones]; | ||
phonesLabels = new Integer[numOfPhones]; | ||
phonesTypes = new Integer[numOfPhones]; | ||
phonesLabels = new String[numOfPhones]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove tab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot more of unneeded tabbing, please check that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sometimes this is the ide inserting stuff. Just try to be consistent with the rest of the code @Git-Hub-Admin and align items like these.
@morenoh149 Sorry about the tabs. Had something to do with my vim settings. They should be fixed now |
lgtm |
Commit 9ffadc0:
Added code for updating postal addresses. I'm basically using the same code used in addContact except it updates instead of insert.
Closes #345
Commit 9a51c5a:
Addresses a few issues with @luucv 's solution to #332
Commit 871bd49:
Allow custom labels.
Before, we only supported TYPE update. We convert labels to type using mapStringToPhoneType function and only updates the type. This only works for Android's default label. Any unrecognized label is default to OTHER TYPE, and the actual value of the label was lost.
I added support for LABEL update. unrecognized TYPE is now default to CUSTOM, and the label value will be read from actual label instead.
This is also added to addContact to support custom labels for addContact.
I'm not familiar with openContactForm, so I didn't touch anything for that.
Note: The duplicate issue (#332 ) may affect uris (Websites) for contacts as well. I'm planning on addressing that at a much later date if no one else gets to it by then.