"Move to" multiple messages

Now Controller.moveMessage supports moving multiple messages.

Change-Id: I5d9715cd94e55cf14254b4d4d731524be9d014a8
This commit is contained in:
Makoto Onuki 2010-09-01 13:46:11 -07:00
parent 62f9c4d280
commit 11aea1efe4
3 changed files with 32 additions and 14 deletions

View File

@ -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<Void, Void, Void> moveMessage(final long messageId, final long mailboxId) {
public AsyncTask<Void, Void, Void> 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);
}

View File

@ -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);

View File

@ -158,6 +158,7 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
/**
* Test the "move message" function.
*
* @throws ExecutionException
* @throws InterruptedException
*/
@ -168,18 +169,24 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
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);
}
/**