Return total number of results from IMAP search
Change-Id: I44eb83042774294aa5aaa8f45a46b82dd78b0141
This commit is contained in:
parent
bc1fa23031
commit
5a9c95f94e
@ -912,11 +912,11 @@ public class Controller {
|
|||||||
* @param searchParams the parameters for this search
|
* @param searchParams the parameters for this search
|
||||||
* @throws MessagingException
|
* @throws MessagingException
|
||||||
*/
|
*/
|
||||||
public void searchMessages(final long accountId, final SearchParams searchParams)
|
public int searchMessages(final long accountId, final SearchParams searchParams)
|
||||||
throws MessagingException {
|
throws MessagingException {
|
||||||
// Find/create our search mailbox
|
// Find/create our search mailbox
|
||||||
Mailbox searchMailbox = getSearchMailbox(accountId);
|
Mailbox searchMailbox = getSearchMailbox(accountId);
|
||||||
if (searchMailbox == null) return;
|
if (searchMailbox == null) return 0;
|
||||||
final long searchMailboxId = searchMailbox.mId;
|
final long searchMailboxId = searchMailbox.mId;
|
||||||
// Save this away (per account)
|
// Save this away (per account)
|
||||||
sSearchParamsMap.put(accountId, searchParams);
|
sSearchParamsMap.put(accountId, searchParams);
|
||||||
@ -937,11 +937,12 @@ public class Controller {
|
|||||||
if (service != null) {
|
if (service != null) {
|
||||||
// Service implementation
|
// Service implementation
|
||||||
try {
|
try {
|
||||||
service.searchMessages(accountId, searchParams, searchMailboxId);
|
return service.searchMessages(accountId, searchParams, searchMailboxId);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// TODO Change exception handling to be consistent with however this method
|
// TODO Change exception handling to be consistent with however this method
|
||||||
// is implemented for other protocols
|
// is implemented for other protocols
|
||||||
Log.e("searchMessages", "RemoteException", e);
|
Log.e("searchMessages", "RemoteException", e);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This is the actual mailbox we'll be searching
|
// This is the actual mailbox we'll be searching
|
||||||
@ -949,13 +950,13 @@ public class Controller {
|
|||||||
if (actualMailbox == null) {
|
if (actualMailbox == null) {
|
||||||
Log.e(Logging.LOG_TAG, "Unable to find mailbox " + searchParams.mMailboxId
|
Log.e(Logging.LOG_TAG, "Unable to find mailbox " + searchParams.mMailboxId
|
||||||
+ " to search in with " + searchParams);
|
+ " to search in with " + searchParams);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
// Do the search
|
// Do the search
|
||||||
if (Email.DEBUG) {
|
if (Email.DEBUG) {
|
||||||
Log.d(Logging.LOG_TAG, "Search: " + searchParams.mFilter);
|
Log.d(Logging.LOG_TAG, "Search: " + searchParams.mFilter);
|
||||||
}
|
}
|
||||||
mLegacyController.searchMailbox(accountId, searchParams, searchMailboxId);
|
return mLegacyController.searchMailbox(accountId, searchParams, searchMailboxId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
throws MessagingException {
|
||||||
try {
|
try {
|
||||||
searchMailboxImpl(accountId, searchParams, destMailboxId);
|
return searchMailboxImpl(accountId, searchParams, destMailboxId);
|
||||||
} finally {
|
} finally {
|
||||||
// Tell UI that we're done loading any search results (no harm calling this even if we
|
// 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)
|
// 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 long destMailboxId) throws MessagingException {
|
||||||
final Account account = Account.restoreAccountWithId(mContext, accountId);
|
final Account account = Account.restoreAccountWithId(mContext, accountId);
|
||||||
final Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, searchParams.mMailboxId);
|
final Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, searchParams.mMailboxId);
|
||||||
@ -609,7 +609,7 @@ public class MessagingController implements Runnable {
|
|||||||
if (account == null || mailbox == null || destMailbox == null) {
|
if (account == null || mailbox == null || destMailbox == null) {
|
||||||
Log.d(Logging.LOG_TAG, "Attempted search for " + searchParams
|
Log.d(Logging.LOG_TAG, "Attempted search for " + searchParams
|
||||||
+ " but account or mailbox information was missing");
|
+ " but account or mailbox information was missing");
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell UI that we're loading messages
|
// Tell UI that we're loading messages
|
||||||
@ -645,10 +645,11 @@ public class MessagingController implements Runnable {
|
|||||||
sortableMessages = sSearchResults.get(accountId);
|
sortableMessages = sSearchResults.get(accountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int numSearchResults = sortableMessages.length;
|
final int numSearchResults = sortableMessages.length;
|
||||||
int numToLoad = Math.min(numSearchResults - searchParams.mOffset, searchParams.mLimit);
|
final int numToLoad =
|
||||||
|
Math.min(numSearchResults - searchParams.mOffset, searchParams.mLimit);
|
||||||
if (numToLoad <= 0) {
|
if (numToLoad <= 0) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<Message> messageList = new ArrayList<Message>();
|
final ArrayList<Message> messageList = new ArrayList<Message>();
|
||||||
@ -700,6 +701,7 @@ public class MessagingController implements Runnable {
|
|||||||
public void loadAttachmentProgress(int progress) {
|
public void loadAttachmentProgress(int progress) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return numSearchResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user