forked from TeamMaestro/capacitor-contact-picker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin): contacts without an e-mail address are not being display…
…ed on Android - Modify the PICK intent so that it loads all root level contact entries (i.e. not only those with an e-mail address) - Add two content queries so that first the root level contact (ContactsContract.Contacts), and then the subordinate contact data records (ContactsContract.Contacts.Data) are retrieved. This makes it possible to load e-mails and phone numbers for a contact, stored in the latter. - Add the .gradle/ folder to .gitignore Refs TeamMaestro#1
- Loading branch information
Peter Velosy
committed
Jul 29, 2020
1 parent
348e658
commit 9e83d8a
Showing
19 changed files
with
343 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
dist | ||
.gradle/ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Empty file.
42 changes: 42 additions & 0 deletions
42
android/src/main/java/com/teamhive/capacitor/ContactDataExtractorVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.teamhive.capacitor; | ||
|
||
import android.database.Cursor; | ||
import android.provider.ContactsContract; | ||
import com.getcapacitor.JSArray; | ||
import com.getcapacitor.JSObject; | ||
import com.teamhive.capacitor.contentQuery.ContentQueryService; | ||
import com.teamhive.capacitor.utils.Visitor; | ||
|
||
import java.util.Map; | ||
|
||
public class ContactDataExtractorVisitor implements Visitor<Cursor> { | ||
|
||
private Map<String, String> projectionMap; | ||
|
||
private JSArray phoneNumbers = new JSArray(); | ||
private JSArray emailAddresses = new JSArray(); | ||
|
||
public ContactDataExtractorVisitor(Map<String, String> projectionMap) { | ||
this.projectionMap = projectionMap; | ||
} | ||
|
||
@Override | ||
public void visit(Cursor cursor) { | ||
JSObject currentDataRecord = ContentQueryService.extractDataFromResultSet(cursor, projectionMap); | ||
String currentMimeType = currentDataRecord.getString(PluginContactFields.MIME_TYPE); | ||
|
||
if (ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(currentMimeType)) { | ||
emailAddresses.put(currentDataRecord.getString(ContactsContract.Contacts.Data.DATA1)); | ||
} else if (ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(currentMimeType)) { | ||
phoneNumbers.put(currentDataRecord.getString(ContactsContract.Contacts.Data.DATA1)); | ||
} | ||
} | ||
|
||
public JSArray getPhoneNumbers() { | ||
return phoneNumbers; | ||
} | ||
|
||
public JSArray getEmailAddresses() { | ||
return emailAddresses; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
android/src/main/java/com/teamhive/capacitor/ContactExtractorVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.teamhive.capacitor; | ||
|
||
import android.database.Cursor; | ||
import com.getcapacitor.JSObject; | ||
import com.teamhive.capacitor.contentQuery.ContentQueryService; | ||
import com.teamhive.capacitor.utils.Visitor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ContactExtractorVisitor implements Visitor<Cursor> { | ||
|
||
private Map<String, String> projectionMap; | ||
|
||
private List<JSObject> contacts = new ArrayList<>(); | ||
|
||
public ContactExtractorVisitor(Map<String, String> projectionMap) { | ||
this.projectionMap = projectionMap; | ||
} | ||
|
||
@Override | ||
public void visit(Cursor cursor) { | ||
JSObject contact = ContentQueryService.extractDataFromResultSet(cursor, projectionMap); | ||
contacts.add(contact); | ||
} | ||
|
||
public List<JSObject> getContacts() { | ||
return contacts; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
android/src/main/java/com/teamhive/capacitor/PluginContactFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.teamhive.capacitor; | ||
|
||
public class PluginContactFields { | ||
public static final String IDENTIFIER = "identifier"; | ||
public static final String DISPLAY_NAME = "displayName"; | ||
public static final String FULL_NAME = "fullName"; | ||
public static final String GIVEN_NAME = "givenName"; | ||
public static final String FAMILY_NAME = "familyName"; | ||
public static final String EMAIL_ADDRESSES = "emailAddresses"; | ||
public static final String PHONE_NUMBERS = "phoneNumbers"; | ||
public static final String MIME_TYPE = "mimeType"; | ||
} |
83 changes: 83 additions & 0 deletions
83
android/src/main/java/com/teamhive/capacitor/contentQuery/ContentQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.teamhive.capacitor.contentQuery; | ||
|
||
import android.net.Uri; | ||
import android.os.CancellationSignal; | ||
|
||
import java.util.Map; | ||
|
||
public class ContentQuery { | ||
|
||
private Uri uri; | ||
private Map<String, String> projection; | ||
private String selection; | ||
private String[] selectionArgs; | ||
private String sortOrder; | ||
private CancellationSignal cancellationSignal; | ||
|
||
private ContentQuery() { | ||
} | ||
|
||
public Uri getUri() { | ||
return uri; | ||
} | ||
|
||
public Map<String, String> getProjection() { | ||
return projection; | ||
} | ||
|
||
public String getSelection() { | ||
return selection; | ||
} | ||
|
||
public String[] getSelectionArgs() { | ||
return selectionArgs; | ||
} | ||
|
||
public String getSortOrder() { | ||
return sortOrder; | ||
} | ||
|
||
public CancellationSignal getCancellationSignal() { | ||
return cancellationSignal; | ||
} | ||
|
||
public static class Builder { | ||
|
||
private ContentQuery contentQuery = new ContentQuery(); | ||
|
||
public Builder withUri(Uri uri) { | ||
contentQuery.uri = uri; | ||
return this; | ||
} | ||
|
||
public Builder withProjection(Map<String, String> projection) { | ||
contentQuery.projection = projection; | ||
return this; | ||
} | ||
|
||
public Builder withSelection(String selection) { | ||
contentQuery.selection = selection; | ||
return this; | ||
} | ||
|
||
public Builder withSelectionArgs(String[] selectionArgs) { | ||
contentQuery.selectionArgs = selectionArgs; | ||
return this; | ||
} | ||
|
||
public Builder withSortOrder(String sortOrder) { | ||
contentQuery.sortOrder = sortOrder; | ||
return this; | ||
} | ||
|
||
public Builder withCancellationSignal(CancellationSignal cancellationSignal) { | ||
contentQuery.cancellationSignal = cancellationSignal; | ||
return this; | ||
} | ||
|
||
public ContentQuery build() { | ||
return contentQuery; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.