From 39137e51aa3b454cfa1258a10c9c7499261b175a Mon Sep 17 00:00:00 2001 From: Mihai Preda Date: Mon, 1 Jun 2009 12:38:20 -0700 Subject: [PATCH] AI 149446: Add sending pending outbox message feature; integrates 148664, 148823 from imode to donut. BUG=1860250,1793767 Automated import of CL 149446 --- res/values/strings.xml | 7 ++ .../android/email/MessagingController.java | 29 ++++---- src/com/android/email/MessagingListener.java | 6 ++ .../email/activity/FolderMessageList.java | 69 ++++++++++++++++--- 4 files changed, 90 insertions(+), 21 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 88c5c767c..1358c3ac2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -84,10 +84,14 @@ Account options Loading messages\u2026 + + Sending messages\u2026 Connection error + Retry sending messages + Retry loading more messages New email @@ -137,6 +141,9 @@ Load more messages + + Send outgoing messages To diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index f47a20c5f..e4ebada69 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -1586,7 +1586,7 @@ public class MessagingController implements Runnable { message.setFlag(Flag.X_SEND_IN_PROGRESS, true); sender.sendMessage(message); message.setFlag(Flag.X_SEND_IN_PROGRESS, false); - + // Upload to "sent" folder if not supported server-side if (requireCopyMessageToSentFolder) { localFolder.copyMessages( @@ -1604,19 +1604,22 @@ public class MessagingController implements Runnable { } catch (Exception e) { message.setFlag(Flag.X_SEND_FAILED, true); + synchronized (mListeners) { + for (MessagingListener l : mListeners) { + l.sendPendingMessageFailed(account, message, e); + } + } } } catch (Exception e) { - /* - * We ignore this exception because a future refresh will retry this - * message. - */ + synchronized (mListeners) { + for (MessagingListener l : mListeners) { + l.sendPendingMessageFailed(account, message, e); + } + } } } localFolder.expunge(); - if (localFolder.getMessageCount() == 0) { - localFolder.delete(false); - } synchronized (mListeners) { for (MessagingListener l : mListeners) { l.sendPendingMessagesCompleted(account); @@ -1624,11 +1627,11 @@ public class MessagingController implements Runnable { } } catch (Exception e) { -// synchronized (mListeners) { -// for (MessagingListener l : mListeners) { -// // TODO general failed -// } -// } + synchronized (mListeners) { + for (MessagingListener l : mListeners) { + l.sendPendingMessagesFailed(account, e); + } + } } } diff --git a/src/com/android/email/MessagingListener.java b/src/com/android/email/MessagingListener.java index 44ddc4229..b8271681c 100644 --- a/src/com/android/email/MessagingListener.java +++ b/src/com/android/email/MessagingListener.java @@ -100,6 +100,12 @@ public class MessagingListener { public void sendPendingMessagesCompleted(Account account) { } + public void sendPendingMessagesFailed(Account account, Exception reason) { + } + + public void sendPendingMessageFailed(Account account, Message message, Exception reason) { + } + public void emptyTrashCompleted(Account account) { } diff --git a/src/com/android/email/activity/FolderMessageList.java b/src/com/android/email/activity/FolderMessageList.java index bd13dfcce..4bd55530d 100644 --- a/src/com/android/email/activity/FolderMessageList.java +++ b/src/com/android/email/activity/FolderMessageList.java @@ -596,6 +596,13 @@ public class FolderMessageList extends ExpandableListActivity { int childPosition, long id) { FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getGroup(groupPosition); if (folder.outbox) { + if (childPosition == folder.messages.size() && !folder.loading) { + mHandler.folderLoading(mAccount.getOutboxFolderName(), true); + mHandler.progress(true); + MessagingController.getInstance(getApplication()).sendPendingMessages( + mAccount, + null); + } return false; } if (childPosition == folder.messages.size() && !folder.loading) { @@ -617,7 +624,8 @@ public class FolderMessageList extends ExpandableListActivity { else if (childPosition >= folder.messages.size()) { return false; } - MessageInfoHolder message = (MessageInfoHolder) mAdapter.getChild(groupPosition, childPosition); + MessageInfoHolder message = + (MessageInfoHolder) mAdapter.getChild(groupPosition, childPosition); onOpenMessage(folder, message); @@ -636,6 +644,8 @@ public class FolderMessageList extends ExpandableListActivity { mRefreshRemote, mAdapter.mListener); if (forceRemote) { + mHandler.folderLoading(mAccount.getOutboxFolderName(), true); + mHandler.progress(true); MessagingController.getInstance(getApplication()).sendPendingMessages( mAccount, null); @@ -975,9 +985,34 @@ public class FolderMessageList extends ExpandableListActivity { if (!account.equals(mAccount)) { return; } + mHandler.folderLoading(account.getOutboxFolderName(), false); + mHandler.progress(false); onRefresh(false); } + @Override + public void sendPendingMessagesFailed(Account account, Exception reason) { + if (!account.equals(mAccount)) { + return; + } + String outboxName = account.getOutboxFolderName(); + mHandler.folderLoading(outboxName, false); + mHandler.progress(false); + mHandler.folderStatus(outboxName, reason.getMessage(), false); + onRefresh(false); + } + + @Override + public void sendPendingMessageFailed(Account account, Message message, + Exception reason) { + if (!account.equals(mAccount)) { + return; + } + // TODO May we move failed message to draft folder? + //mHandler.removeMessageByUid(folder, message.getUid()); + //mHandler.folderStatus(account.getOutboxFolderName(), reason.getMessage(), false); + } + @Override public void messageUidChanged( Account account, @@ -1023,6 +1058,7 @@ public class FolderMessageList extends ExpandableListActivity { } try { folder.open(Folder.OpenMode.READ_WRITE, null); + holder.messageCount = folder.getMessageCount(); holder.unreadMessageCount = folder.getUnreadMessageCount(); folder.close(false); } @@ -1194,10 +1230,14 @@ public class FolderMessageList extends ExpandableListActivity { holder.folderStatus.setVisibility(View.VISIBLE); } - if (folder.unreadMessageCount != 0) { + if (!folder.outbox && folder.unreadMessageCount != 0) { holder.newMessageCount.setText(Integer.toString(folder.unreadMessageCount)); holder.newMessageCount.setVisibility(View.VISIBLE); } + else if (folder.outbox && folder.messageCount > 0) { + holder.newMessageCount.setText(Integer.toString(folder.messageCount)); + holder.newMessageCount.setVisibility(View.VISIBLE); + } else { holder.newMessageCount.setVisibility(View.GONE); } @@ -1247,20 +1287,32 @@ public class FolderMessageList extends ExpandableListActivity { view.setTag(holder); } if (folder.loading) { - holder.main.setText(getString(R.string.status_loading_more)); + if (folder.outbox) { + holder.main.setText(R.string.status_sending_messages); + } else { + holder.main.setText(R.string.status_loading_more); + } holder.progress.setVisibility(View.VISIBLE); } else { if (folder.status == null) { - if (mSyncWindowUser) { - holder.main.setText(getString( - R.string.message_list_load_more_messages_action)); + if (folder.outbox) { + holder.main.setText(R.string.message_list_send_pending_messages_action); } else { - holder.main.setText(getString(R.string.refresh_action)); + if (mSyncWindowUser) { + holder.main.setText( + R.string.message_list_load_more_messages_action); + } else { + holder.main.setText(R.string.refresh_action); + } } } else { - holder.main.setText(getString(R.string.status_loading_more_failed)); + if (folder.outbox) { + holder.main.setText(R.string.status_sending_messages_failed); + } else { + holder.main.setText(R.string.status_loading_more_failed); + } } holder.progress.setVisibility(View.GONE); } @@ -1334,6 +1386,7 @@ public class FolderMessageList extends ExpandableListActivity { public String displayName; public ArrayList messages; public long lastChecked; + public int messageCount; public int unreadMessageCount; public boolean loading; public String status;