Remove a layer of callback in inbox finder.

I'm changing it so that inbox finding happens at an earlier stage so
that the UIController.open() methods can be simpler. Specifically: I
want them to just always accept a mailbox, and not have to deal with an
intermediate state where it's still looking for a mailbox.

Change-Id: I1c5be783859a3bee7e46007e778de13eb1685cbe
This commit is contained in:
Ben Komalo 2011-06-17 17:01:54 -07:00
parent facd131fad
commit 99401ebea7
4 changed files with 30 additions and 121 deletions

View File

@ -231,9 +231,11 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
mUIController.open(accountId, searchMailboxId, Message.NO_MESSAGE);
} else {
final long messageId = intent.getLongExtra(EXTRA_MESSAGE_ID, Message.NO_MESSAGE);
if (accountId != Account.NO_ACCOUNT) {
if (mailboxId != Mailbox.NO_MAILBOX) {
final long messageId = intent.getLongExtra(EXTRA_MESSAGE_ID, Message.NO_MESSAGE);
mUIController.open(accountId, mailboxId, messageId);
} else {
mUIController.switchAccount(accountId);
}
}
}

View File

@ -29,6 +29,7 @@ import android.view.MenuItem;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.RefreshManager;
import com.android.email.activity.setup.AccountSecurity;
import com.android.email.activity.setup.AccountSettings;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
@ -454,14 +455,13 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
// Do nothing if the account is already selected. Not even going back to the inbox.
return;
}
openAccount(accountId);
}
/**
* Shortcut for {@link #open} with {@link Mailbox#NO_MAILBOX} and {@link Message#NO_MESSAGE}.
*/
protected final void openAccount(long accountId) {
open(accountId, Mailbox.NO_MAILBOX, Message.NO_MESSAGE);
if (accountId == Account.ACCOUNT_ID_COMBINED_VIEW) {
open(accountId, Mailbox.QUERY_ALL_INBOXES, Message.NO_MESSAGE);
} else {
// For a normal account, just open the inbox. Unfortunately, we have to look it up first
startInboxLookup(accountId);
}
}
/**
@ -477,8 +477,8 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
*
* @param accountId ID of the account to load. Can be {@link Account#ACCOUNT_ID_COMBINED_VIEW}.
* Must never be {@link Account#NO_ACCOUNT}.
* @param mailboxId ID of the mailbox to load. If {@link Mailbox#NO_MAILBOX},
* load the account's inbox.
* @param mailboxId ID of the mailbox to load. Must always be specified and cannot be
* {@link Mailbox#NO_MAILBOX}
* @param messageId ID of the message to load. If {@link Message#NO_MESSAGE},
* do not open a message.
*/
@ -507,11 +507,6 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
mActionBarController.enterSearchMode(null);
}
/**
* Callback called when the inbox lookup (started by {@link #startInboxLookup}) is finished.
*/
protected abstract MailboxFinder.Callback getInboxLookupCallback();
private final MailboxFinder.Callback mMailboxFinderCallback = new MailboxFinder.Callback() {
private void cleanUp() {
mInboxFinder = null;
@ -519,25 +514,28 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
@Override
public void onAccountNotFound() {
getInboxLookupCallback().onAccountNotFound();
// Account removed?
Welcome.actionStart(mActivity);
cleanUp();
}
@Override
public void onAccountSecurityHold(long accountId) {
getInboxLookupCallback().onAccountSecurityHold(accountId);
mActivity.startActivity(
AccountSecurity.actionUpdateSecurityIntent(mActivity, accountId, true));
cleanUp();
}
@Override
public void onMailboxFound(long accountId, long mailboxId) {
getInboxLookupCallback().onMailboxFound(accountId, mailboxId);
openMailbox(accountId, mailboxId);
cleanUp();
}
@Override
public void onMailboxNotFound(long accountId) {
getInboxLookupCallback().onMailboxNotFound(accountId);
// Inbox not found.
Welcome.actionStart(mActivity);
cleanUp();
}
};
@ -545,7 +543,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
/**
* Start inbox lookup.
*/
protected void startInboxLookup(long accountId) {
private void startInboxLookup(long accountId) {
if (mInboxFinder != null) {
return; // already running
}
@ -562,7 +560,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
/**
* Stop inbox lookup.
*/
protected void stopInboxLookup() {
private void stopInboxLookup() {
if (mInboxFinder == null) {
return; // not running
}

View File

@ -24,8 +24,6 @@ import android.util.Log;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.activity.MailboxFinder.Callback;
import com.android.email.activity.setup.AccountSecurity;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent.Message;
@ -370,37 +368,6 @@ class UIControllerOnePane extends UIControllerBase {
return Message.NO_MESSAGE;
}
private final MailboxFinder.Callback mInboxLookupCallback = new MailboxFinder.Callback() {
@Override
public void onMailboxFound(long accountId, long mailboxId) {
// Inbox found.
openMailbox(accountId, mailboxId);
}
@Override
public void onAccountNotFound() {
// Account removed?
Welcome.actionStart(mActivity);
}
@Override
public void onMailboxNotFound(long accountId) {
// Inbox not found??
Welcome.actionStart(mActivity);
}
@Override
public void onAccountSecurityHold(long accountId) {
mActivity.startActivity(AccountSecurity.actionUpdateSecurityIntent(mActivity, accountId,
true));
}
};
@Override
protected Callback getInboxLookupCallback() {
return mInboxLookupCallback;
}
@Override
public boolean onBackPressed(boolean isSystemBackKey) {
if (Email.DEBUG) {
@ -461,15 +428,12 @@ class UIControllerOnePane extends UIControllerBase {
final boolean accountChanging = (getUIAccountId() != accountId);
if (messageId != Message.NO_MESSAGE) {
showMessageView(accountId, mailboxId, messageId, accountChanging);
} else if (mailboxId != Mailbox.NO_MAILBOX) {
showMessageList(accountId, mailboxId, accountChanging);
} else {
// Mailbox not specified. Open Inbox or Combined Inbox.
if (accountId == Account.ACCOUNT_ID_COMBINED_VIEW) {
showMessageList(accountId, Mailbox.QUERY_ALL_INBOXES, accountChanging);
} else {
startInboxLookup(accountId);
if (mailboxId == Mailbox.NO_MAILBOX) {
Log.e(Logging.LOG_TAG, this + " unspecified mailbox.");
return;
}
showMessageList(accountId, mailboxId, accountChanging);
}
}

View File

@ -28,8 +28,6 @@ import com.android.email.Email;
import com.android.email.Preferences;
import com.android.email.R;
import com.android.email.RefreshManager;
import com.android.email.activity.MailboxFinder.Callback;
import com.android.email.activity.setup.AccountSecurity;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent.Message;
@ -46,7 +44,6 @@ import java.util.Set;
* so that we can easily switch between synchronous and asynchronous transactions.
*/
class UIControllerTwoPane extends UIControllerBase implements
MailboxFinder.Callback,
ThreePaneLayout.Callback,
MailboxListFragment.Callback,
MessageListFragment.Callback,
@ -89,43 +86,6 @@ class UIControllerTwoPane extends UIControllerBase implements
return R.layout.email_activity_two_pane;
}
// MailboxFinder$Callback
@Override
public void onAccountNotFound() {
if (Logging.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, this + " onAccountNotFound()");
}
// Shouldn't happen
}
// MailboxFinder$Callback
@Override
public void onAccountSecurityHold(long accountId) {
if (Logging.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, this + " onAccountSecurityHold()");
}
mActivity.startActivity(AccountSecurity.actionUpdateSecurityIntent(mActivity, accountId,
true));
}
// MailboxFinder$Callback
@Override
public void onMailboxFound(long accountId, long mailboxId) {
if (Logging.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, this + " onMailboxFound()");
}
updateMessageList(accountId, mailboxId, true);
}
// MailboxFinder$Callback
@Override
public void onMailboxNotFound(long accountId) {
if (Logging.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, this + " onMailboxNotFound()");
}
Log.e(Logging.LOG_TAG, "unable to find mailbox for account " + accountId);
}
// ThreePaneLayoutCallback
@Override
public void onVisiblePanesChanged(int previousVisiblePanes) {
@ -491,11 +451,6 @@ class UIControllerTwoPane extends UIControllerBase implements
super.onRestoreInstanceState(savedInstanceState);
}
@Override
protected Callback getInboxLookupCallback() {
return this;
}
@Override
protected void installMessageListFragment(MessageListFragment fragment) {
super.installMessageListFragment(fragment);
@ -543,18 +498,6 @@ class UIControllerTwoPane extends UIControllerBase implements
final FragmentTransaction ft = mFragmentManager.beginTransaction();
if (accountId == Account.NO_ACCOUNT) {
throw new IllegalArgumentException();
} else if (mailboxId == Mailbox.NO_MAILBOX) {
updateMailboxList(ft, accountId, Mailbox.NO_MAILBOX, true);
// Show the appropriate message list
if (accountId == Account.ACCOUNT_ID_COMBINED_VIEW) {
// When opening the Combined view, the right pane will be "combined inbox".
updateMessageList(ft, accountId, Mailbox.QUERY_ALL_INBOXES, true);
} else {
// Try to find the inbox for the account
startInboxLookup(accountId);
}
mThreePane.showLeftPane();
} else if (messageId == Message.NO_MESSAGE) {
updateMailboxList(ft, accountId, mailboxId, true);
updateMessageList(ft, accountId, mailboxId, true);
@ -567,6 +510,10 @@ class UIControllerTwoPane extends UIControllerBase implements
mThreePane.showLeftPane();
}
} else {
if (mailboxId == Mailbox.NO_MAILBOX) {
Log.e(Logging.LOG_TAG, this + " unspecified mailbox ");
return;
}
updateMailboxList(ft, accountId, mailboxId, true);
updateMessageList(ft, accountId, mailboxId, true);
updateMessageView(ft, messageId);
@ -647,8 +594,6 @@ class UIControllerTwoPane extends UIControllerBase implements
throw new IllegalArgumentException();
}
stopInboxLookup();
if (mailboxId != getMessageListMailboxId()) {
removeMessageListFragment(ft);
ft.add(mThreePane.getMiddlePaneId(), MessageListFragment.newInstance(