Report search result total to UI

Change-Id: Ic88e7594b98548a96c8c6f96d2f8a585e539f520
This commit is contained in:
Marc Blank 2012-03-09 14:04:49 -08:00
parent ebb79619e8
commit 55d0e821ea
2 changed files with 40 additions and 11 deletions

View File

@ -40,6 +40,10 @@ public class SearchParams implements Parcelable {
// If zero, specifies a "new" search; otherwise, asks for a continuation of the previous
// query(ies) starting with the mOffset'th match (0 based)
public int mOffset = DEFAULT_OFFSET;
// The total number of results for this search
public int mTotalCount = 0;
// The id of the "search" mailbox being used
public long mSearchMailboxId;
/**
* Error codes returned by the searchMessages API
@ -54,6 +58,12 @@ public class SearchParams implements Parcelable {
mFilter = filter;
}
public SearchParams(long mailboxId, String filter, long searchMailboxId) {
mMailboxId = mailboxId;
mFilter = filter;
mSearchMailboxId = searchMailboxId;
}
@Override
public boolean equals(Object o) {
if (o == this) {

View File

@ -2072,12 +2072,15 @@ outer:
} else {
sb.append(',');
}
String val = map.get(column);
// If we don't have the column, be permissive, returning "0 AS <column>", and warn
if (val == null) {
String val = null;
// First look at values; this is an override of default behavior
if (values.containsKey(column)) {
val = "'" + values.getAsString(column) + "' AS " + column;
} else {
// Now, get the standard value for the column from our projection map
val = map.get(column);
// If we don't have the column, return "NULL AS <column>", and warn
if (val == null) {
Log.w(TAG, "UIProvider column not found, returning NULL: " + column);
val = "NULL AS " + column;
}
@ -2162,8 +2165,15 @@ outer:
* @param uiProjection as passed from UnifiedEmail
* @return the SQLite query to be executed on the EmailProvider database
*/
private String genQueryMailbox(String[] uiProjection) {
StringBuilder sb = genSelect(sFolderListMap, uiProjection);
private String genQueryMailbox(String[] uiProjection, String id) {
long mailboxId = Long.parseLong(id);
ContentValues values = EMPTY_CONTENT_VALUES;
if (mSearchParams != null && mailboxId == mSearchParams.mSearchMailboxId) {
// This is the current search mailbox; use the total count
values = new ContentValues();
values.put(UIProvider.FolderColumns.TOTAL_COUNT, mSearchParams.mTotalCount);
}
StringBuilder sb = genSelect(sFolderListMap, uiProjection, values);
sb.append(" FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.ID + "=?");
return sb.toString();
}
@ -2367,7 +2377,7 @@ outer:
notifyUri = UIPROVIDER_ATTACHMENT_NOTIFIER.buildUpon().appendPath(id).build();
break;
case UI_FOLDER:
c = db.rawQuery(genQueryMailbox(uiProjection), new String[] {id});
c = db.rawQuery(genQueryMailbox(uiProjection, id), new String[] {id});
notifyUri = UIPROVIDER_MAILBOX_NOTIFIER.buildUpon().appendPath(id).build();
break;
case UI_ACCOUNT:
@ -2800,6 +2810,10 @@ outer:
Log.d(TAG, "[Notify UI: " + notifyUri + "]");
}
private void notifyUI(Uri uri, long id) {
notifyUI(uri, Long.toString(id));
}
/**
* Support for services and service notifications
*/
@ -2888,12 +2902,13 @@ outer:
if (filter == null) {
throw new IllegalArgumentException("No query parameter in search query");
}
mSearchParams = new SearchParams(inbox.mId, filter);
// Find/create our search mailbox
Mailbox searchMailbox = getSearchMailbox(accountId);
final long searchMailboxId = searchMailbox.mId;
mSearchParams = new SearchParams(inbox.mId, filter, searchMailboxId);
final Context context = getContext();
if (mSearchParams.mOffset == 0) {
// Delete existing contents of search mailbox
@ -2916,7 +2931,11 @@ outer:
mServiceCallback, accountId);
if (service != null) {
try {
service.searchMessages(accountId, mSearchParams, searchMailboxId);
// Save away the total count
mSearchParams.mTotalCount = service.searchMessages(accountId,
mSearchParams, searchMailboxId);
Log.d(TAG, "TotalCount to UI: " + mSearchParams.mTotalCount);
notifyUI(UIPROVIDER_MAILBOX_NOTIFIER, searchMailboxId);
} catch (RemoteException e) {
Log.e("searchMessages", "RemoteException", e);
}