1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

unify the synchronous and asynchronous codepaths for listlocalmessages

This commit is contained in:
Jesse Vincent 2009-12-18 02:36:37 +00:00
parent 157455f26b
commit 25306fad83

View File

@ -545,8 +545,7 @@ public class MessagingController implements Runnable
/** /**
* List the local message store for the given folder. This work is done * List the messages in the local message store for the given folder asynchronously.
* synchronously.
* *
* @param account * @param account
* @param folder * @param folder
@ -559,6 +558,23 @@ public class MessagingController implements Runnable
{ {
public void run() public void run()
{ {
listLocalMessagesSynchronous(account, folder, listener);
}
});
}
/**
* List the messages in the local message store for the given folder synchronously.
*
* @param account
* @param folder
* @param listener
* @throws MessagingException
*/
public void listLocalMessagesSynchronous(final Account account, final String folder, final MessagingListener listener)
{
for (MessagingListener l : getListeners()) for (MessagingListener l : getListeners())
{ {
l.listLocalMessagesStarted(account, folder); l.listLocalMessagesStarted(account, folder);
@ -587,34 +603,44 @@ public class MessagingController implements Runnable
public void messageStarted(String message, int number, int ofTotal) {} public void messageStarted(String message, int number, int ofTotal) {}
public void messageFinished(Message message, int number, int ofTotal) { public void messageFinished(Message message, int number, int ofTotal)
{
if (isMessageSuppressed(account, folder, message) == false) { if (isMessageSuppressed(account, folder, message) == false)
{
pendingMessages.add(message); pendingMessages.add(message);
totalDone++; totalDone++;
if (pendingMessages.size() > 10) { if (pendingMessages.size() > 10)
{
callbackPending(); callbackPending();
} }
} else { }
for (MessagingListener l : getListeners()) { else
{
for (MessagingListener l : getListeners())
{
l.listLocalMessagesRemoveMessage(account, folder, message); l.listLocalMessagesRemoveMessage(account, folder, message);
} }
if (listener != null && getListeners().contains(listener) == false) { if (listener != null && getListeners().contains(listener) == false)
{
listener.listLocalMessagesRemoveMessage(account, folder, message); listener.listLocalMessagesRemoveMessage(account, folder, message);
} }
} }
} }
public void messagesFinished(int number) { public void messagesFinished(int number)
{
callbackPending(); callbackPending();
} }
private void callbackPending() private void callbackPending()
{ {
for (MessagingListener l : getListeners()) { for (MessagingListener l : getListeners())
{
l.listLocalMessagesAddMessages(account, folder, pendingMessages); l.listLocalMessagesAddMessages(account, folder, pendingMessages);
} }
if (listener != null && getListeners().contains(listener) == false) { if (listener != null && getListeners().contains(listener) == false)
{
listener.listLocalMessagesAddMessages(account, folder, pendingMessages); listener.listLocalMessagesAddMessages(account, folder, pendingMessages);
} }
pendingMessages.clear(); pendingMessages.clear();
@ -662,56 +688,6 @@ public class MessagingController implements Runnable
} }
} }
} }
});
}
public void listLocalMessagesSynchronous(final Account account, final String folder, final MessagingListener listener)
{
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Folder localFolder;
localFolder = localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
localFolder.getMessages(
new MessageRetrievalListener()
{
int totalDone = 0;
public void messageStarted(String uid, int number, int ofTotal){};
public void messagesFinished(int total) {};
public void messageFinished(Message message, int number, int ofTotal)
{
if (isMessageSuppressed(account, folder, message) == false)
{
List<Message> messages = new ArrayList<Message>();
messages.add(message);
listener.listLocalMessagesAddMessages(account,folder, messages);
totalDone++;
}
else
{
listener.listLocalMessagesRemoveMessage(account, folder, message);
}
}
},
false // Skip deleted messages
);
localFolder.close(false);
}
catch (Exception e)
{
}
finally
{
}
}
public void loadMoreMessages(Account account, String folder, MessagingListener listener) public void loadMoreMessages(Account account, String folder, MessagingListener listener)
{ {
try try