aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Millar <emillar@google.com>2009-10-21 14:47:14 -0700
committerEvan Millar <emillar@google.com>2009-10-22 09:53:53 -0700
commit5e28b3a5e44bf4f2c0980c50a2ab35350fc5f230 (patch)
tree5c98ac49b3939ccbcd514ad36c3a887fb9be28cb
parent9a75d6d827c7a9810e39d2abf9757862044a0714 (diff)
downloadContactsProvider-5e28b3a5e44bf4f2c0980c50a2ab35350fc5f230.tar.gz
Fix favorite ordering bug (http://b/issue?id=2197247)
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 00204ed7..337cc9b9 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -145,8 +145,10 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+ private static final String TIMES_CONTACED_SORT_COLUMN = "times_contacted_sort";
+
private static final String STREQUENT_ORDER_BY = Contacts.STARRED + " DESC, "
- + Contacts.TIMES_CONTACTED + " DESC, "
+ + TIMES_CONTACED_SORT_COLUMN + " DESC, "
+ Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
private static final String STREQUENT_LIMIT =
"(SELECT COUNT(1) FROM " + Tables.CONTACTS + " WHERE "
@@ -347,6 +349,9 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
private static final HashMap<String, String> sCountProjectionMap;
/** Contains just the contacts columns */
private static final HashMap<String, String> sContactsProjectionMap;
+ /** Used for pushing starred contacts to the top of a times contacted list **/
+ private static final HashMap<String, String> sStrequentStarredProjectionMap;
+ private static final HashMap<String, String> sStrequentFrequentProjectionMap;
/** Contains just the contacts vCard columns */
private static final HashMap<String, String> sContactsVCardProjectionMap;
/** Contains just the raw contacts columns */
@@ -504,6 +509,14 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
addProjection(sContactsProjectionMap, Contacts.CONTACT_STATUS_ICON,
ContactsStatusUpdatesColumns.CONCRETE_STATUS_ICON);
+ sStrequentStarredProjectionMap = new HashMap<String, String>(sContactsProjectionMap);
+ sStrequentStarredProjectionMap.put(TIMES_CONTACED_SORT_COLUMN,
+ Long.MAX_VALUE + " AS " + TIMES_CONTACED_SORT_COLUMN);
+
+ sStrequentFrequentProjectionMap = new HashMap<String, String>(sContactsProjectionMap);
+ sStrequentFrequentProjectionMap.put(TIMES_CONTACED_SORT_COLUMN,
+ Contacts.TIMES_CONTACTED + " AS " + TIMES_CONTACED_SORT_COLUMN);
+
sContactsVCardProjectionMap = Maps.newHashMap();
sContactsVCardProjectionMap.put(OpenableColumns.DISPLAY_NAME, Contacts.DISPLAY_NAME
+ " || '.vcf' AS " + OpenableColumns.DISPLAY_NAME);
@@ -3377,11 +3390,19 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
setTablesAndProjectionMapForContacts(qb, uri, projection);
+ String[] starredProjection = null;
+ String[] frequentProjection = null;
+ if (projection != null) {
+ starredProjection = appendProjectionArg(projection, TIMES_CONTACED_SORT_COLUMN);
+ frequentProjection = appendProjectionArg(projection, TIMES_CONTACED_SORT_COLUMN);
+ }
+
// Build the first query for starred
if (filterSql != null) {
qb.appendWhere(filterSql);
}
- final String starredQuery = qb.buildQuery(projection, Contacts.STARRED + "=1",
+ qb.setProjectionMap(sStrequentStarredProjectionMap);
+ final String starredQuery = qb.buildQuery(starredProjection, Contacts.STARRED + "=1",
null, Contacts._ID, null, null, null);
// Build the second query for frequent
@@ -3390,7 +3411,8 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
if (filterSql != null) {
qb.appendWhere(filterSql);
}
- final String frequentQuery = qb.buildQuery(projection,
+ qb.setProjectionMap(sStrequentFrequentProjectionMap);
+ final String frequentQuery = qb.buildQuery(frequentProjection,
Contacts.TIMES_CONTACTED + " > 0 AND (" + Contacts.STARRED
+ " = 0 OR " + Contacts.STARRED + " IS NULL)",
null, Contacts._ID, null, null, null);
@@ -4941,6 +4963,17 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun
}
}
+ private String[] appendProjectionArg(String[] projection, String arg) {
+ if (projection == null) {
+ return null;
+ }
+ final int length = projection.length;
+ String[] newProjection = new String[length + 1];
+ System.arraycopy(projection, 0, newProjection, 0, length);
+ newProjection[length] = arg;
+ return newProjection;
+ }
+
protected Account getDefaultAccount() {
AccountManager accountManager = AccountManager.get(getContext());
try {