1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-13 21:15:08 -05:00

Refactor the MessagingController to be a bit easier to tease apart.

This commit is contained in:
Jesse Vincent 2008-11-01 21:34:50 +00:00
parent 5491dee81b
commit cd7a7a67fb

View File

@ -151,8 +151,8 @@ public class MessagingController implements Runnable {
* listFoldersCallback for local folders before it returns, and then for * listFoldersCallback for local folders before it returns, and then for
* remote folders at some later point. If there are no local folders * remote folders at some later point. If there are no local folders
* includeRemote is forced by this method. This method should be called from * includeRemote is forced by this method. This method should be called from
* a Thread as it may take several seconds to list the local folders. TODO * a Thread as it may take several seconds to list the local folders.
* this needs to cache the remote folder list * TODO this needs to cache the remote folder list
* *
* @param account * @param account
* @param includeRemote * @param includeRemote
@ -171,20 +171,26 @@ public class MessagingController implements Runnable {
Folder[] localFolders = localStore.getPersonalNamespaces(); Folder[] localFolders = localStore.getPersonalNamespaces();
if ( localFolders == null || localFolders.length == 0) { if ( localFolders == null || localFolders.length == 0) {
refreshRemote = true; doRefreshRemote(account, listener);
} else { return;
}
for (MessagingListener l : mListeners) { for (MessagingListener l : mListeners) {
l.listFolders(account, localFolders); l.listFolders(account, localFolders);
} }
} }
}
catch (Exception e) { catch (Exception e) {
for (MessagingListener l : mListeners) { for (MessagingListener l : mListeners) {
l.listFoldersFailed(account, e.getMessage()); l.listFoldersFailed(account, e.getMessage());
return; return;
} }
} }
if (refreshRemote) { for (MessagingListener l : mListeners) {
l.listFoldersFinished(account);
}
}
private void doRefreshRemote (final Account account, MessagingListener listener) {
put("listFolders", listener, new Runnable() { put("listFolders", listener, new Runnable() {
public void run() { public void run() {
try { try {
@ -199,6 +205,7 @@ public class MessagingController implements Runnable {
for (int i = 0, count = remoteFolders.length; i < count; i++) { for (int i = 0, count = remoteFolders.length; i < count; i++) {
Folder localFolder = localStore.getFolder(remoteFolders[i].getName()); Folder localFolder = localStore.getFolder(remoteFolders[i].getName());
if (!localFolder.exists()) { if (!localFolder.exists()) {
localFolder.create(FolderType.HOLDS_MESSAGES); localFolder.create(FolderType.HOLDS_MESSAGES);
} }
remoteFolderNames.add(remoteFolders[i].getName()); remoteFolderNames.add(remoteFolders[i].getName());
@ -239,13 +246,10 @@ public class MessagingController implements Runnable {
} }
} }
}); });
} else {
for (MessagingListener l : mListeners) {
l.listFoldersFinished(account);
}
}
} }
/** /**
* List the local message store for the given folder. This work is done * List the local message store for the given folder. This work is done
* synchronously. * synchronously.