1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-13 06:38:05 -05:00

Exit action mode when a message list item context menu is displayed

This commit is contained in:
cketti 2012-09-18 04:05:13 +02:00
parent 0334ba88c5
commit de59725743

View File

@ -1464,7 +1464,7 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
return true; return true;
} }
case R.id.select_all: { case R.id.select_all: {
toggleAllSelected(); setSelectionState(true);
return true; return true;
} }
case R.id.app_settings: { case R.id.app_settings: {
@ -1980,7 +1980,9 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
private final OnClickListener itemMenuClickListener = new OnClickListener() { private final OnClickListener itemMenuClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// Perform action on clicks // Deselect all messages
setSelectionState(false);
final MessageInfoHolder message = (MessageInfoHolder) getItem((Integer)v.getTag()); final MessageInfoHolder message = (MessageInfoHolder) getItem((Integer)v.getTag());
final MenuBuilder menu = new MenuBuilder(MessageList.this); final MenuBuilder menu = new MenuBuilder(MessageList.this);
getSupportMenuInflater().inflate(R.menu.message_list_item_context, menu); getSupportMenuInflater().inflate(R.menu.message_list_item_context, menu);
@ -2407,20 +2409,16 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
} }
/** /**
* Toggle all selected message states. Sort of. If anything selected, unselect everything. If nothing is * Set selection state for all messages.
* selected, select everything. *
* @param selected
* If {@code true} all messages get selected. Otherwise, all messages get deselected and
* action mode is finished.
*/ */
private void toggleAllSelected() { private void setSelectionState(boolean selected) {
boolean newState = true; mAdapter.setSelectionForAllMesages(selected);
// If there was anything selected, unselect everything. if (selected) {
if (mSelectedCount > 0) {
newState = false;
}
mAdapter.setSelectionForAllMesages(newState);
if (newState) {
mSelectedCount = mAdapter.getCount(); mSelectedCount = mAdapter.getCount();
mActionMode = MessageList.this.startActionMode(mActionModeCallback); mActionMode = MessageList.this.startActionMode(mActionModeCallback);
updateActionModeTitle(); updateActionModeTitle();
@ -2428,7 +2426,9 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
computeBatchDirection(); computeBatchDirection();
} else { } else {
mSelectedCount = 0; mSelectedCount = 0;
mActionMode.finish(); if (mActionMode != null) {
mActionMode.finish();
}
} }
} }