1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Instant deletes from FolderMessageList. Faster deletes from

MessageView

Deleting a message in Trash deletes it for real (permanently)

All message operations are allowed on messages in the Outbox.  Special
handling for deleting, so that the message is copied to Trash, then
copied asynchronously to the remote Trash.

Add some more items to the hotkey help
This commit is contained in:
Daniel Applebaum 2009-01-07 06:02:04 +00:00
parent efb2801bab
commit 3a3dc2da43
5 changed files with 151 additions and 81 deletions

View File

@ -1860,39 +1860,77 @@ s * critical data as fast as possible, and then we'll fill in the de
} }
} }
/**
* We do the local portion of this synchronously because other activities may have to make
* updates based on what happens here
* @param account
* @param folder
* @param message
* @param listener
*/
public void deleteMessage(final Account account, final String folder, final Message message, public void deleteMessage(final Account account, final String folder, final Message message,
MessagingListener listener) { final MessagingListener listener) {
if (folder.equals(account.getTrashFolderName())) { put("deleteMessage", null, new Runnable() {
return; public void run() {
deleteMessageSynchronous(account, folder, message, listener);
} }
});
}
private void deleteMessageSynchronous(final Account account, final String folder, final Message message,
MessagingListener listener) {
try { try {
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Folder localFolder = localStore.getFolder(folder); Folder localFolder = localStore.getFolder(folder);
Folder localTrashFolder = localStore.getFolder(account.getTrashFolderName());
if (localTrashFolder.exists() == false) if (folder.equals(account.getTrashFolderName()))
{ {
localTrashFolder.create(Folder.FolderType.HOLDS_MESSAGES); if (Config.LOGD)
} {
if (localTrashFolder.exists() == true) Log.d(Email.LOG_TAG, "Deleting message in trash folder, not copying");
{ }
localFolder.copyMessages(new Message[] { message }, localTrashFolder);
message.setFlag(Flag.DELETED, true); message.setFlag(Flag.DELETED, true);
} }
else
{
Folder localTrashFolder = localStore.getFolder(account.getTrashFolderName());
if (localTrashFolder.exists() == false)
{
localTrashFolder.create(Folder.FolderType.HOLDS_MESSAGES);
}
if (localTrashFolder.exists() == true)
{
if (Config.LOGD)
{
Log.d(Email.LOG_TAG, "Deleting message in normal folder, copying");
}
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.BODY);
// TODO: Turn the fetch/copy/delete into an atomic move
localFolder.fetch(new Message[] { message }, fp, null);
localFolder.copyMessages(new Message[] { message }, localTrashFolder);
message.setFlag(Flag.DELETED, true);
}
}
if (listener != null) {
listener.messageDeleted(account, folder, message);
}
// for (MessagingListener l : getListeners()) {
// l.folderStatusChanged(account, account.getTrashFolderName());
// }
if (Config.LOGD) if (Config.LOGD)
{ {
Log.d(Email.LOG_TAG, "Delete policy for account " + account.getDescription() + " is " + account.getDeletePolicy()); Log.d(Email.LOG_TAG, "Delete policy for account " + account.getDescription() + " is " + account.getDeletePolicy());
} }
if (account.getDeletePolicy() == Account.DELETE_POLICY_ON_DELETE) { if (folder.equals(account.getOutboxFolderName()))
{
// If the message was in the Outbox, then it has been copied to local Trash, and has
// to be copied to remote trash
PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_APPEND;
command.arguments =
new String[] {
account.getTrashFolderName(),
message.getUid() };
queuePendingCommand(account, command);
processPendingCommands(account);
}
else if (account.getDeletePolicy() == Account.DELETE_POLICY_ON_DELETE) {
PendingCommand command = new PendingCommand(); PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_TRASH; command.command = PENDING_COMMAND_TRASH;
command.arguments = new String[] { folder, message.getUid() }; command.arguments = new String[] { folder, message.getUid() };

View File

@ -92,7 +92,10 @@ public class MessagingListener {
public void sendPendingMessagesFailed(Account account) { public void sendPendingMessagesFailed(Account account) {
} }
public void messageDeleted(Account account, String folder, Message message)
{
}
public void emptyTrashCompleted(Account account) { public void emptyTrashCompleted(Account account) {
} }

View File

@ -546,18 +546,18 @@ public class FolderMessageList extends ExpandableListActivity
@Override @Override
public void onResume() public void onResume()
{ {
super.onResume(); super.onResume();
clearFormats(); clearFormats();
MessagingController.getInstance(getApplication()).addListener( MessagingController.getInstance(getApplication()).addListener(
mAdapter.mListener); mAdapter.mListener);
mAccount.refresh(Preferences.getPreferences(this)); mAccount.refresh(Preferences.getPreferences(this));
onRefresh(false); onRefresh(false);
NotificationManager notifMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notifMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notifMgr.cancel(mAccount.getAccountNumber()); notifMgr.cancel(mAccount.getAccountNumber());
} }
@Override @Override
public void onSaveInstanceState(Bundle outState) public void onSaveInstanceState(Bundle outState)
@ -651,10 +651,8 @@ public class FolderMessageList extends ExpandableListActivity
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) { int childPosition, long id) {
FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getGroup(groupPosition); FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getGroup(groupPosition);
if (folder.outbox) {
return false; if (!folder.outbox && childPosition == folder.messages.size() && !folder.loading)
}
if (childPosition == folder.messages.size() && !folder.loading)
{ {
if (folder.status == null) if (folder.status == null)
{ {
@ -759,12 +757,13 @@ public class FolderMessageList extends ExpandableListActivity
{ {
holder.folder.unreadMessageCount--; holder.folder.unreadMessageCount--;
} }
MessagingController.getInstance(getApplication()).deleteMessage(mAccount,
holder.message.getFolder().getName(), holder.message, null);
mAdapter.removeMessage(holder.message.getFolder().getName(), holder.uid); mAdapter.removeMessage(holder.message.getFolder().getName(), holder.uid);
Toast.makeText(this, R.string.message_deleted_toast, Toast.LENGTH_SHORT) mAdapter.addOrUpdateMessage(mAccount.getTrashFolderName(), holder.message);
.show();
// onRefresh(false); MessagingController.getInstance(getApplication()).deleteMessage(mAccount,
holder.message.getFolder().getName(), holder.message, null);
} }
private void onReply(MessageInfoHolder holder) private void onReply(MessageInfoHolder holder)
@ -950,10 +949,10 @@ public class FolderMessageList extends ExpandableListActivity
.getPackedPositionChild(packedPosition); .getPackedPositionChild(packedPosition);
FolderInfoHolder folder = (FolderInfoHolder) mAdapter FolderInfoHolder folder = (FolderInfoHolder) mAdapter
.getGroup(groupPosition); .getGroup(groupPosition);
if (folder.outbox) // if (folder.outbox)
{ // {
return; // return;
} // }
if (childPosition < folder.messages.size()) if (childPosition < folder.messages.size())
{ {
getMenuInflater().inflate(R.menu.folder_message_list_context, menu); getMenuInflater().inflate(R.menu.folder_message_list_context, menu);

View File

@ -426,26 +426,48 @@ public class MessageView extends Activity
private void onDelete() { private void onDelete() {
if (mMessage != null) { if (mMessage != null) {
MessagingController.getInstance(getApplication()).deleteMessage(
mAccount,
mFolder,
mMessage,
null);
Toast.makeText(this, R.string.message_deleted_toast, Toast.LENGTH_SHORT).show();
// Remove this message's Uid locally // Remove this message's Uid locally
mFolderUids.remove(mMessage.getUid()); mFolderUids.remove(mMessage.getUid());
// Check if we have previous/next messages available before choosing
// which one to display findSurroundingMessagesUid();
findSurroundingMessagesUid();
MessagingListener listener = new MessagingListener()
if (mPreviousMessageUid != null) { {
onPrevious(); public void messageDeleted(Account account, String folder, Message message)
} else if (mNextMessageUid != null) { {
onNext(); // Toast.makeText(MessageView.this, R.string.message_deleted_toast, Toast.LENGTH_SHORT).show();
} else {
finish(); // Check if we have previous/next messages available before choosing
// which one to display
if (mPreviousMessageUid != null) {
onPrevious();
} else if (mNextMessageUid != null) {
onNext();
} else {
finish();
}
}
};
MessagingListener waitListener = null;
if (mPreviousMessageUid == null && mNextMessageUid == null)
{
// If we have no more messages to view, force the delete to be synchronous, so that
// when we return to the list, all of the localStore operations have completed.
waitListener = listener;
} }
else
{
listener.messageDeleted(mAccount, mFolder, mMessage);
}
MessagingController.getInstance(getApplication()).deleteMessage(
mAccount,
mFolder,
mMessage,
waitListener);
} }
} }

View File

@ -1394,33 +1394,41 @@ public class ImapStore extends Store {
public void delete(String trashFolderName) throws MessagingException public void delete(String trashFolderName) throws MessagingException
{ {
ImapFolder iFolder = (ImapFolder)getFolder(); ImapFolder iFolder = (ImapFolder)getFolder();
Folder remoteTrashFolder = iFolder.getStore().getFolder(trashFolderName); if (iFolder.getName().equals(trashFolderName))
/* {
* Attempt to copy the remote message to the remote trash folder. setFlag(Flag.DELETED, true);
*/ iFolder.expunge();
if (!remoteTrashFolder.exists()) { }
/* else
* If the remote trash folder doesn't exist we try to create it. {
*/ Folder remoteTrashFolder = iFolder.getStore().getFolder(trashFolderName);
Log.i(Email.LOG_TAG, "IMAPMessage.delete: attempting to create remote " + trashFolderName + " folder"); /*
remoteTrashFolder.create(FolderType.HOLDS_MESSAGES); * Attempt to copy the remote message to the remote trash folder.
} */
if (!remoteTrashFolder.exists()) {
if (remoteTrashFolder.exists()) { /*
if (Config.LOGD) * If the remote trash folder doesn't exist we try to create it.
{ */
Log.d(Email.LOG_TAG, "IMAPMessage.delete: copying remote message to " + trashFolderName); Log.i(Email.LOG_TAG, "IMAPMessage.delete: attempting to create remote " + trashFolderName + " folder");
} remoteTrashFolder.create(FolderType.HOLDS_MESSAGES);
iFolder.copyMessages(new Message[] { this }, remoteTrashFolder); }
setFlag(Flag.DELETED, true);
iFolder.expunge(); if (remoteTrashFolder.exists()) {
} if (Config.LOGD)
else {
{ Log.d(Email.LOG_TAG, "IMAPMessage.delete: copying remote message to " + trashFolderName);
// Toast.makeText(context, R.string.message_delete_failed, Toast.LENGTH_SHORT).show(); }
iFolder.copyMessages(new Message[] { this }, remoteTrashFolder);
Log.e(Email.LOG_TAG, "IMAPMessage.delete: remote Trash folder " + trashFolderName + " does not exist and could not be created"); setFlag(Flag.DELETED, true);
} iFolder.expunge();
}
else
{
// Toast.makeText(context, R.string.message_delete_failed, Toast.LENGTH_SHORT).show();
Log.e(Email.LOG_TAG, "IMAPMessage.delete: remote Trash folder " + trashFolderName + " does not exist and could not be created");
}
}
} }
} }