Apply auto-advance policy when doing a batch op.

Batch operations that occur when the current message selection is
contained within the affected messages will now force the selection to
advance according to the auto advance policy to the next unselected
conversation.

Bug: 3409809
Bug: 3405864
Change-Id: Ibe75f32b9263ef6f3fb2314a07e63980f437f988
This commit is contained in:
Ben Komalo 2011-04-13 11:30:56 -07:00
parent ead17de8f2
commit 52618afa81
4 changed files with 79 additions and 17 deletions

View File

@ -49,7 +49,7 @@ public class Preferences {
public static final int AUTO_ADVANCE_OLDER = 1;
public static final int AUTO_ADVANCE_MESSAGE_LIST = 2;
// "move to older" was the behavior on older versions.
public static final int AUTO_ADVANCE_DEFAULT = AUTO_ADVANCE_OLDER;
private static final int AUTO_ADVANCE_DEFAULT = AUTO_ADVANCE_OLDER;
// The following constants are used as offsets into TEXT_ZOOM_ARRAY (below)
public static final int TEXT_ZOOM_TINY = 0;

View File

@ -16,7 +16,6 @@
package com.android.email.activity;
import com.android.email.Controller;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.RefreshManager;
@ -37,6 +36,8 @@ import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import java.util.Set;
public class MessageList extends Activity implements MessageListFragment.Callback {
// Intent extras (internal to this activity)
private static final String EXTRA_ACCOUNT_ID = "com.android.email.activity._ACCOUNT_ID";
@ -203,6 +204,11 @@ public class MessageList extends Activity implements MessageListFragment.Callbac
public void onEnterSelectionMode(boolean enter) {
}
@Override
public void onAdvancingOpAccepted(Set<Long> affectedMessages) {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.message_list_option, menu);

View File

@ -197,6 +197,13 @@ public class MessageListFragment extends ListFragment
* @param enter true if entering, false if leaving
*/
public void onEnterSelectionMode(boolean enter);
/**
* Called when an operation is initiated that can potentially advance the current
* message selection (e.g. a delete operation may advance the selection).
* @param affectedMessages the messages the operation will apply to
*/
public void onAdvancingOpAccepted(Set<Long> affectedMessages);
}
private static final class EmptyCallback implements Callback {
@ -216,6 +223,10 @@ public class MessageListFragment extends ListFragment
@Override
public void onEnterSelectionMode(boolean enter) {
}
@Override
public void onAdvancingOpAccepted(Set<Long> affectedMessages) {
}
}
@Override
@ -460,9 +471,9 @@ public class MessageListFragment extends ListFragment
}
/**
* @return the number of messages that are currently selecteed.
* @return the number of messages that are currently selected.
*/
public int getSelectedCount() {
private int getSelectedCount() {
return mListAdapter.getSelectedSet().size();
}
@ -1314,17 +1325,25 @@ public class MessageListFragment extends ListFragment
Set<Long> selectedConversations = mListAdapter.getSelectedSet();
switch (item.getItemId()) {
case R.id.mark_read:
// Note - marking as read does not trigger auto-advance.
toggleRead(selectedConversations);
break;
case R.id.mark_unread:
mCallback.onAdvancingOpAccepted(selectedConversations);
toggleRead(selectedConversations);
break;
case R.id.add_star:
case R.id.remove_star:
// TODO: removing a star can be a destructive command and cause auto-advance
// if the current mailbox shown is favorites.
toggleFavorite(selectedConversations);
break;
case R.id.delete:
mCallback.onAdvancingOpAccepted(selectedConversations);
deleteMessages(selectedConversations);
break;
case R.id.move:
mCallback.onAdvancingOpAccepted(selectedConversations);
moveMessages(selectedConversations);
break;
}

View File

@ -31,6 +31,7 @@ import android.util.Log;
import android.view.View;
import java.security.InvalidParameterException;
import java.util.Set;
/**
* A class manages what are showing on {@link MessageListXL} (i.e. account id, mailbox id, and
@ -217,10 +218,48 @@ class MessageListXLFragmentManager implements
public void onEnterSelectionMode(boolean enter) {
}
/**
* Apply the auto-advance policy upon initation of a batch command that could potentially
* affect the currently selected conversation.
*/
@Override
public void onAdvancingOpAccepted(Set<Long> affectedMessages) {
int autoAdvanceDir = Preferences.getPreferences(mActivity).getAutoAdvanceDirection();
if ((autoAdvanceDir == Preferences.AUTO_ADVANCE_MESSAGE_LIST) || (mOrderManager == null)) {
if (affectedMessages.contains(getMessageId())) {
goBackToMailbox();
}
return;
}
// Navigate to the first unselected item in the appropriate direction.
switch (autoAdvanceDir) {
case Preferences.AUTO_ADVANCE_NEWER:
while (affectedMessages.contains(mOrderManager.getCurrentMessageId())) {
if (!mOrderManager.moveToNewer()) {
goBackToMailbox();
return;
}
}
selectMessage(mOrderManager.getCurrentMessageId());
break;
case Preferences.AUTO_ADVANCE_OLDER:
while (affectedMessages.contains(mOrderManager.getCurrentMessageId())) {
if (!mOrderManager.moveToOlder()) {
goBackToMailbox();
return;
}
}
selectMessage(mOrderManager.getCurrentMessageId());
break;
}
}
@Override
public void onListLoaded() {
}
// MessageViewFragment$Callback
@Override
public void onMessageViewShown(int mailboxType) {
@ -600,24 +639,24 @@ class MessageListXLFragmentManager implements
private class CommandButtonCallback implements MessageCommandButtonView.Callback {
@Override
public void onMoveToNewer() {
MessageListXLFragmentManager.this.onMoveToNewer();
moveToNewer();
}
@Override
public void onMoveToOlder() {
MessageListXLFragmentManager.this.onMoveToOlder();
moveToOlder();
}
}
private void onCurrentMessageGone() {
switch (Preferences.getPreferences(mActivity).getAutoAdvanceDirection()) {
case Preferences.AUTO_ADVANCE_NEWER:
if (onMoveToNewer()) return;
if (onMoveToOlder()) return;
if (moveToNewer()) return;
if (moveToOlder()) return;
break;
case Preferences.AUTO_ADVANCE_OLDER:
if (onMoveToOlder()) return;
if (onMoveToNewer()) return;
if (moveToOlder()) return;
if (moveToNewer()) return;
break;
}
// Last message in the box or AUTO_ADVANCE_MESSAGE_LIST. Go back to message list.
@ -680,18 +719,16 @@ class MessageListXLFragmentManager implements
}
}
private boolean onMoveToOlder() {
if (isMessageSelected() && (mOrderManager != null)
&& mOrderManager.moveToOlder()) {
private boolean moveToOlder() {
if ((mOrderManager != null) && mOrderManager.moveToOlder()) {
selectMessage(mOrderManager.getCurrentMessageId());
return true;
}
return false;
}
private boolean onMoveToNewer() {
if (isMessageSelected() && (mOrderManager != null)
&& mOrderManager.moveToNewer()) {
private boolean moveToNewer() {
if ((mOrderManager != null) && mOrderManager.moveToNewer()) {
selectMessage(mOrderManager.getCurrentMessageId());
return true;
}