@aalzehla/capacitor-contacts 0.0.4 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{AalzehlaCapacitorContacts.podspec → CapacitorCommunityContacts.podspec} +3 -3
- package/README.md +69 -45
- package/android/build.gradle +15 -12
- package/android/src/main/java/getcapacitor/community/contacts/BiMap.java +45 -0
- package/android/src/main/java/getcapacitor/community/contacts/ContactPayload.java +286 -0
- package/android/src/main/java/getcapacitor/community/contacts/Contacts.java +384 -0
- package/android/src/main/java/getcapacitor/community/contacts/ContactsPlugin.java +255 -0
- package/android/src/main/java/getcapacitor/community/contacts/CreateContactInput.java +233 -0
- package/android/src/main/java/getcapacitor/community/contacts/GetContactsProjectionInput.java +214 -0
- package/dist/esm/definitions.d.ts +285 -19
- package/dist/esm/definitions.js +47 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +9 -7
- package/dist/esm/web.js +21 -7
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +73 -14
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +74 -15
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/BiMap.swift +42 -0
- package/ios/Plugin/ContactPayload.swift +227 -0
- package/ios/Plugin/Contacts.swift +227 -0
- package/ios/Plugin/ContactsPlugin.h +10 -0
- package/ios/Plugin/ContactsPlugin.m +14 -0
- package/ios/Plugin/ContactsPlugin.swift +221 -0
- package/ios/Plugin/CreateContactInput.swift +187 -0
- package/ios/Plugin/GetContactsProjectionInput.swift +119 -0
- package/ios/Plugin/Info.plist +24 -0
- package/package.json +33 -30
- package/Package.swift +0 -28
- package/android/src/main/java/com/aalzehla/capacitor/contacts/CapacitorContactsPlugin.java +0 -177
- package/android/src/main/java/com/aalzehla/capacitor/contacts/ContactDataExtractorVisitor.java +0 -122
- package/android/src/main/java/com/aalzehla/capacitor/contacts/ContactExtractorVisitor.java +0 -31
- package/android/src/main/java/com/aalzehla/capacitor/contacts/PluginContactFields.java +0 -17
- package/android/src/main/java/com/aalzehla/capacitor/contacts/contentQuery/ContentQuery.java +0 -83
- package/android/src/main/java/com/aalzehla/capacitor/contacts/contentQuery/ContentQueryService.java +0 -60
- package/android/src/main/java/com/aalzehla/capacitor/contacts/utils/Utils.java +0 -19
- package/android/src/main/java/com/aalzehla/capacitor/contacts/utils/Visitable.java +0 -5
- package/android/src/main/java/com/aalzehla/capacitor/contacts/utils/Visitor.java +0 -5
- package/dist/docs.json +0 -145
- package/ios/Sources/CapacitorContactsPlugin/CapacitorContactsPlugin.swift +0 -166
- package/ios/Tests/CapacitorContactsPluginTests/CapacitorContactsPluginTests.swift +0 -15
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
package com.aalzehla.capacitor.contacts;
|
|
2
|
-
|
|
3
|
-
import android.Manifest;
|
|
4
|
-
import android.content.Intent;
|
|
5
|
-
import android.provider.ContactsContract;
|
|
6
|
-
import android.provider.ContactsContract.CommonDataKinds;
|
|
7
|
-
import android.util.Log;
|
|
8
|
-
|
|
9
|
-
import androidx.activity.result.ActivityResult;
|
|
10
|
-
|
|
11
|
-
import com.getcapacitor.JSArray;
|
|
12
|
-
import com.getcapacitor.JSObject;
|
|
13
|
-
import com.getcapacitor.PermissionState;
|
|
14
|
-
import com.getcapacitor.Plugin;
|
|
15
|
-
import com.getcapacitor.PluginCall;
|
|
16
|
-
import com.getcapacitor.PluginMethod;
|
|
17
|
-
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
18
|
-
import com.getcapacitor.annotation.Permission;
|
|
19
|
-
import com.getcapacitor.annotation.PermissionCallback;
|
|
20
|
-
import com.getcapacitor.annotation.ActivityCallback;
|
|
21
|
-
|
|
22
|
-
import com.aalzehla.capacitor.contacts.contentQuery.ContentQuery;
|
|
23
|
-
import com.aalzehla.capacitor.contacts.contentQuery.ContentQueryService;
|
|
24
|
-
import com.aalzehla.capacitor.contacts.utils.Utils;
|
|
25
|
-
|
|
26
|
-
import java.io.IOException;
|
|
27
|
-
import java.util.HashMap;
|
|
28
|
-
import java.util.List;
|
|
29
|
-
import java.util.Map;
|
|
30
|
-
|
|
31
|
-
// import android.util.Log;
|
|
32
|
-
|
|
33
|
-
@CapacitorPlugin(
|
|
34
|
-
name = "CapacitorContacts",
|
|
35
|
-
permissions={
|
|
36
|
-
@Permission(strings = {Manifest.permission.READ_CONTACTS}, alias = "contacts"),
|
|
37
|
-
}
|
|
38
|
-
)
|
|
39
|
-
public class CapacitorContactsPlugin extends Plugin {
|
|
40
|
-
|
|
41
|
-
// Messages
|
|
42
|
-
public static final String ERROR_READ_CONTACT = "Unable to read contact data.";
|
|
43
|
-
public static final String ERROR_NO_PERMISSION = "User denied permission";
|
|
44
|
-
|
|
45
|
-
// Queries
|
|
46
|
-
public static final String CONTACT_DATA_SELECT_CLAUSE = ContactsContract.Data.LOOKUP_KEY + " = ? AND " + ContactsContract.Data.MIMETYPE + " IN('" + CommonDataKinds.Email.CONTENT_ITEM_TYPE + "', '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "', '" + CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "')"; //
|
|
47
|
-
|
|
48
|
-
@PluginMethod()
|
|
49
|
-
public void open(PluginCall call) {
|
|
50
|
-
if (getPermissionState("contacts") != PermissionState.GRANTED) {
|
|
51
|
-
//saveCall(call);
|
|
52
|
-
call.setKeepAlive(true);
|
|
53
|
-
requestPermissionForAlias("contacts", call, "contactsPermsCallback");
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
//saveCall(call);
|
|
57
|
-
call.setKeepAlive(true);
|
|
58
|
-
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
|
|
59
|
-
startActivityForResult(call, contactPickerIntent, "activityCallback");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@PermissionCallback
|
|
63
|
-
private void contactsPermsCallback(PluginCall call) {
|
|
64
|
-
if (getPermissionState("contacts") == PermissionState.GRANTED) {
|
|
65
|
-
open(call);
|
|
66
|
-
} else {
|
|
67
|
-
call.reject(ERROR_NO_PERMISSION);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@ActivityCallback
|
|
72
|
-
private void activityCallback(PluginCall call, ActivityResult result) {
|
|
73
|
-
try {
|
|
74
|
-
//Log.v("File: ", String.valueOf(result));
|
|
75
|
-
JSObject contact = readContactData(result.getData(), call);
|
|
76
|
-
call.resolve(contact); // since it is just the contact object and not an array, no need to return the value field but instead just return the selected contact. use contact to replace Utils.wrapIntoResult(contact)
|
|
77
|
-
} catch (IOException e) {
|
|
78
|
-
call.reject(ERROR_READ_CONTACT);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
@PluginMethod()
|
|
83
|
-
public void close(PluginCall call) {
|
|
84
|
-
call.unimplemented();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private JSObject readContactData(Intent intent, PluginCall savedCall) throws IOException {
|
|
88
|
-
final Map<String, String> projectionMap = getContactProjectionMap(); ////
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
ContentQuery contactQuery = new ContentQuery.Builder()
|
|
92
|
-
.withUri(intent.getData())
|
|
93
|
-
.withProjection(projectionMap)
|
|
94
|
-
.build();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
try (ContentQueryService.VisitableCursorWrapper contactVcw = ContentQueryService.query(getContext(), contactQuery)) {
|
|
98
|
-
|
|
99
|
-
ContactExtractorVisitor contactExtractor = new ContactExtractorVisitor(projectionMap);
|
|
100
|
-
contactVcw.accept(contactExtractor);
|
|
101
|
-
List<JSObject> contacts = contactExtractor.getContacts();
|
|
102
|
-
|
|
103
|
-
if (contacts.size() == 0) {
|
|
104
|
-
return null;
|
|
105
|
-
} else {
|
|
106
|
-
JSObject chosenContact = contacts.get(0);
|
|
107
|
-
|
|
108
|
-
Map<String, String> dataProjectionMap = getContactDataProjectionMap(); ////////
|
|
109
|
-
ContentQuery contactDataQuery = new ContentQuery.Builder()
|
|
110
|
-
.withUri(ContactsContract.Data.CONTENT_URI)
|
|
111
|
-
.withProjection(dataProjectionMap)
|
|
112
|
-
.withSelection(CONTACT_DATA_SELECT_CLAUSE)
|
|
113
|
-
.withSelectionArgs(new String[]{chosenContact.getString(PluginContactFields.ANDROID_CONTACT_LOOKUP_KEY)})
|
|
114
|
-
.withSortOrder(ContactsContract.Data.MIMETYPE)
|
|
115
|
-
.build();
|
|
116
|
-
|
|
117
|
-
try (ContentQueryService.VisitableCursorWrapper dataVcw = ContentQueryService.query(getContext(), contactDataQuery)) {
|
|
118
|
-
|
|
119
|
-
ContactDataExtractorVisitor contactDataExtractor = new ContactDataExtractorVisitor(dataProjectionMap);
|
|
120
|
-
dataVcw.accept(contactDataExtractor);
|
|
121
|
-
|
|
122
|
-
return transformContactObject(chosenContact, contactDataExtractor.getEmailAddresses(), contactDataExtractor.getPhoneNumbers(), contactDataExtractor.getPostalAddresses());
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
} catch (Exception e) {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private JSObject transformContactObject(JSObject tempContact, JSArray emailAddresses, JSArray phoneNumbers, JSArray postalAddresses) {
|
|
133
|
-
JSObject contact = new JSObject();
|
|
134
|
-
contact.put(PluginContactFields.IDENTIFIER, tempContact.getString(PluginContactFields.IDENTIFIER));
|
|
135
|
-
contact.put(PluginContactFields.ANDROID_CONTACT_LOOKUP_KEY, tempContact.getString(PluginContactFields.ANDROID_CONTACT_LOOKUP_KEY));
|
|
136
|
-
String displayName = tempContact.getString(PluginContactFields.DISPLAY_NAME);
|
|
137
|
-
contact.put(PluginContactFields.FULL_NAME, displayName);
|
|
138
|
-
if (displayName != null && displayName.contains(" ")) {
|
|
139
|
-
contact.put(PluginContactFields.DISPLAY_NAME, displayName);
|
|
140
|
-
contact.put(PluginContactFields.GIVEN_NAME, displayName.split(" ")[0]);
|
|
141
|
-
contact.put(PluginContactFields.FAMILY_NAME, displayName.split(" ")[1]);
|
|
142
|
-
}
|
|
143
|
-
contact.put(PluginContactFields.EMAIL_ADDRESSES, emailAddresses);
|
|
144
|
-
contact.put(PluginContactFields.PHONE_NUMBERS, phoneNumbers);
|
|
145
|
-
contact.put(PluginContactFields.POSTAL_ADDRESSES, postalAddresses);
|
|
146
|
-
//contact.put(PluginContactFields.PHOTO_URI, tempContact.getString(PluginContactFields.PHOTO_URI));
|
|
147
|
-
return contact;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private Map<String, String> getContactProjectionMap() {
|
|
151
|
-
Map<String, String> contactFieldsMap = new HashMap<>();
|
|
152
|
-
contactFieldsMap.put(ContactsContract.Contacts._ID, PluginContactFields.IDENTIFIER);
|
|
153
|
-
contactFieldsMap.put(ContactsContract.Contacts.LOOKUP_KEY, PluginContactFields.ANDROID_CONTACT_LOOKUP_KEY);
|
|
154
|
-
contactFieldsMap.put(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY, PluginContactFields.DISPLAY_NAME);
|
|
155
|
-
|
|
156
|
-
contactFieldsMap.put(ContactsContract.Contacts.PHOTO_URI, PluginContactFields.PHOTO_URI);
|
|
157
|
-
|
|
158
|
-
// contactFieldsMap.put(ContactsContract.Contacts.Data.DATA15, PluginContactFields.PHOTO_URI);
|
|
159
|
-
return contactFieldsMap;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private Map<String, String> getContactDataProjectionMap() {
|
|
163
|
-
Map<String, String> contactFieldsMap = new HashMap<>();
|
|
164
|
-
contactFieldsMap.put(CommonDataKinds.Email.MIMETYPE, PluginContactFields.MIME_TYPE);
|
|
165
|
-
contactFieldsMap.put(ContactsContract.Data.DATA1, ContactsContract.Data.DATA1);
|
|
166
|
-
contactFieldsMap.put(ContactsContract.Data.DATA2, ContactsContract.Data.DATA2);
|
|
167
|
-
contactFieldsMap.put(ContactsContract.Data.DATA3, ContactsContract.Data.DATA3);
|
|
168
|
-
contactFieldsMap.put(ContactsContract.Data.DATA4, ContactsContract.Data.DATA4);
|
|
169
|
-
contactFieldsMap.put(ContactsContract.Data.DATA5, ContactsContract.Data.DATA5);
|
|
170
|
-
contactFieldsMap.put(ContactsContract.Data.DATA6, ContactsContract.Data.DATA6);
|
|
171
|
-
contactFieldsMap.put(ContactsContract.Data.DATA7, ContactsContract.Data.DATA7);
|
|
172
|
-
contactFieldsMap.put(ContactsContract.Data.DATA8, ContactsContract.Data.DATA8);
|
|
173
|
-
contactFieldsMap.put(ContactsContract.Data.DATA9, ContactsContract.Data.DATA9);
|
|
174
|
-
contactFieldsMap.put(ContactsContract.Data.DATA10, ContactsContract.Data.DATA10);
|
|
175
|
-
return contactFieldsMap;
|
|
176
|
-
}
|
|
177
|
-
}
|
package/android/src/main/java/com/aalzehla/capacitor/contacts/ContactDataExtractorVisitor.java
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
package com.aalzehla.capacitor.contacts;
|
|
2
|
-
|
|
3
|
-
import android.database.Cursor;
|
|
4
|
-
import android.provider.ContactsContract;
|
|
5
|
-
import com.getcapacitor.JSArray;
|
|
6
|
-
import com.getcapacitor.JSObject;
|
|
7
|
-
import com.aalzehla.capacitor.contacts.contentQuery.ContentQueryService;
|
|
8
|
-
import com.aalzehla.capacitor.contacts.utils.Visitor;
|
|
9
|
-
|
|
10
|
-
import java.util.Map;
|
|
11
|
-
import android.util.Log;
|
|
12
|
-
|
|
13
|
-
public class ContactDataExtractorVisitor implements Visitor<Cursor> {
|
|
14
|
-
|
|
15
|
-
private Map<String, String> projectionMap;
|
|
16
|
-
|
|
17
|
-
private JSArray phoneNumbers = new JSArray();
|
|
18
|
-
private JSArray emailAddresses = new JSArray();
|
|
19
|
-
private JSArray postalAddresses = new JSArray();
|
|
20
|
-
|
|
21
|
-
public ContactDataExtractorVisitor(Map<String, String> projectionMap) {
|
|
22
|
-
this.projectionMap = projectionMap;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@Override
|
|
26
|
-
public void visit(Cursor cursor) {
|
|
27
|
-
JSObject currentDataRecord = ContentQueryService.extractDataFromResultSet(cursor, projectionMap);
|
|
28
|
-
String currentMimeType = currentDataRecord.getString(PluginContactFields.MIME_TYPE);
|
|
29
|
-
|
|
30
|
-
//Log.v("HELLO", String.valueOf(currentDataRecord));
|
|
31
|
-
|
|
32
|
-
if (ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE.equals(currentMimeType)) {
|
|
33
|
-
JSObject email = new JSObject();
|
|
34
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA1) != null) {
|
|
35
|
-
email.put("emailAddress", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA1));
|
|
36
|
-
}
|
|
37
|
-
switch (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA2)) {
|
|
38
|
-
case "1":
|
|
39
|
-
email.put("type", "home");
|
|
40
|
-
break;
|
|
41
|
-
case "2":
|
|
42
|
-
email.put("type", "mobile");
|
|
43
|
-
break;
|
|
44
|
-
case "3":
|
|
45
|
-
email.put("type", "work");
|
|
46
|
-
break;
|
|
47
|
-
default:
|
|
48
|
-
email.put("type", "other");
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
emailAddresses.put(email);
|
|
52
|
-
} else if (ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(currentMimeType)) {
|
|
53
|
-
JSObject phone = new JSObject();
|
|
54
|
-
// https://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone
|
|
55
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA1) != null) {
|
|
56
|
-
phone.put("phoneNumber", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA1));
|
|
57
|
-
}
|
|
58
|
-
switch (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA2)) {
|
|
59
|
-
case "1":
|
|
60
|
-
phone.put("type", "home");
|
|
61
|
-
break;
|
|
62
|
-
case "2":
|
|
63
|
-
phone.put("type", "mobile");
|
|
64
|
-
break;
|
|
65
|
-
case "3":
|
|
66
|
-
phone.put("type", "work");
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
phone.put("type", "other");
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
phoneNumbers.put(phone);
|
|
73
|
-
} else if (ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE.equals(currentMimeType)) {
|
|
74
|
-
JSObject address = new JSObject();
|
|
75
|
-
// https://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.StructuredPostal
|
|
76
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA1) != null) {
|
|
77
|
-
address.put("formattedAddress", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA1));
|
|
78
|
-
}
|
|
79
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA4) != null) {
|
|
80
|
-
address.put("street", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA4));
|
|
81
|
-
}
|
|
82
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA5) != null) {
|
|
83
|
-
address.put("pobox", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA5));
|
|
84
|
-
}
|
|
85
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA6) != null) {
|
|
86
|
-
address.put("neighborhood", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA6));
|
|
87
|
-
}
|
|
88
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA7) != null) {
|
|
89
|
-
address.put("city", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA7));
|
|
90
|
-
}
|
|
91
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA8) != null) {
|
|
92
|
-
address.put("state", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA8));
|
|
93
|
-
}
|
|
94
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA9) != null) {
|
|
95
|
-
address.put("postalCode", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA9));
|
|
96
|
-
}
|
|
97
|
-
if (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA10) != null) {
|
|
98
|
-
address.put("country", currentDataRecord.getString(ContactsContract.Contacts.Data.DATA10));
|
|
99
|
-
}
|
|
100
|
-
switch (currentDataRecord.getString(ContactsContract.Contacts.Data.DATA2)) {
|
|
101
|
-
case "1":
|
|
102
|
-
address.put("type", "home");
|
|
103
|
-
break;
|
|
104
|
-
case "2":
|
|
105
|
-
address.put("type", "work");
|
|
106
|
-
break;
|
|
107
|
-
default:
|
|
108
|
-
address.put("type", "other");
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
postalAddresses.put(address);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public JSArray getPhoneNumbers() {
|
|
116
|
-
return phoneNumbers;
|
|
117
|
-
}
|
|
118
|
-
public JSArray getEmailAddresses() {
|
|
119
|
-
return emailAddresses;
|
|
120
|
-
}
|
|
121
|
-
public JSArray getPostalAddresses() { return postalAddresses; }
|
|
122
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
package com.aalzehla.capacitor.contacts;
|
|
2
|
-
|
|
3
|
-
import android.database.Cursor;
|
|
4
|
-
import com.getcapacitor.JSObject;
|
|
5
|
-
import com.aalzehla.capacitor.contacts.contentQuery.ContentQueryService;
|
|
6
|
-
import com.aalzehla.capacitor.contacts.utils.Visitor;
|
|
7
|
-
|
|
8
|
-
import java.util.ArrayList;
|
|
9
|
-
import java.util.List;
|
|
10
|
-
import java.util.Map;
|
|
11
|
-
|
|
12
|
-
public class ContactExtractorVisitor implements Visitor<Cursor> {
|
|
13
|
-
|
|
14
|
-
private Map<String, String> projectionMap;
|
|
15
|
-
|
|
16
|
-
private List<JSObject> contacts = new ArrayList<>();
|
|
17
|
-
|
|
18
|
-
public ContactExtractorVisitor(Map<String, String> projectionMap) {
|
|
19
|
-
this.projectionMap = projectionMap;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Override
|
|
23
|
-
public void visit(Cursor cursor) {
|
|
24
|
-
JSObject contact = ContentQueryService.extractDataFromResultSet(cursor, projectionMap);
|
|
25
|
-
contacts.add(contact);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public List<JSObject> getContacts() {
|
|
29
|
-
return contacts;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
package com.aalzehla.capacitor.contacts;
|
|
2
|
-
|
|
3
|
-
public class PluginContactFields {
|
|
4
|
-
public static final String IDENTIFIER = "identifier";
|
|
5
|
-
public static final String ANDROID_CONTACT_LOOKUP_KEY = "androidContactLookupKey";
|
|
6
|
-
public static final String DISPLAY_NAME = "displayName";
|
|
7
|
-
public static final String FULL_NAME = "fullName";
|
|
8
|
-
public static final String GIVEN_NAME = "givenName";
|
|
9
|
-
public static final String FAMILY_NAME = "familyName";
|
|
10
|
-
public static final String EMAIL_ADDRESSES = "emailAddresses";
|
|
11
|
-
public static final String PHONE_NUMBERS = "phoneNumbers";
|
|
12
|
-
public static final String PHONE_TYPES = "phoneNumberLabels";
|
|
13
|
-
public static final String POSTAL_ADDRESSES = "postalAddresses";
|
|
14
|
-
public static final String POSTAL_TYPES = "postalAddressLabels";
|
|
15
|
-
public static final String MIME_TYPE = "mimeType";
|
|
16
|
-
public static final String PHOTO_URI = "image";
|
|
17
|
-
}
|
package/android/src/main/java/com/aalzehla/capacitor/contacts/contentQuery/ContentQuery.java
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
package com.aalzehla.capacitor.contacts.contentQuery;
|
|
2
|
-
|
|
3
|
-
import android.net.Uri;
|
|
4
|
-
import android.os.CancellationSignal;
|
|
5
|
-
|
|
6
|
-
import java.util.Map;
|
|
7
|
-
|
|
8
|
-
public class ContentQuery {
|
|
9
|
-
|
|
10
|
-
private Uri uri;
|
|
11
|
-
private Map<String, String> projection;
|
|
12
|
-
private String selection;
|
|
13
|
-
private String[] selectionArgs;
|
|
14
|
-
private String sortOrder;
|
|
15
|
-
private CancellationSignal cancellationSignal;
|
|
16
|
-
|
|
17
|
-
private ContentQuery() {
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public Uri getUri() {
|
|
21
|
-
return uri;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public Map<String, String> getProjection() {
|
|
25
|
-
return projection;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public String getSelection() {
|
|
29
|
-
return selection;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public String[] getSelectionArgs() {
|
|
33
|
-
return selectionArgs;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public String getSortOrder() {
|
|
37
|
-
return sortOrder;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public CancellationSignal getCancellationSignal() {
|
|
41
|
-
return cancellationSignal;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public static class Builder {
|
|
45
|
-
|
|
46
|
-
private ContentQuery contentQuery = new ContentQuery();
|
|
47
|
-
|
|
48
|
-
public Builder withUri(Uri uri) {
|
|
49
|
-
contentQuery.uri = uri;
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public Builder withProjection(Map<String, String> projection) {
|
|
54
|
-
contentQuery.projection = projection;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public Builder withSelection(String selection) {
|
|
59
|
-
contentQuery.selection = selection;
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public Builder withSelectionArgs(String[] selectionArgs) {
|
|
64
|
-
contentQuery.selectionArgs = selectionArgs;
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public Builder withSortOrder(String sortOrder) {
|
|
69
|
-
contentQuery.sortOrder = sortOrder;
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public Builder withCancellationSignal(CancellationSignal cancellationSignal) {
|
|
74
|
-
contentQuery.cancellationSignal = cancellationSignal;
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public ContentQuery build() {
|
|
79
|
-
return contentQuery;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
}
|
package/android/src/main/java/com/aalzehla/capacitor/contacts/contentQuery/ContentQueryService.java
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
package com.aalzehla.capacitor.contacts.contentQuery;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.database.Cursor;
|
|
5
|
-
import com.getcapacitor.JSObject;
|
|
6
|
-
import com.aalzehla.capacitor.contacts.utils.Utils;
|
|
7
|
-
import com.aalzehla.capacitor.contacts.utils.Visitable;
|
|
8
|
-
import com.aalzehla.capacitor.contacts.utils.Visitor;
|
|
9
|
-
|
|
10
|
-
import java.io.Closeable;
|
|
11
|
-
import java.util.Map;
|
|
12
|
-
|
|
13
|
-
public class ContentQueryService {
|
|
14
|
-
|
|
15
|
-
public static VisitableCursorWrapper query(Context context, ContentQuery query) {
|
|
16
|
-
try {
|
|
17
|
-
String[] projectionArray = Utils.getMapKeysAsArray(query.getProjection());
|
|
18
|
-
Cursor cursor = context.getContentResolver().query(query.getUri(), projectionArray, query.getSelection(), query.getSelectionArgs(), query.getSortOrder(), query.getCancellationSignal());
|
|
19
|
-
return new VisitableCursorWrapper(cursor);
|
|
20
|
-
} catch (Exception e) {
|
|
21
|
-
throw new RuntimeException(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static JSObject extractDataFromResultSet(Cursor cursor, Map<String, String> projectionMap) {
|
|
26
|
-
try {
|
|
27
|
-
JSObject result = new JSObject();
|
|
28
|
-
for (Map.Entry<String, String> entry : projectionMap.entrySet()) {
|
|
29
|
-
int columnIndex = cursor.getColumnIndex(entry.getKey());
|
|
30
|
-
result.put(entry.getValue(), cursor.getString(columnIndex));
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
} catch (Exception e) {
|
|
34
|
-
throw new RuntimeException(e);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public static class VisitableCursorWrapper implements Visitable<Cursor>, Closeable, AutoCloseable {
|
|
39
|
-
|
|
40
|
-
private Cursor cursor;
|
|
41
|
-
|
|
42
|
-
private VisitableCursorWrapper(Cursor cursor) {
|
|
43
|
-
this.cursor = cursor;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public void accept(Visitor<Cursor> visitor) {
|
|
47
|
-
while (cursor != null && cursor.moveToNext()) {
|
|
48
|
-
visitor.visit(cursor);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Override
|
|
53
|
-
public void close() {
|
|
54
|
-
if (cursor != null) {
|
|
55
|
-
cursor.close();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
package com.aalzehla.capacitor.contacts.utils;
|
|
2
|
-
|
|
3
|
-
import com.getcapacitor.JSObject;
|
|
4
|
-
|
|
5
|
-
import java.util.Map;
|
|
6
|
-
|
|
7
|
-
public class Utils {
|
|
8
|
-
|
|
9
|
-
public static String[] getMapKeysAsArray(Map<String, ?> map) {
|
|
10
|
-
return map.keySet().toArray(new String[]{});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public static JSObject wrapIntoResult(JSObject contact) {
|
|
14
|
-
JSObject result = new JSObject();
|
|
15
|
-
result.put("value", contact);
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
package/dist/docs.json
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"api": {
|
|
3
|
-
"name": "CapacitorContactsPlugin",
|
|
4
|
-
"slug": "capacitorcontactsplugin",
|
|
5
|
-
"docs": "",
|
|
6
|
-
"tags": [],
|
|
7
|
-
"methods": [
|
|
8
|
-
{
|
|
9
|
-
"name": "open",
|
|
10
|
-
"signature": "() => Promise<Contact[]>",
|
|
11
|
-
"parameters": [],
|
|
12
|
-
"returns": "Promise<Contact[]>",
|
|
13
|
-
"tags": [],
|
|
14
|
-
"docs": "",
|
|
15
|
-
"complexTypes": [
|
|
16
|
-
"Contact"
|
|
17
|
-
],
|
|
18
|
-
"slug": "open"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"name": "close",
|
|
22
|
-
"signature": "() => Promise<void>",
|
|
23
|
-
"parameters": [],
|
|
24
|
-
"returns": "Promise<void>",
|
|
25
|
-
"tags": [],
|
|
26
|
-
"docs": "",
|
|
27
|
-
"complexTypes": [],
|
|
28
|
-
"slug": "close"
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
"properties": []
|
|
32
|
-
},
|
|
33
|
-
"interfaces": [
|
|
34
|
-
{
|
|
35
|
-
"name": "Contact",
|
|
36
|
-
"slug": "contact",
|
|
37
|
-
"docs": "",
|
|
38
|
-
"tags": [],
|
|
39
|
-
"methods": [],
|
|
40
|
-
"properties": [
|
|
41
|
-
{
|
|
42
|
-
"name": "identifier",
|
|
43
|
-
"tags": [],
|
|
44
|
-
"docs": "",
|
|
45
|
-
"complexTypes": [],
|
|
46
|
-
"type": "string | undefined"
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
"name": "androidContactLookupKey",
|
|
50
|
-
"tags": [],
|
|
51
|
-
"docs": "",
|
|
52
|
-
"complexTypes": [],
|
|
53
|
-
"type": "string | undefined"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
"name": "contactId",
|
|
57
|
-
"tags": [],
|
|
58
|
-
"docs": "",
|
|
59
|
-
"complexTypes": [],
|
|
60
|
-
"type": "string | undefined"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"name": "givenName",
|
|
64
|
-
"tags": [],
|
|
65
|
-
"docs": "",
|
|
66
|
-
"complexTypes": [],
|
|
67
|
-
"type": "string | undefined"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"name": "familyName",
|
|
71
|
-
"tags": [],
|
|
72
|
-
"docs": "",
|
|
73
|
-
"complexTypes": [],
|
|
74
|
-
"type": "string | undefined"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
"name": "nickname",
|
|
78
|
-
"tags": [],
|
|
79
|
-
"docs": "",
|
|
80
|
-
"complexTypes": [],
|
|
81
|
-
"type": "string | undefined"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
"name": "fullName",
|
|
85
|
-
"tags": [],
|
|
86
|
-
"docs": "",
|
|
87
|
-
"complexTypes": [],
|
|
88
|
-
"type": "string | undefined"
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"name": "jobTitle",
|
|
92
|
-
"tags": [],
|
|
93
|
-
"docs": "",
|
|
94
|
-
"complexTypes": [],
|
|
95
|
-
"type": "string | undefined"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
"name": "departmentName",
|
|
99
|
-
"tags": [],
|
|
100
|
-
"docs": "",
|
|
101
|
-
"complexTypes": [],
|
|
102
|
-
"type": "string | undefined"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"name": "organizationName",
|
|
106
|
-
"tags": [],
|
|
107
|
-
"docs": "",
|
|
108
|
-
"complexTypes": [],
|
|
109
|
-
"type": "string | undefined"
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
"name": "note",
|
|
113
|
-
"tags": [],
|
|
114
|
-
"docs": "",
|
|
115
|
-
"complexTypes": [],
|
|
116
|
-
"type": "string | undefined"
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
"name": "phoneNumbers",
|
|
120
|
-
"tags": [],
|
|
121
|
-
"docs": "",
|
|
122
|
-
"complexTypes": [],
|
|
123
|
-
"type": "any[] | undefined"
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
"name": "emailAddresses",
|
|
127
|
-
"tags": [],
|
|
128
|
-
"docs": "",
|
|
129
|
-
"complexTypes": [],
|
|
130
|
-
"type": "any[] | undefined"
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
"name": "postalAddresses",
|
|
134
|
-
"tags": [],
|
|
135
|
-
"docs": "",
|
|
136
|
-
"complexTypes": [],
|
|
137
|
-
"type": "any[] | undefined"
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
}
|
|
141
|
-
],
|
|
142
|
-
"enums": [],
|
|
143
|
-
"typeAliases": [],
|
|
144
|
-
"pluginConfigs": []
|
|
145
|
-
}
|