Skip to content

Commit

Permalink
Merge pull request #666 from johnf/favourites
Browse files Browse the repository at this point in the history
Add a field to indicate if the contact is starred
  • Loading branch information
morenoh149 authored Aug 11, 2022
2 parents ecc133e + a800f96 commit a45047a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ react-native unlink react-native-contacts
npm install latest version of react-native-contacts
Your good to go!
```
### react native version 60 and above
### react native version 60 and above

If you are using react native version 0.60 or above you do not have to link this library.

Expand Down Expand Up @@ -230,11 +230,21 @@ If you'd like to read/write the contact's notes, call the `iosEnableNotesUsage(t
imAddresses: [
{ username: '0123456789', service: 'ICQ'},
{ username: 'johndoe123', service: 'Facebook'}
]
],
isStarred: false,
}
```
**NOTE**

### Android only

* on Android versions below 8 the entire display name is passed in the `givenName` field. `middleName` and `familyName` will be `""`.
* isStarred field
* writePhotoToPath() - writes the contact photo to a given path

## iOS only

checkPermission(): Promise - checks permission to access Contacts
requestPermission(): Promise - request permission to access Contacts

## Adding Contacts
Currently all fields from the contact record except for thumbnailPath are supported for writing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ContactsProvider {
add(ContactsContract.Data.CONTACT_ID);
add(ContactsContract.Data.RAW_CONTACT_ID);
add(ContactsContract.Data.LOOKUP_KEY);
add(ContactsContract.Data.STARRED);
add(ContactsContract.Contacts.Data.MIMETYPE);
add(ContactsContract.Profile.DISPLAY_NAME);
add(Contactables.PHOTO_URI);
Expand Down Expand Up @@ -344,10 +345,13 @@ private Map<String, Contact> loadContactsFrom(Cursor cursor) {
Contact contact = map.get(contactId);
String mimeType = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE));
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
int starred = cursor.getInt(cursor.getColumnIndex(ContactsContract.Data.STARRED));
Boolean isStarred = starred == 1;
contact.rawContactId = rawContactId;
if (!TextUtils.isEmpty(name) && TextUtils.isEmpty(contact.displayName)) {
contact.displayName = name;
}
contact.isStarred = isStarred;

if (TextUtils.isEmpty(contact.photoUri)) {
String rawPhotoURI = cursor.getString(cursor.getColumnIndex(Contactables.PHOTO_URI));
Expand Down Expand Up @@ -599,6 +603,7 @@ private static class Contact {
private List<Item> urls = new ArrayList<>();
private List<Item> instantMessengers = new ArrayList<>();
private boolean hasPhoto = false;
private boolean isStarred = false;
private String photoUri;
private List<Item> emails = new ArrayList<>();
private List<Item> phones = new ArrayList<>();
Expand Down Expand Up @@ -626,6 +631,7 @@ public WritableMap toMap() {
contact.putString("note", note);
contact.putBoolean("hasThumbnail", this.hasPhoto);
contact.putString("thumbnailPath", photoUri == null ? "" : photoUri);
contact.putBoolean("isStarred", this.isStarred);

WritableArray phoneNumbers = Arguments.createArray();
for (Item item : phones) {
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface Contact {
phoneNumbers: PhoneNumber[];
hasThumbnail: boolean;
thumbnailPath: string;
isStarred: boolean;
postalAddresses: PostalAddress[];
prefix: string;
suffix: string;
Expand Down

0 comments on commit a45047a

Please sign in to comment.