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

Android fix load contacts no email no phone and setNameMatch with pagesize #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,8 @@ private List<String> getAllContacts() {
}

public WritableArray getContacts(QueryParams params) {
if (matchName != null) {
return getContactsWithNameFilter(params);
} else {
List<Contact> contactsWithRange = getContactsWithRange(params);
return toWritableArray(params, new List[]{contactsWithRange});
}
}

private WritableArray getContactsWithNameFilter(QueryParams params) {
ensureContactIds();
int size = contactIds.size();
int offset = 0;
List<List<Contact>> contactLists = new ArrayList<>();
while (size > 0) {
params.size = size > MAX_ARGS ? MAX_ARGS : size;
params.offset = offset;
contactLists.add(getContactsWithRange(params));

offset += params.size;
size = size - MAX_ARGS;
}
List[] lists = contactLists.toArray(new List[contactLists.size()]);
return toWritableArray(params, lists);
List<Contact> contactsWithRange = getContactsWithRange(params);
return toWritableArray(params, new List[]{contactsWithRange});
}

private List<Contact> getContactsWithRange(QueryParams params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,20 @@ String getSelection() {
if (matchName != null) {
return getMatchNameSelection();
}
return combineMimeTypeAndContactsSelection(getMimeTypeSelection(), getContactSelection());
}

private String combineMimeTypeAndContactsSelection(String mimeTypeSelection, String contactSelection) {
String result = "";
if (!TextUtils.isEmpty(mimeTypeSelection)) {
result = mimeTypeSelection;
}
if (!TextUtils.isEmpty(contactSelection)) {
if (!TextUtils.isEmpty(mimeTypeSelection)) {
result = "(" + result + ") AND (" + contactSelection + ")";
} else {
result = contactSelection;
}
}
return result.isEmpty() ? null : result;
return getContactSelection();
}

String[] getSelectionArgs() {
if (matchName != null) {
return getMatchNameSelectionArgs();
}
return Collections.concat(selectionArgs, contactsToFetch);
return Collections.concat(new ArrayList<String>(), contactsToFetch);
}

private String[] getMatchNameSelectionArgs() {
return new String[]{"%" + matchName + "%"};
}

private String getMimeTypeSelection() {
return getSelection(ContactsContract.Data.MIMETYPE, selectionArgs.size());
}

private String getContactSelection() {
return getSelection(ContactsContract.Data.CONTACT_ID, contactsToFetch.size());
Expand Down