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:
parent
157455f26b
commit
25306fad83
@ -545,8 +545,7 @@ public class MessagingController implements Runnable
|
||||
|
||||
|
||||
/**
|
||||
* List the local message store for the given folder. This work is done
|
||||
* synchronously.
|
||||
* List the messages in the local message store for the given folder asynchronously.
|
||||
*
|
||||
* @param account
|
||||
* @param folder
|
||||
@ -559,6 +558,23 @@ public class MessagingController implements Runnable
|
||||
{
|
||||
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())
|
||||
{
|
||||
l.listLocalMessagesStarted(account, folder);
|
||||
@ -587,34 +603,44 @@ public class MessagingController implements Runnable
|
||||
|
||||
|
||||
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);
|
||||
totalDone++;
|
||||
if (pendingMessages.size() > 10) {
|
||||
if (pendingMessages.size() > 10)
|
||||
{
|
||||
callbackPending();
|
||||
}
|
||||
|
||||
} else {
|
||||
for (MessagingListener l : getListeners()) {
|
||||
}
|
||||
else
|
||||
{
|
||||
for (MessagingListener l : getListeners())
|
||||
{
|
||||
l.listLocalMessagesRemoveMessage(account, folder, message);
|
||||
}
|
||||
if (listener != null && getListeners().contains(listener) == false) {
|
||||
if (listener != null && getListeners().contains(listener) == false)
|
||||
{
|
||||
listener.listLocalMessagesRemoveMessage(account, folder, message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void messagesFinished(int number) {
|
||||
public void messagesFinished(int number)
|
||||
{
|
||||
callbackPending();
|
||||
}
|
||||
private void callbackPending()
|
||||
{
|
||||
for (MessagingListener l : getListeners()) {
|
||||
for (MessagingListener l : getListeners())
|
||||
{
|
||||
l.listLocalMessagesAddMessages(account, folder, pendingMessages);
|
||||
}
|
||||
if (listener != null && getListeners().contains(listener) == false) {
|
||||
if (listener != null && getListeners().contains(listener) == false)
|
||||
{
|
||||
listener.listLocalMessagesAddMessages(account, folder, pendingMessages);
|
||||
}
|
||||
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)
|
||||
{
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user