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

[expo-contacts] Fix presentFormAsync pre-filling #7285

Merged
merged 3 commits into from Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@ This is the log of notable changes to the Expo client that are developer-facing.

- Fixed `Brightness.requestPermissionsAsync` throwing `permission cannot be null or empty` error on Android. ([#7276](https://github.com/expo/expo/pull/7276) by [@lukmccall](https://github.com/lukmccall))
- Fixed `KeepAwake.activateKeepAwake` not working with multiple tags on Android. ([#7197](https://github.com/expo/expo/pull/7197) by [@lukmccall](https://github.com/lukmccall))
- Fix `Contacts.presentFormAsync` pre-filling. ([#7285](https://github.com/expo/expo/pull/7285) by [@abdelilah](https://github.com/abdelilah) & [@lukmccall](https://github.com/lukmccall))

## 37.0.0

Expand Down
@@ -1,5 +1,6 @@
package expo.modules.contacts;

import android.net.Uri;
import android.util.Log;
import android.content.ContentProviderOperation;
import android.content.ContentValues;
Expand All @@ -11,6 +12,8 @@
import android.provider.ContactsContract;
import android.text.TextUtils;

import org.jetbrains.annotations.Nullable;

import java.io.ByteArrayOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -183,6 +186,15 @@ public String getLastName() {
return lastName;
}

@Nullable
public String getDisplayName() {
if (displayName == null && firstName != null) {
return lastName == null ? firstName : String.format("%s %s", firstName, lastName).trim();
}

return displayName;
}

public Contact(String contactId) {
this.contactId = contactId;
}
Expand Down Expand Up @@ -466,7 +478,7 @@ public ArrayList<ContentValues> getContentValues() {
contactData.add(notes);

if (photoUri != null && !photoUri.isEmpty()) {
Bitmap photo = BitmapFactory.decodeFile(photoUri);
Bitmap photo = BitmapFactory.decodeFile(Uri.parse(photoUri).getPath());

if (photo != null) {
ContentValues image = new ContentValues();
Expand Down Expand Up @@ -495,4 +507,4 @@ public ArrayList<ContentValues> getContentValues() {
return contactData;
}

}
}
Expand Up @@ -274,11 +274,7 @@ public void presentFormAsync(String contactId, Map<String, Object> contactData,

private void presentForm(Contact contact) {
Intent intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
if (contact.displayName != null) {
intent.putExtra(ContactsContract.Intents.Insert.NAME, contact.displayName);
} else {
intent.putExtra(ContactsContract.Intents.Insert.NAME, contact.getFirstName());
}
intent.putExtra(ContactsContract.Intents.Insert.NAME, contact.getDisplayName());
intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, contact.getContentValues());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Expand Down Expand Up @@ -367,6 +363,15 @@ private Contact mutateContact(Contact contact, Map<String, Object> data) {
if (data.containsKey("note"))
contact.note = (String) data.get("note");

if (data.containsKey("image")) {
Map<String, Object> photo = (Map<String, Object>) data.get("image");

if (photo.containsKey("uri")) {
contact.photoUri = (String) photo.get("uri");
contact.hasPhoto = true;
}
}

ArrayList results;

try {
Expand Down