1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-14 05:25:07 -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
@ -170,13 +170,14 @@ public class MessagingController implements Runnable {
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
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) {
@ -184,7 +185,12 @@ public class MessagingController implements Runnable {
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.