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

@ -1861,22 +1861,31 @@ 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,
MessagingListener listener) {
if (folder.equals(account.getTrashFolderName())) {
return;
final MessagingListener listener) {
put("deleteMessage", null, new Runnable() {
public void run() {
deleteMessageSynchronous(account, folder, message, listener);
}
});
}
private void deleteMessageSynchronous(final Account account, final String folder, final Message message,
MessagingListener listener) {
try {
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Folder localFolder = localStore.getFolder(folder);
if (folder.equals(account.getTrashFolderName()))
{
if (Config.LOGD)
{
Log.d(Email.LOG_TAG, "Deleting message in trash folder, not copying");
}
message.setFlag(Flag.DELETED, true);
}
else
{
Folder localTrashFolder = localStore.getFolder(account.getTrashFolderName());
if (localTrashFolder.exists() == false)
{
@ -1884,15 +1893,44 @@ s * critical data as fast as possible, and then we'll fill in the de
}
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)
{
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();
command.command = PENDING_COMMAND_TRASH;
command.arguments = new String[] { folder, message.getUid() };

View File

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

View File

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

View File

@ -426,19 +426,21 @@ public class MessageView extends Activity
private void onDelete() {
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
mFolderUids.remove(mMessage.getUid());
// Check if we have previous/next messages available before choosing
// which one to display
findSurroundingMessagesUid();
MessagingListener listener = new MessagingListener()
{
public void messageDeleted(Account account, String folder, Message message)
{
// Toast.makeText(MessageView.this, R.string.message_deleted_toast, Toast.LENGTH_SHORT).show();
// Check if we have previous/next messages available before choosing
// which one to display
if (mPreviousMessageUid != null) {
onPrevious();
} else if (mNextMessageUid != null) {
@ -447,6 +449,26 @@ public class MessageView extends Activity
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);
}
}
private void onReply() {

View File

@ -1394,6 +1394,13 @@ public class ImapStore extends Store {
public void delete(String trashFolderName) throws MessagingException
{
ImapFolder iFolder = (ImapFolder)getFolder();
if (iFolder.getName().equals(trashFolderName))
{
setFlag(Flag.DELETED, true);
iFolder.expunge();
}
else
{
Folder remoteTrashFolder = iFolder.getStore().getFolder(trashFolderName);
/*
* Attempt to copy the remote message to the remote trash folder.
@ -1422,6 +1429,7 @@ public class ImapStore extends Store {
Log.e(Email.LOG_TAG, "IMAPMessage.delete: remote Trash folder " + trashFolderName + " does not exist and could not be created");
}
}
}
}