Don't show context menu when long-pressing message list item
This commit is contained in:
parent
857aab3182
commit
fa45a11858
2 changed files with 0 additions and 241 deletions
|
@ -1251,46 +1251,21 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResendMessage(MessageReference messageReference) {
|
||||
MessageActions.actionEditDraft(this, messageReference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForward(MessageReference messageReference) {
|
||||
onForward(messageReference, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForward(MessageReference messageReference, Parcelable decryptionResultForReply) {
|
||||
MessageActions.actionForward(this, messageReference, decryptionResultForReply);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForwardAsAttachment(MessageReference messageReference) {
|
||||
onForwardAsAttachment(messageReference, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForwardAsAttachment(MessageReference messageReference, Parcelable decryptionResultForReply) {
|
||||
MessageActions.actionForwardAsAttachment(this, messageReference, decryptionResultForReply);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReply(MessageReference messageReference) {
|
||||
onReply(messageReference, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReply(MessageReference messageReference, Parcelable decryptionResultForReply) {
|
||||
MessageActions.actionReply(this, messageReference, false, decryptionResultForReply);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplyAll(MessageReference messageReference) {
|
||||
onReplyAll(messageReference, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplyAll(MessageReference messageReference, Parcelable decryptionResultForReply) {
|
||||
MessageActions.actionReply(this, messageReference, true, decryptionResultForReply);
|
||||
|
@ -1301,18 +1276,6 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
|
|||
MessageActions.actionCompose(this, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMoreFromSameSender(String senderAddress) {
|
||||
LocalSearch tmpSearch = new LocalSearch(getString(R.string.search_from_format, senderAddress));
|
||||
tmpSearch.addAccountUuids(search.getAccountUuids());
|
||||
tmpSearch.and(SearchField.SENDER, senderAddress, Attribute.CONTAINS);
|
||||
|
||||
initializeFromLocalSearch(tmpSearch);
|
||||
|
||||
MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false, false);
|
||||
addMessageListFragment(fragment, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackStackChanged() {
|
||||
findFragments();
|
||||
|
|
|
@ -20,8 +20,6 @@ import android.graphics.Rect;
|
|||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -30,7 +28,6 @@ import android.view.MotionEvent;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
@ -171,17 +168,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
private LocalBroadcastManager localBroadcastManager;
|
||||
private BroadcastReceiver cacheBroadcastReceiver;
|
||||
private IntentFilter cacheIntentFilter;
|
||||
/**
|
||||
* Stores the unique ID of the message the context menu was opened for.
|
||||
*
|
||||
* We have to save this because the message list might change between the time the menu was
|
||||
* opened and when the user clicks on a menu item. When this happens the 'adapter position' that
|
||||
* is accessible via the {@code ContextMenu} object might correspond to another list item and we
|
||||
* would end up using/modifying the wrong message.
|
||||
*
|
||||
* The value of this field is {@code 0} when no context menu is currently open.
|
||||
*/
|
||||
private long contextMenuUniqueId = 0;
|
||||
|
||||
|
||||
private MessageListViewModel getViewModel() {
|
||||
|
@ -614,8 +600,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
listView.setFastScrollEnabled(true);
|
||||
listView.setScrollingCacheEnabled(false);
|
||||
listView.setOnItemClickListener(this);
|
||||
|
||||
registerForContextMenu(listView);
|
||||
}
|
||||
|
||||
public void onCompose() {
|
||||
|
@ -630,26 +614,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
}
|
||||
}
|
||||
|
||||
private void onReply(MessageReference messageReference) {
|
||||
fragmentListener.onReply(messageReference);
|
||||
}
|
||||
|
||||
private void onReplyAll(MessageReference messageReference) {
|
||||
fragmentListener.onReplyAll(messageReference);
|
||||
}
|
||||
|
||||
private void onForward(MessageReference messageReference) {
|
||||
fragmentListener.onForward(messageReference);
|
||||
}
|
||||
|
||||
public void onForwardAsAttachment(MessageReference messageReference) {
|
||||
fragmentListener.onForwardAsAttachment(messageReference);
|
||||
}
|
||||
|
||||
private void onResendMessage(MessageReference messageReference) {
|
||||
fragmentListener.onResendMessage(messageReference);
|
||||
}
|
||||
|
||||
public void changeSort(SortType sortType) {
|
||||
Boolean sortAscending = (this.sortType == sortType) ? !this.sortAscending : null;
|
||||
changeSort(sortType, sortAscending);
|
||||
|
@ -751,10 +715,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
changeSort(sorts[curIndex]);
|
||||
}
|
||||
|
||||
private void onDelete(MessageReference message) {
|
||||
onDelete(Collections.singletonList(message));
|
||||
}
|
||||
|
||||
private void onDelete(List<MessageReference> messages) {
|
||||
if (K9.isConfirmDelete()) {
|
||||
// remember the message selection for #onCreateDialog(int)
|
||||
|
@ -940,122 +900,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
messagingController.sendPendingMessages(account, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(android.view.MenuItem item) {
|
||||
if (contextMenuUniqueId == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int adapterPosition = getPositionForUniqueId(contextMenuUniqueId);
|
||||
if (adapterPosition == AdapterView.INVALID_POSITION) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.deselect || id == R.id.select) {
|
||||
toggleMessageSelectWithAdapterPosition(adapterPosition);
|
||||
} else if (id == R.id.reply) {
|
||||
onReply(getMessageAtPosition(adapterPosition));
|
||||
} else if (id == R.id.reply_all) {
|
||||
onReplyAll(getMessageAtPosition(adapterPosition));
|
||||
} else if (id == R.id.forward) {
|
||||
onForward(getMessageAtPosition(adapterPosition));
|
||||
} else if (id == R.id.forward_as_attachment) {
|
||||
onForwardAsAttachment(getMessageAtPosition(adapterPosition));
|
||||
} else if (id == R.id.send_again) {
|
||||
onResendMessage(getMessageAtPosition(adapterPosition));
|
||||
selectedCount = 0;
|
||||
} else if (id == R.id.same_sender) {
|
||||
MessageListItem messageListItem = adapter.getItem(adapterPosition);
|
||||
String senderAddress = messageListItem.getSenderAddress();
|
||||
if (senderAddress != null) {
|
||||
fragmentListener.showMoreFromSameSender(senderAddress);
|
||||
}
|
||||
} else if (id == R.id.delete) {
|
||||
MessageReference message = getMessageAtPosition(adapterPosition);
|
||||
onDelete(message);
|
||||
} else if (id == R.id.mark_as_read) {
|
||||
setFlag(adapterPosition, Flag.SEEN, true);
|
||||
} else if (id == R.id.mark_as_unread) {
|
||||
setFlag(adapterPosition, Flag.SEEN, false);
|
||||
} else if (id == R.id.flag) {
|
||||
setFlag(adapterPosition, Flag.FLAGGED, true);
|
||||
} else if (id == R.id.unflag) {
|
||||
setFlag(adapterPosition, Flag.FLAGGED, false);
|
||||
} else if (id == R.id.archive) { // only if the account supports this
|
||||
onArchive(getMessageAtPosition(adapterPosition));
|
||||
} else if (id == R.id.spam) {
|
||||
onSpam(getMessageAtPosition(adapterPosition));
|
||||
} else if (id == R.id.move) {
|
||||
onMove(getMessageAtPosition(adapterPosition));
|
||||
} else if (id == R.id.copy) {
|
||||
onCopy(getMessageAtPosition(adapterPosition));
|
||||
} else if (id == R.id.debug_delete_locally) { // debug options
|
||||
onDebugClearLocally(getMessageAtPosition(adapterPosition));
|
||||
}
|
||||
|
||||
contextMenuUniqueId = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||
int adapterPosition = listViewToAdapterPosition(info.position);
|
||||
MessageListItem messageListItem = adapter.getItem(adapterPosition);
|
||||
|
||||
getActivity().getMenuInflater().inflate(R.menu.message_list_item_context, menu);
|
||||
menu.findItem(R.id.debug_delete_locally).setVisible(K9.DEVELOPER_MODE);
|
||||
|
||||
contextMenuUniqueId = messageListItem.getUniqueId();
|
||||
Account account = messageListItem.getAccount();
|
||||
|
||||
String subject = messageListItem.getSubject();
|
||||
boolean read = messageListItem.isRead();
|
||||
boolean flagged = messageListItem.isStarred();
|
||||
|
||||
menu.setHeaderTitle(subject);
|
||||
|
||||
if (selected.contains(contextMenuUniqueId)) {
|
||||
menu.findItem(R.id.select).setVisible(false);
|
||||
} else {
|
||||
menu.findItem(R.id.deselect).setVisible(false);
|
||||
}
|
||||
|
||||
if (read) {
|
||||
menu.findItem(R.id.mark_as_read).setVisible(false);
|
||||
} else {
|
||||
menu.findItem(R.id.mark_as_unread).setVisible(false);
|
||||
}
|
||||
|
||||
if (flagged) {
|
||||
menu.findItem(R.id.flag).setVisible(false);
|
||||
} else {
|
||||
menu.findItem(R.id.unflag).setVisible(false);
|
||||
}
|
||||
|
||||
if (!messagingController.isCopyCapable(account)) {
|
||||
menu.findItem(R.id.copy).setVisible(false);
|
||||
}
|
||||
|
||||
if (!messagingController.isMoveCapable(account)) {
|
||||
menu.findItem(R.id.move).setVisible(false);
|
||||
menu.findItem(R.id.archive).setVisible(false);
|
||||
menu.findItem(R.id.spam).setVisible(false);
|
||||
}
|
||||
|
||||
if (!account.hasArchiveFolder()) {
|
||||
menu.findItem(R.id.archive).setVisible(false);
|
||||
}
|
||||
|
||||
if (!account.hasSpamFolder()) {
|
||||
menu.findItem(R.id.spam).setVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onSwipeRightToLeft(final MotionEvent e1, final MotionEvent e2) {
|
||||
// Handle right-to-left as an un-select
|
||||
handleSwipe(e1, false);
|
||||
|
@ -1590,10 +1434,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
messages);
|
||||
}
|
||||
|
||||
private void onDebugClearLocally(MessageReference message) {
|
||||
messagingController.debugClearMessagesLocally(Collections.singletonList(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to manage the invocation of {@link #startActivityForResult(Intent, int)} for a
|
||||
* folder operation ({@link ChooseFolderActivity} activity), while saving a list of associated messages.
|
||||
|
@ -1648,10 +1488,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
return messagesByAccount;
|
||||
}
|
||||
|
||||
private void onSpam(MessageReference message) {
|
||||
onSpam(Collections.singletonList(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Move messages to the spam folder.
|
||||
*
|
||||
|
@ -2187,12 +2023,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
void setMessageListProgressEnabled(boolean enable);
|
||||
void setMessageListProgress(int level);
|
||||
void showThread(Account account, String folderServerId, long rootId);
|
||||
void showMoreFromSameSender(String senderAddress);
|
||||
void onResendMessage(MessageReference message);
|
||||
void onForward(MessageReference message);
|
||||
void onForwardAsAttachment(MessageReference message);
|
||||
void onReply(MessageReference message);
|
||||
void onReplyAll(MessageReference message);
|
||||
void openMessage(MessageReference messageReference);
|
||||
void setMessageListTitle(String title);
|
||||
void onCompose(Account account);
|
||||
|
@ -2218,17 +2048,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
return listViewToAdapterPosition(listViewPosition);
|
||||
}
|
||||
|
||||
private int getPositionForUniqueId(long uniqueId) {
|
||||
for (int position = 0, end = adapter.getCount(); position < end; position++) {
|
||||
MessageListItem messageListItem = adapter.getItem(position);
|
||||
if (messageListItem.getUniqueId() == uniqueId) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
return AdapterView.INVALID_POSITION;
|
||||
}
|
||||
|
||||
private MessageReference getMessageAtPosition(int adapterPosition) {
|
||||
if (adapterPosition == AdapterView.INVALID_POSITION) {
|
||||
return null;
|
||||
|
@ -2404,8 +2223,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
cleanupSelected(messageListItems);
|
||||
adapter.setSelected(selected);
|
||||
|
||||
updateContextMenu(messageListItems);
|
||||
|
||||
adapter.setMessages(messageListItems);
|
||||
|
||||
resetActionMode();
|
||||
|
@ -2429,27 +2246,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
return messageListLoaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the context menu when the message it was opened for is no longer in the message list.
|
||||
*/
|
||||
private void updateContextMenu(List<MessageListItem> messageListItems) {
|
||||
if (contextMenuUniqueId == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (MessageListItem messageListItem : messageListItems) {
|
||||
if (messageListItem.getUniqueId() == contextMenuUniqueId) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
contextMenuUniqueId = 0;
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.closeContextMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanupSelected(List<MessageListItem> messageListItems) {
|
||||
if (selected.isEmpty()) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue