Merge pull request #4466 from k9mail/MessagingListener_cleanup
Remove MessagingController.listFolders() and associated callbacks
This commit is contained in:
commit
79259b678c
8 changed files with 8 additions and 186 deletions
|
@ -368,110 +368,16 @@ public class MessagingController {
|
|||
cache.removeValueForThreads(messageIds, columnName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lists folders that are available locally and remotely. This method calls
|
||||
* listFoldersCallback for local folders before it returns, and then for
|
||||
* remote folders at some later point. If there are no local folders
|
||||
* 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 this needs to cache the remote folder list
|
||||
*/
|
||||
public void listFolders(final Account account, final boolean refreshRemote, final MessagingListener listener) {
|
||||
threadPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listFoldersSynchronous(account, refreshRemote, listener);
|
||||
}
|
||||
});
|
||||
public void refreshFolderList(final Account account) {
|
||||
put("refreshFolderList", null, () -> refreshFolderListSynchronous(account));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists folders that are available locally and remotely. This method calls
|
||||
* listFoldersCallback for local folders before it returns, and then for
|
||||
* remote folders at some later point. If there are no local folders
|
||||
* includeRemote is forced by this method. This method is called in the
|
||||
* foreground.
|
||||
* TODO this needs to cache the remote folder list
|
||||
*/
|
||||
public void listFoldersSynchronous(final Account account, final boolean refreshRemote,
|
||||
final MessagingListener listener) {
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.listFoldersStarted(account);
|
||||
}
|
||||
List<LocalFolder> localFolders = null;
|
||||
if (!account.isAvailable(context)) {
|
||||
Timber.i("not listing folders of unavailable account");
|
||||
} else {
|
||||
try {
|
||||
LocalStore localStore = localStoreProvider.getInstance(account);
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
|
||||
if (refreshRemote || localFolders.isEmpty()) {
|
||||
doRefreshRemote(account, listener);
|
||||
return;
|
||||
}
|
||||
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.listFolders(account, localFolders);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.listFoldersFailed(account, e.getMessage());
|
||||
}
|
||||
|
||||
Timber.e(e);
|
||||
return;
|
||||
} finally {
|
||||
if (localFolders != null) {
|
||||
for (LocalFolder localFolder : localFolders) {
|
||||
closeFolder(localFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.listFoldersFinished(account);
|
||||
}
|
||||
}
|
||||
|
||||
private void doRefreshRemote(final Account account, final MessagingListener listener) {
|
||||
put("doRefreshRemote", listener, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
refreshRemoteSynchronous(account, listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void refreshRemoteSynchronous(final Account account, final MessagingListener listener) {
|
||||
List<LocalFolder> localFolders = null;
|
||||
public void refreshFolderListSynchronous(Account account) {
|
||||
try {
|
||||
Backend backend = getBackend(account);
|
||||
backend.refreshFolderList();
|
||||
|
||||
LocalStore localStore = localStoreProvider.getInstance(account);
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.listFolders(account, localFolders);
|
||||
}
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.listFoldersFinished(account);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Timber.e(e);
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.listFoldersFailed(account, "");
|
||||
}
|
||||
} finally {
|
||||
if (localFolders != null) {
|
||||
for (LocalFolder localFolder : localFolders) {
|
||||
closeFolder(localFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2380,8 +2286,6 @@ public class MessagingController {
|
|||
} finally {
|
||||
closeFolder(localFolder);
|
||||
}
|
||||
|
||||
listFoldersSynchronous(account, false, listener);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,18 +9,12 @@ import android.content.Context;
|
|||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mailstore.LocalFolder;
|
||||
import com.fsck.k9.mailstore.LocalMessage;
|
||||
|
||||
|
||||
public interface MessagingListener {
|
||||
void accountSizeChanged(Account account, long oldSize, long newSize);
|
||||
|
||||
void listFoldersStarted(Account account);
|
||||
void listFolders(Account account, List<LocalFolder> folders);
|
||||
void listFoldersFinished(Account account);
|
||||
void listFoldersFailed(Account account, String message);
|
||||
|
||||
void listLocalMessagesAddMessages(Account account, String folderServerId, List<LocalMessage> messages);
|
||||
void listLocalMessagesFinished();
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.content.Context;
|
|||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mailstore.LocalFolder;
|
||||
import com.fsck.k9.mailstore.LocalMessage;
|
||||
|
||||
|
||||
|
@ -18,22 +17,6 @@ public abstract class SimpleMessagingListener implements MessagingListener {
|
|||
public void accountSizeChanged(Account account, long oldSize, long newSize) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listFoldersStarted(Account account) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listFolders(Account account, List<LocalFolder> folders) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listFoldersFinished(Account account) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listFoldersFailed(Account account, String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listLocalMessagesAddMessages(Account account, String folderServerId, List<LocalMessage> messages) {
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ import org.mockito.stubbing.Answer;
|
|||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowLog;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
@ -104,8 +103,6 @@ public class MessagingControllerTest extends K9RobolectricTest {
|
|||
@Mock
|
||||
private NotificationStrategy notificationStrategy;
|
||||
@Captor
|
||||
private ArgumentCaptor<List<LocalFolder>> localFolderListCaptor;
|
||||
@Captor
|
||||
private ArgumentCaptor<FetchProfile> fetchProfileCaptor;
|
||||
@Captor
|
||||
private ArgumentCaptor<MessageRetrievalListener<LocalMessage>> messageRetrievalListenerCaptor;
|
||||
|
@ -199,65 +196,9 @@ public class MessagingControllerTest extends K9RobolectricTest {
|
|||
verify(localFolder, atLeastOnce()).close();
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void clearFolderSynchronous_shouldListFolders() throws MessagingException {
|
||||
controller.clearFolderSynchronous(account, FOLDER_NAME, listener);
|
||||
|
||||
verify(listener, atLeastOnce()).listFoldersStarted(account);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listFoldersSynchronous_shouldNotifyTheListenerListingStarted() throws MessagingException {
|
||||
List<LocalFolder> folders = Collections.singletonList(localFolder);
|
||||
when(localStore.getPersonalNamespaces(false)).thenReturn(folders);
|
||||
|
||||
controller.listFoldersSynchronous(account, false, listener);
|
||||
|
||||
verify(listener).listFoldersStarted(account);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listFoldersSynchronous_shouldNotifyTheListenerOfTheListOfFolders() throws MessagingException {
|
||||
List<LocalFolder> folders = Collections.singletonList(localFolder);
|
||||
when(localStore.getPersonalNamespaces(false)).thenReturn(folders);
|
||||
|
||||
controller.listFoldersSynchronous(account, false, listener);
|
||||
|
||||
verify(listener).listFolders(eq(account), localFolderListCaptor.capture());
|
||||
assertEquals(folders, localFolderListCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listFoldersSynchronous_shouldNotifyFailureOnException() throws MessagingException {
|
||||
when(localStore.getPersonalNamespaces(false)).thenThrow(new MessagingException("Test"));
|
||||
|
||||
controller.listFoldersSynchronous(account, true, listener);
|
||||
|
||||
verify(listener).listFoldersFailed(account, "Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listFoldersSynchronous_shouldNotNotifyFinishedAfterFailure() throws MessagingException {
|
||||
when(localStore.getPersonalNamespaces(false)).thenThrow(new MessagingException("Test"));
|
||||
|
||||
controller.listFoldersSynchronous(account, true, listener);
|
||||
|
||||
verify(listener, never()).listFoldersFinished(account);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listFoldersSynchronous_shouldNotifyFinishedAfterSuccess() throws MessagingException {
|
||||
List<LocalFolder> folders = Collections.singletonList(localFolder);
|
||||
when(localStore.getPersonalNamespaces(false)).thenReturn(folders);
|
||||
|
||||
controller.listFoldersSynchronous(account, false, listener);
|
||||
|
||||
verify(listener).listFoldersFinished(account);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshRemoteSynchronous_shouldCallBackend() throws MessagingException {
|
||||
controller.refreshRemoteSynchronous(account, listener);
|
||||
controller.refreshFolderListSynchronous(account);
|
||||
|
||||
verify(backend).refreshFolderList();
|
||||
}
|
||||
|
|
|
@ -503,7 +503,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
|||
if (isWebDavAccount()) {
|
||||
publishProgress(R.string.account_setup_check_settings_fetch);
|
||||
}
|
||||
MessagingController.getInstance(getApplication()).listFoldersSynchronous(account, true, null);
|
||||
MessagingController.getInstance(getApplication()).refreshFolderListSynchronous(account);
|
||||
MessagingController.getInstance(getApplication())
|
||||
.synchronizeMailbox(account, account.getInboxFolder(), null);
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ class ChooseFolderActivity : K9Activity() {
|
|||
}
|
||||
|
||||
private fun refreshFolderList() {
|
||||
messagingController.listFolders(account, true, null)
|
||||
messagingController.refreshFolderList(account)
|
||||
}
|
||||
|
||||
private fun setDisplayMode(displayMode: FolderMode) {
|
||||
|
|
|
@ -187,7 +187,7 @@ class ManageFoldersActivity : K9Activity() {
|
|||
}
|
||||
|
||||
private fun refreshFolderList() {
|
||||
messagingController.listFolders(account, true, messagingListener)
|
||||
messagingController.refreshFolderList(account)
|
||||
}
|
||||
|
||||
private fun compactAccount() {
|
||||
|
|
|
@ -25,7 +25,7 @@ class AccountActivator(
|
|||
Core.setServicesEnabled(context)
|
||||
|
||||
// Get list of folders from remote server
|
||||
messagingController.listFolders(account, true, null)
|
||||
messagingController.refreshFolderList(account)
|
||||
}
|
||||
|
||||
private fun setAccountPasswords(
|
||||
|
|
Loading…
Reference in a new issue