Merge "Hide sync options and search icon when appropriate"

This commit is contained in:
Ben Komalo 2011-08-07 15:44:30 -07:00 committed by Android (Google) Code Review
commit 03cb4a2135
3 changed files with 44 additions and 16 deletions

View File

@ -470,6 +470,31 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
return false; // TYPE_DRAFTS, TYPE_OUTBOX, TYPE_SENT, etc
}
/**
* @return whether or not this mailbox retrieves its data from the server (as opposed to just
* a local mailbox that is never synced).
*/
public boolean loadsFromServer(String protocol) {
if (HostAuth.SCHEME_EAS.equals(protocol)) {
return mType != Mailbox.TYPE_DRAFTS
&& mType != Mailbox.TYPE_OUTBOX
&& mType != Mailbox.TYPE_SEARCH
&& mType < Mailbox.TYPE_NOT_SYNCABLE;
} else if (HostAuth.SCHEME_IMAP.equals(protocol)) {
// TODO: actually use a sync flag when creating the mailboxes. Right now we use an
// approximation for IMAP.
return mType != Mailbox.TYPE_DRAFTS
&& mType != Mailbox.TYPE_OUTBOX
&& mType != Mailbox.TYPE_SEARCH;
} else if (HostAuth.SCHEME_POP3.equals(protocol)) {
return TYPE_INBOX == mType;
}
return false;
}
/**
* @return true if messages in a mailbox of a type can be replied/forwarded.
*/

View File

@ -1155,6 +1155,9 @@ public class MessageListFragment extends ListFragment
// There's no good way to tell that right now, though.
mShowMoveCommand = (mAccount == null || mAccount.supportsMoveMessages(getActivity()))
&& (mMailbox == null || mMailbox.canHaveMessagesMoved());
// Enable mailbox specific actions on the UIController level if needed.
mActivity.invalidateOptionsMenu();
}
/**

View File

@ -97,7 +97,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
* The NfcHandler implements Near Field Communication sharing features
* whenever the activity is in the foreground.
*/
private NfcHandler mNfcHandler;
private final NfcHandler mNfcHandler;
/**
* The active context for the current MessageList.
@ -772,26 +772,26 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
}
// Deal with protocol-specific menu options.
boolean isEas = false;
boolean mailboxHasServerCounterpart = false;
boolean accountSearchable = false;
long accountId = getActualAccountId();
if (accountId > 0) {
Account account = Account.restoreAccountWithId(mActivity, accountId);
if (account != null) {
String protocol = account.getProtocol(mActivity);
if (HostAuth.SCHEME_EAS.equals(protocol)) {
isEas = true;
boolean isEas = false;
if (isMessageListReady()) {
long accountId = getActualAccountId();
if (accountId > 0) {
Account account = Account.restoreAccountWithId(mActivity, accountId);
if (account != null) {
String protocol = account.getProtocol(mActivity);
isEas = HostAuth.SCHEME_EAS.equals(protocol);
Mailbox mailbox = getMessageListFragment().getMailbox();
mailboxHasServerCounterpart = mailbox.loadsFromServer(protocol);
accountSearchable = (account.mFlags & Account.FLAGS_SUPPORTS_SEARCH) != 0;
}
accountSearchable = (account.mFlags & Account.FLAGS_SUPPORTS_SEARCH) != 0;
}
}
// TODO: Should use an isSyncable call to prevent drafts/outbox from allowing this
menu.findItem(R.id.search).setVisible(accountSearchable);
// TODO Show only for syncable mailbox as well.
menu.findItem(R.id.mailbox_settings).setVisible(isEas
&& (getMailboxSettingsMailboxId() != Mailbox.NO_MAILBOX));
menu.findItem(R.id.search).setVisible(accountSearchable && mailboxHasServerCounterpart);
menu.findItem(R.id.mailbox_settings).setVisible(isEas && mailboxHasServerCounterpart);
return true;
}