From 5a9c95f94eaaed326d3116b539b7005ab4f3f8c7 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Mon, 27 Jun 2011 18:16:04 -0700 Subject: [PATCH] Return total number of results from IMAP search Change-Id: I44eb83042774294aa5aaa8f45a46b82dd78b0141 --- src/com/android/email/Controller.java | 11 ++++++----- src/com/android/email/MessagingController.java | 16 +++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index d8fde03f2..be163cb7f 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -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); } } diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index 631461d33..c3fedf434 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -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 messageList = new ArrayList(); @@ -700,6 +701,7 @@ public class MessagingController implements Runnable { public void loadAttachmentProgress(int progress) { } }); + return numSearchResults; }