Return total number of results from IMAP search

Change-Id: I44eb83042774294aa5aaa8f45a46b82dd78b0141
This commit is contained in:
Marc Blank 2011-06-27 18:16:04 -07:00
parent bc1fa23031
commit 5a9c95f94e
2 changed files with 15 additions and 12 deletions

View File

@ -912,11 +912,11 @@ public class Controller {
* @param searchParams the parameters for this search
* @throws MessagingException
*/
public void searchMessages(final long accountId, final SearchParams searchParams)
public int searchMessages(final long accountId, final SearchParams searchParams)
throws MessagingException {
// Find/create our search mailbox
Mailbox searchMailbox = getSearchMailbox(accountId);
if (searchMailbox == null) return;
if (searchMailbox == null) return 0;
final long searchMailboxId = searchMailbox.mId;
// Save this away (per account)
sSearchParamsMap.put(accountId, searchParams);
@ -937,11 +937,12 @@ public class Controller {
if (service != null) {
// Service implementation
try {
service.searchMessages(accountId, searchParams, searchMailboxId);
return service.searchMessages(accountId, searchParams, searchMailboxId);
} catch (RemoteException e) {
// TODO Change exception handling to be consistent with however this method
// is implemented for other protocols
Log.e("searchMessages", "RemoteException", e);
return 0;
}
} else {
// This is the actual mailbox we'll be searching
@ -949,13 +950,13 @@ public class Controller {
if (actualMailbox == null) {
Log.e(Logging.LOG_TAG, "Unable to find mailbox " + searchParams.mMailboxId
+ " to search in with " + searchParams);
return;
return 0;
}
// Do the search
if (Email.DEBUG) {
Log.d(Logging.LOG_TAG, "Search: " + searchParams.mFilter);
}
mLegacyController.searchMailbox(accountId, searchParams, searchMailboxId);
return mLegacyController.searchMailbox(accountId, searchParams, searchMailboxId);
}
}

View File

@ -590,10 +590,10 @@ public class MessagingController implements Runnable {
}
}
public void searchMailbox(long accountId, SearchParams searchParams, long destMailboxId)
public int searchMailbox(long accountId, SearchParams searchParams, long destMailboxId)
throws MessagingException {
try {
searchMailboxImpl(accountId, searchParams, destMailboxId);
return searchMailboxImpl(accountId, searchParams, destMailboxId);
} finally {
// Tell UI that we're done loading any search results (no harm calling this even if we
// encountered an error or never sent a "started" message)
@ -601,7 +601,7 @@ public class MessagingController implements Runnable {
}
}
private void searchMailboxImpl(long accountId, SearchParams searchParams,
private int searchMailboxImpl(long accountId, SearchParams searchParams,
final long destMailboxId) throws MessagingException {
final Account account = Account.restoreAccountWithId(mContext, accountId);
final Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, searchParams.mMailboxId);
@ -609,7 +609,7 @@ public class MessagingController implements Runnable {
if (account == null || mailbox == null || destMailbox == null) {
Log.d(Logging.LOG_TAG, "Attempted search for " + searchParams
+ " but account or mailbox information was missing");
return;
return 0;
}
// Tell UI that we're loading messages
@ -645,10 +645,11 @@ public class MessagingController implements Runnable {
sortableMessages = sSearchResults.get(accountId);
}
int numSearchResults = sortableMessages.length;
int numToLoad = Math.min(numSearchResults - searchParams.mOffset, searchParams.mLimit);
final int numSearchResults = sortableMessages.length;
final int numToLoad =
Math.min(numSearchResults - searchParams.mOffset, searchParams.mLimit);
if (numToLoad <= 0) {
return;
return 0;
}
final ArrayList<Message> messageList = new ArrayList<Message>();
@ -700,6 +701,7 @@ public class MessagingController implements Runnable {
public void loadAttachmentProgress(int progress) {
}
});
return numSearchResults;
}