Skip to content

Commit

Permalink
[expo-contacts] Fix presentFormAsync pre-filling (#7285)
Browse files Browse the repository at this point in the history
* [expo-contacts] Fix presentFormAsync

* [expo-contacts] Update changelog

* [contacts] Apply requested changes
  • Loading branch information
lukmccall committed Mar 9, 2020
1 parent 72ad264 commit 958d95f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
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

0 comments on commit 958d95f

Please sign in to comment.