From 11aea1efe45b23c1217b31be029a527c9dc460b8 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Wed, 1 Sep 2010 13:46:11 -0700 Subject: [PATCH] "Move to" multiple messages Now Controller.moveMessage supports moving multiple messages. Change-Id: I5d9715cd94e55cf14254b4d4d731524be9d014a8 --- src/com/android/email/Controller.java | 29 +++++++++++++------ .../email/activity/ActivityHelper.java | 2 +- .../email/ControllerProviderOpsTests.java | 15 +++++++--- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/com/android/email/Controller.java b/src/com/android/email/Controller.java index 132f2daea..0f499889a 100644 --- a/src/com/android/email/Controller.java +++ b/src/com/android/email/Controller.java @@ -53,6 +53,7 @@ import android.util.Log; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.security.InvalidParameterException; import java.util.Collection; import java.util.HashSet; import java.util.concurrent.ConcurrentHashMap; @@ -722,25 +723,35 @@ public class Controller { } /** - * Moving a message to another folder + * Moving messages to another folder * * This function has no callback, no result reporting, because the desired outcome * is reflected entirely by changes to one or more cursors. * - * @param messageId The id of the message to move - * @param mailboxId The id of the folder we're supposed to move the folder to + * Note this method assumes all the messages, and the destination mailbox belong to the same + * account. + * + * @param messageIds The IDs of the messages to move + * @param newMailboxId The id of the folder we're supposed to move the folder to * @return the AsyncTask that will execute the move */ - public AsyncTask moveMessage(final long messageId, final long mailboxId) { + public AsyncTask moveMessage(final long[] messageIds, + final long newMailboxId) { + if (messageIds == null || messageIds.length == 0) { + throw new InvalidParameterException(); + } return Utility.runAsync(new Runnable() { public void run() { - Account account = Account.getAccountForMessageId(mProviderContext, messageId); + Account account = Account.getAccountForMessageId(mProviderContext, messageIds[0]); if (account != null) { - Uri uri = ContentUris.withAppendedId(EmailContent.Message.SYNCED_CONTENT_URI, - messageId); ContentValues cv = new ContentValues(); - cv.put(EmailContent.MessageColumns.MAILBOX_KEY, mailboxId); - mProviderContext.getContentResolver().update(uri, cv, null, null); + cv.put(EmailContent.MessageColumns.MAILBOX_KEY, newMailboxId); + ContentResolver resolver = mProviderContext.getContentResolver(); + for (long messageId : messageIds) { + Uri uri = ContentUris.withAppendedId( + EmailContent.Message.SYNCED_CONTENT_URI, messageId); + resolver.update(uri, cv, null, null); + } if (isMessagingController(account)) { mLegacyController.processPendingActions(account.mId); } diff --git a/src/com/android/email/activity/ActivityHelper.java b/src/com/android/email/activity/ActivityHelper.java index 5855d405c..29b62ae63 100644 --- a/src/com/android/email/activity/ActivityHelper.java +++ b/src/com/android/email/activity/ActivityHelper.java @@ -101,7 +101,7 @@ public final class ActivityHelper { public static void moveMessages(Activity activity, long newMailboxId, long[] messageIds) { // TODO Support moving multiple messages - Controller.getInstance(activity).moveMessage(messageIds[0], newMailboxId); + Controller.getInstance(activity).moveMessage(messageIds, newMailboxId); String message = activity.getResources().getQuantityString(R.plurals.message_moved_toast, messageIds.length, messageIds.length , "a mailbox"); // STOPSHIP get mailbox name Utility.showToast(activity, message); diff --git a/tests/src/com/android/email/ControllerProviderOpsTests.java b/tests/src/com/android/email/ControllerProviderOpsTests.java index 29f3cb617..208baa8c1 100644 --- a/tests/src/com/android/email/ControllerProviderOpsTests.java +++ b/tests/src/com/android/email/ControllerProviderOpsTests.java @@ -158,6 +158,7 @@ public class ControllerProviderOpsTests extends ProviderTestCase2 /** * Test the "move message" function. + * * @throws ExecutionException * @throws InterruptedException */ @@ -168,18 +169,24 @@ public class ControllerProviderOpsTests extends ProviderTestCase2 long box1Id = box1.mId; Mailbox box2 = ProviderTestUtils.setupMailbox("box2", account1Id, true, mProviderContext); long box2Id = box2.mId; + Mailbox boxDest = ProviderTestUtils.setupMailbox("d", account1Id, true, mProviderContext); + long boxDestId = boxDest.mId; Message message1 = ProviderTestUtils.setupMessage("message1", account1Id, box1Id, false, true, mProviderContext); + Message message2 = ProviderTestUtils.setupMessage("message2", account1Id, box2Id, false, + true, mProviderContext); long message1Id = message1.mId; + long message2Id = message2.mId; // Because moveMessage runs asynchronously, call get() to force it to complete - mTestController.moveMessage(message1Id, box2Id).get(); + mTestController.moveMessage(new long[] {message1Id, message2Id}, boxDestId).get(); // now read back a fresh copy and confirm it's in the trash - Message message1get = EmailContent.Message.restoreMessageWithId(mProviderContext, - message1Id); - assertEquals(box2Id, message1get.mMailboxKey); + assertEquals(boxDestId, EmailContent.Message.restoreMessageWithId(mProviderContext, + message1Id).mMailboxKey); + assertEquals(boxDestId, EmailContent.Message.restoreMessageWithId(mProviderContext, + message2Id).mMailboxKey); } /**