Messaging: Don't show numbers of contacts multiple times
* Somehow there are multiple entries per some numbers, sometimes stored with, sometimes without spaces and/or invisible characters * This leads to the same number being shown multiple times * Don't add those entries by comparing number and type of all already added entries with the staging one Change-Id: Ic815393d3d4f4ba56107f42c9d8940309564554c
This commit is contained in:
@@ -74,7 +74,7 @@ public class FrequentContactsCursorBuilder {
|
|||||||
* are both ready to be consumed.
|
* are both ready to be consumed.
|
||||||
* @return the frequent contact cursor if built successfully, or null if it can't be built yet.
|
* @return the frequent contact cursor if built successfully, or null if it can't be built yet.
|
||||||
*/
|
*/
|
||||||
public Cursor build() {
|
public Cursor build(boolean getAllContacts) {
|
||||||
if (mFrequentContactsCursor != null && mAllContactsCursor != null) {
|
if (mFrequentContactsCursor != null && mAllContactsCursor != null) {
|
||||||
Assert.isTrue(!mFrequentContactsCursor.isClosed());
|
Assert.isTrue(!mFrequentContactsCursor.isClosed());
|
||||||
Assert.isTrue(!mAllContactsCursor.isClosed());
|
Assert.isTrue(!mAllContactsCursor.isClosed());
|
||||||
@@ -108,7 +108,7 @@ public class FrequentContactsCursorBuilder {
|
|||||||
mAllContactsCursor.moveToPosition(-1);
|
mAllContactsCursor.moveToPosition(-1);
|
||||||
while (mAllContactsCursor.moveToNext()) {
|
while (mAllContactsCursor.moveToNext()) {
|
||||||
final String lookupKey = mAllContactsCursor.getString(ContactUtil.INDEX_LOOKUP_KEY);
|
final String lookupKey = mAllContactsCursor.getString(ContactUtil.INDEX_LOOKUP_KEY);
|
||||||
if (lookupKeyToRankMap.containsKey(lookupKey)) {
|
if (lookupKeyToRankMap.containsKey(lookupKey) || getAllContacts) {
|
||||||
final Object[] row = new Object[ContactUtil.PhoneQuery.PROJECTION.length];
|
final Object[] row = new Object[ContactUtil.PhoneQuery.PROJECTION.length];
|
||||||
row[ContactUtil.INDEX_DATA_ID] =
|
row[ContactUtil.INDEX_DATA_ID] =
|
||||||
mAllContactsCursor.getLong(ContactUtil.INDEX_DATA_ID);
|
mAllContactsCursor.getLong(ContactUtil.INDEX_DATA_ID);
|
||||||
@@ -121,16 +121,38 @@ public class FrequentContactsCursorBuilder {
|
|||||||
row[ContactUtil.INDEX_PHOTO_URI] =
|
row[ContactUtil.INDEX_PHOTO_URI] =
|
||||||
mAllContactsCursor.getString(ContactUtil.INDEX_PHOTO_URI);
|
mAllContactsCursor.getString(ContactUtil.INDEX_PHOTO_URI);
|
||||||
row[ContactUtil.INDEX_PHONE_EMAIL] =
|
row[ContactUtil.INDEX_PHONE_EMAIL] =
|
||||||
mAllContactsCursor.getString(ContactUtil.INDEX_PHONE_EMAIL);
|
mAllContactsCursor.getString(ContactUtil.INDEX_PHONE_EMAIL)
|
||||||
|
.replaceAll("[^\\d+]", "");
|
||||||
row[ContactUtil.INDEX_PHONE_EMAIL_TYPE] =
|
row[ContactUtil.INDEX_PHONE_EMAIL_TYPE] =
|
||||||
mAllContactsCursor.getInt(ContactUtil.INDEX_PHONE_EMAIL_TYPE);
|
mAllContactsCursor.getInt(ContactUtil.INDEX_PHONE_EMAIL_TYPE);
|
||||||
row[ContactUtil.INDEX_PHONE_EMAIL_LABEL] =
|
row[ContactUtil.INDEX_PHONE_EMAIL_LABEL] =
|
||||||
mAllContactsCursor.getString(ContactUtil.INDEX_PHONE_EMAIL_LABEL);
|
mAllContactsCursor.getString(ContactUtil.INDEX_PHONE_EMAIL_LABEL);
|
||||||
|
|
||||||
|
boolean numberAlreadyAdded = false;
|
||||||
|
for (Object[] oldRow : rows) {
|
||||||
|
final int idxType = ContactUtil.INDEX_PHONE_EMAIL_TYPE;
|
||||||
|
final int idxPhone = ContactUtil.INDEX_PHONE_EMAIL;
|
||||||
|
if (oldRow[idxType] == row[idxType] &&
|
||||||
|
oldRow[idxPhone].toString().equals(row[idxPhone].toString())) {
|
||||||
|
numberAlreadyAdded = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!numberAlreadyAdded) {
|
||||||
rows.add(row);
|
rows.add(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mAllContactsCursor.moveToPosition(oldPosition);
|
mAllContactsCursor.moveToPosition(oldPosition);
|
||||||
|
|
||||||
|
// We can return all rows at this point, no sorting or further filtering needed
|
||||||
|
if (getAllContacts) {
|
||||||
|
for (final Object[] row : rows) {
|
||||||
|
retCursor.addRow(row);
|
||||||
|
}
|
||||||
|
return retCursor;
|
||||||
|
}
|
||||||
|
|
||||||
// Now we have a list of rows containing frequent contacts in alphabetical order.
|
// Now we have a list of rows containing frequent contacts in alphabetical order.
|
||||||
// Therefore, sort all the rows according to their actual ranks in the frequents list.
|
// Therefore, sort all the rows according to their actual ranks in the frequents list.
|
||||||
Collections.sort(rows, new Comparator<Object[]>() {
|
Collections.sort(rows, new Comparator<Object[]>() {
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ public class ContactPickerData extends BindableData implements
|
|||||||
if (isBound(cursorLoader.getBindingId())) {
|
if (isBound(cursorLoader.getBindingId())) {
|
||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
case ALL_CONTACTS_LOADER:
|
case ALL_CONTACTS_LOADER:
|
||||||
mListener.onAllContactsCursorUpdated(data);
|
|
||||||
mFrequentContactsCursorBuilder.setAllContacts(data);
|
mFrequentContactsCursorBuilder.setAllContacts(data);
|
||||||
break;
|
break;
|
||||||
case FREQUENT_CONTACTS_LOADER:
|
case FREQUENT_CONTACTS_LOADER:
|
||||||
@@ -115,10 +114,14 @@ public class ContactPickerData extends BindableData implements
|
|||||||
// all contacts and frequent contacts loader, and we don't know which will finish
|
// all contacts and frequent contacts loader, and we don't know which will finish
|
||||||
// first. Therefore, try to build the cursor and notify the listener if it's
|
// first. Therefore, try to build the cursor and notify the listener if it's
|
||||||
// successfully built.
|
// successfully built.
|
||||||
final Cursor frequentContactsCursor = mFrequentContactsCursorBuilder.build();
|
final Cursor frequentContactsCursor = mFrequentContactsCursorBuilder.build(false);
|
||||||
if (frequentContactsCursor != null) {
|
if (frequentContactsCursor != null) {
|
||||||
mListener.onFrequentContactsCursorUpdated(frequentContactsCursor);
|
mListener.onFrequentContactsCursorUpdated(frequentContactsCursor);
|
||||||
|
|
||||||
|
final Cursor allContactsCursor = mFrequentContactsCursorBuilder.build(true);
|
||||||
|
mListener.onAllContactsCursorUpdated(allContactsCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LogUtil.w(LogUtil.BUGLE_TAG, "Loader finished after unbinding the contacts list");
|
LogUtil.w(LogUtil.BUGLE_TAG, "Loader finished after unbinding the contacts list");
|
||||||
|
|||||||
Reference in New Issue
Block a user