Fix result count reporting for phone queries
Result count ordering was reporting number of phones as number of
contacts. Fix so for phone list queries we tally number of actual
contacts displayed.
Bug:10457343
Change-Id: Iabd3bd600d47e013a69f6e6ed2bf378a9b344e9f
diff --git a/src/com/android/contacts/common/list/ContactEntryListAdapter.java b/src/com/android/contacts/common/list/ContactEntryListAdapter.java
index c9e74e4..a99d7b4 100644
--- a/src/com/android/contacts/common/list/ContactEntryListAdapter.java
+++ b/src/com/android/contacts/common/list/ContactEntryListAdapter.java
@@ -566,7 +566,7 @@
if (directoryPartition.isLoading()) {
countText.setText(R.string.search_results_searching);
} else {
- int count = cursor == null ? 0 : cursor.getCount();
+ int count = getResultCount(cursor);
final int limit = getDirectoryResultLimit(directoryPartition);
if (directoryId != Directory.DEFAULT && directoryId != Directory.LOCAL_INVISIBLE
&& count >= limit) {
@@ -578,6 +578,13 @@
}
}
+ // Default implementation simply returns number of rows in the cursor.
+ // Broken out into its own routine so can be overridden by child classes
+ // for eg number of unique contacts for a phone list.
+ protected int getResultCount(Cursor cursor) {
+ return cursor == null ? 0 : cursor.getCount();
+ }
+
/**
* Checks whether the contact entry at the given position represents the user's profile.
*/
diff --git a/src/com/android/contacts/common/list/PhoneNumberListAdapter.java b/src/com/android/contacts/common/list/PhoneNumberListAdapter.java
index 43797cc..c85c4e5 100644
--- a/src/com/android/contacts/common/list/PhoneNumberListAdapter.java
+++ b/src/com/android/contacts/common/list/PhoneNumberListAdapter.java
@@ -281,6 +281,26 @@
view.setHighlightedPrefix(isSearchMode() ? getUpperCaseQueryString() : null);
}
+ // Override default, which would return number of phone numbers, so we
+ // instead return number of contacts.
+ @Override
+ protected int getResultCount(Cursor cursor) {
+ if (cursor == null) {
+ return 0;
+ }
+ cursor.moveToPosition(-1);
+ long curContactId = -1;
+ int numContacts = 0;
+ while(cursor.moveToNext()) {
+ final long contactId = cursor.getLong(PhoneQuery.CONTACT_ID);
+ if (contactId != curContactId) {
+ curContactId = contactId;
+ ++numContacts;
+ }
+ }
+ return numContacts;
+ }
+
@Override
protected void bindView(View itemView, int partition, Cursor cursor, int position) {
ContactListItemView view = (ContactListItemView)itemView;