Remove "Move" action on POP.

Bug: 5010614
Change-Id: If0a94840e9dc104566ba39d2e3240883dab5bba0
This commit is contained in:
Ben Komalo 2011-07-20 13:03:54 -07:00
parent 6496562610
commit 81a153463b
7 changed files with 61 additions and 56 deletions

View File

@ -453,11 +453,8 @@ public final class Account extends EmailContent implements AccountColumns, Parce
return "eas".equals(getProtocol(context));
}
/**
* @return true if the account supports "move messages".
*/
public static boolean supportsMoveMessages(Context context, long accountId) {
String protocol = getProtocol(context, accountId);
public boolean supportsMoveMessages(Context context) {
String protocol = getProtocol(context);
return "eas".equals(protocol) || "imap".equals(protocol);
}
@ -479,15 +476,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
mIsDefault = newDefaultState;
}
/**
* Helper method for finding the default account.
*/
static private long getDefaultAccountWhere(Context context, String where) {
return Utility.getFirstRowLong(context, CONTENT_URI,
DEFAULT_ID_PROJECTION,
where, null, null, 0, Long.valueOf(-1));
}
/**
* @return {@link Uri} to this {@link Account} in the
* {@code content://com.android.email.provider/account/UUID} format, which is safe to use

View File

@ -454,22 +454,10 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
}
/**
* @param mailboxId ID of a mailbox. This method DOES NOT accept magic mailbox IDs, such as
* {@link #QUERY_ALL_INBOXES} (because only the actual mailbox ID matters here. e.g.
* {@link #QUERY_ALL_FAVORITES} can contain ANY kind of messages), so don't pass a negative
* value.
* @return true if messages in a mailbox can be moved to another mailbox.
* This method only checks the mailbox information. It doesn't check its account/protocol,
* so it may return true even for POP3 mailbox.
* @return whether or not this mailbox supports moving messages out of it
*/
public static boolean canMoveFrom(Context context, long mailboxId) {
if (mailboxId < 0) {
throw new IllegalArgumentException();
}
Uri url = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId);
int type = Utility.getFirstRowInt(context, url, MAILBOX_TYPE_PROJECTION,
null, null, null, MAILBOX_TYPE_TYPE_COLUMN);
switch (type) {
public boolean canHaveMessagesMoved() {
switch (mType) {
case TYPE_INBOX:
case TYPE_MAIL:
case TYPE_TRASH:

View File

@ -128,8 +128,8 @@ public class MessageListFragment extends ListFragment
// Misc members
/** Whether "Send all messages" should be shown. */
private boolean mShowSendCommand;
private boolean mShowMoveCommand;
/**
* If true, we disable the CAB even if there are selected messages.
@ -706,7 +706,7 @@ public class MessageListFragment extends ListFragment
final long mailboxId = getMailboxId();
if (mAccount == null || mMailbox == null) {
return false;
} else if (mailboxId > 0 && !Mailbox.canMoveFrom(mActivity, mailboxId)) {
} else if (mailboxId > 0 && !mMailbox.canHaveMessagesMoved()) {
return false;
}
// Start drag&drop.
@ -1127,10 +1127,16 @@ public class MessageListFragment extends ListFragment
}
}
private void showSendCommandIfNecessary() {
private void updateMailboxSpecificActions() {
final boolean isOutbox = (getMailboxId() == Mailbox.QUERY_ALL_OUTBOX)
|| ((mMailbox != null) && (mMailbox.mType == Mailbox.TYPE_OUTBOX));
showSendCommand(isOutbox && (mListAdapter != null) && (mListAdapter.getCount() > 0));
// A null account/mailbox means we're in a combined view. We show the move icon there,
// even though it may be the case that we can't move messages from one of the mailboxes.
// There's no good way to tell that right now, though.
mShowMoveCommand = (mAccount == null || mAccount.supportsMoveMessages(getActivity()))
&& (mMailbox == null || mMailbox.canHaveMessagesMoved());
}
private void showNoMessageText(boolean visible) {
@ -1233,7 +1239,7 @@ public class MessageListFragment extends ListFragment
mListAdapter.setQuery(null);
mSearchedMailbox = null;
}
showSendCommandIfNecessary();
updateMailboxSpecificActions();
// Show chips if combined view.
mListAdapter.setShowColorChips(isCombinedMailbox() && mCountTotalAccounts > 1);
@ -1319,6 +1325,7 @@ public class MessageListFragment extends ListFragment
private MenuItem mMarkUnread;
private MenuItem mAddStar;
private MenuItem mRemoveStar;
private MenuItem mMove;
/* package */ boolean mClosedByUser = true;
@ -1332,6 +1339,7 @@ public class MessageListFragment extends ListFragment
mMarkUnread = menu.findItem(R.id.mark_unread);
mAddStar = menu.findItem(R.id.add_star);
mRemoveStar = menu.findItem(R.id.remove_star);
mMove = menu.findItem(R.id.move);
return true;
}
@ -1349,6 +1357,7 @@ public class MessageListFragment extends ListFragment
mMarkUnread.setVisible(readExists);
mAddStar.setVisible(nonStarExists);
mRemoveStar.setVisible(!nonStarExists);
mMove.setVisible(mShowMoveCommand);
return true;
}

View File

@ -20,6 +20,7 @@ import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -37,6 +38,7 @@ import com.android.email.Email;
import com.android.email.R;
import com.android.emailcommon.mail.MeetingInfo;
import com.android.emailcommon.mail.PackedString;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.service.EmailServiceConstants;
@ -63,7 +65,6 @@ public class MessageViewFragment extends MessageViewFragmentBase
/* Nullable - not available on phone. */
private View mForwardButton;
private View mMoreButton;
// calendar meeting invite answers
@ -73,6 +74,9 @@ public class MessageViewFragment extends MessageViewFragmentBase
private Drawable mFavoriteIconOn;
private Drawable mFavoriteIconOff;
/** Whether or not the message can be moved from the mailbox it's in. */
private boolean mSupportsMove;
private int mPreviousMeetingResponse = EmailServiceConstants.MEETING_REQUEST_NOT_RESPONDED;
/**
@ -219,6 +223,11 @@ public class MessageViewFragment extends MessageViewFragmentBase
inflater.inflate(R.menu.message_view_fragment_option, menu);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.move).setVisible(mSupportsMove);
}
private void enableReplyForwardButtons(boolean enabled) {
// We don't have disabled button assets, so let's hide them for now
final int visibility = enabled ? View.VISIBLE : View.GONE;
@ -252,11 +261,22 @@ public class MessageViewFragment extends MessageViewFragmentBase
}
@Override
protected void onMessageShown(long messageId, int mailboxType) {
super.onMessageShown(messageId, mailboxType);
protected void onMessageShown(long messageId, Mailbox mailbox) {
super.onMessageShown(messageId, mailbox);
Account account = Account.restoreAccountWithId(mContext, getAccountId());
boolean supportsMove = account.supportsMoveMessages(mContext)
&& mailbox.canHaveMessagesMoved();
if (mSupportsMove != supportsMove) {
mSupportsMove = supportsMove;
Activity host = getActivity();
if (host != null) {
host.invalidateOptionsMenu();
}
}
// Disable forward/reply buttons as necessary.
enableReplyForwardButtons(Mailbox.isMailboxTypeReplyAndForwardable(mailboxType));
enableReplyForwardButtons(Mailbox.isMailboxTypeReplyAndForwardable(mailbox.mType));
}
/**

View File

@ -1041,7 +1041,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
private class LoadMessageTask extends EmailAsyncTask<Void, Void, Message> {
private final boolean mOkToFetch;
private int mMailboxType;
private Mailbox mMailbox;
/**
* Special constructor to cache some local info
@ -1059,8 +1059,8 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
message = openMessageSync(activity);
}
if (message != null) {
mMailboxType = Mailbox.getMailboxType(mContext, message.mMailboxKey);
if (mMailboxType == Mailbox.NO_MAILBOX) {
mMailbox = Mailbox.restoreMailboxWithId(mContext, message.mMailboxKey);
if (mMailbox == null) {
message = null; // mailbox removed??
}
}
@ -1078,7 +1078,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
reloadUiFromMessage(message, mOkToFetch);
queryContactStatus();
onMessageShown(mMessageId, mMailboxType);
onMessageShown(mMessageId, mMailbox);
RecentMailboxManager.getInstance(mContext).touch(mAccountId, message.mMailboxKey);
}
}
@ -1116,7 +1116,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
/**
* Called when a message is shown to the user.
*/
protected void onMessageShown(long messageId, int mailboxType) {
protected void onMessageShown(long messageId, Mailbox mailbox) {
}
/**

View File

@ -16,14 +16,6 @@
package com.android.email.activity;
import com.android.email.Email;
import com.android.email.R;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.utility.Utility;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -39,6 +31,14 @@ import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import com.android.email.Email;
import com.android.email.R;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.utility.Utility;
/**
* "Move (messages) to" dialog.
*
@ -242,7 +242,7 @@ public class MoveMessageToDialog extends DialogFragment implements DialogInterfa
if (accountId == Account.NO_ACCOUNT) {
// First, check if the account supports move
accountId = message.mAccountKey;
if (!Account.supportsMoveMessages(c, accountId)) {
if (!Account.restoreAccountWithId(c, accountId).supportsMoveMessages(c)) {
Utility.showToast(
mActivity, R.string.cannot_move_protocol_not_supported_toast);
accountId = Account.NO_ACCOUNT;
@ -250,7 +250,7 @@ public class MoveMessageToDialog extends DialogFragment implements DialogInterfa
}
mailboxId = message.mMailboxKey;
// Second, check if the mailbox supports move
if (!Mailbox.canMoveFrom(c, mailboxId)) {
if (!Mailbox.restoreMailboxWithId(c, mailboxId).canHaveMessagesMoved()) {
Utility.showToast(mActivity, R.string.cannot_move_special_mailboxes_toast);
accountId = Account.NO_ACCOUNT;
mailboxId = Mailbox.NO_MAILBOX;

View File

@ -196,10 +196,10 @@ public class MailboxTests extends ProviderTestCase2<EmailProvider> {
Mailbox bd = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_DRAFTS);
Mailbox bo = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_OUTBOX);
assertTrue(Mailbox.canMoveFrom(c, bi.mId));
assertTrue(Mailbox.canMoveFrom(c, bm.mId));
assertFalse(Mailbox.canMoveFrom(c, bd.mId));
assertFalse(Mailbox.canMoveFrom(c, bo.mId));
assertTrue(bi.canHaveMessagesMoved());
assertTrue(bm.canHaveMessagesMoved());
assertFalse(bd.canHaveMessagesMoved());
assertFalse(bo.canHaveMessagesMoved());
}
public void testGetMailboxForMessageId() {