Skip to content
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

Merged
merged 5 commits into from
Jan 21, 2019

Conversation

Git-Hub-Admin
Copy link
Contributor

@Git-Hub-Admin Git-Hub-Admin commented Jan 19, 2019

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

  1. Stop the delete from running if phones/emails are not present as keys in the argument for updateContact.
  2. switch from CONTACT_ID to RAW_CONTACT_ID as reference for deleting because there was problem deleting info added by react-native-contacts.

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.

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
Copy link
Contributor

@luucv luucv left a 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])
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@Git-Hub-Admin Git-Hub-Admin Jan 19, 2019

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.

Copy link
Contributor

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;
Copy link
Contributor

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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove tab

Copy link
Contributor

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 :)

Copy link
Owner

@morenoh149 morenoh149 Jan 19, 2019

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.

@Git-Hub-Admin
Copy link
Contributor Author

@morenoh149 Sorry about the tabs. Had something to do with my vim settings. They should be fixed now

@morenoh149
Copy link
Owner

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants