Put the dest mailbox name in the "message moved" toast
Also removed obsolete todo Bug 3075984 Change-Id: I10ce9df29c4913c328d2a962151d4a9f2e6e1408
This commit is contained in:
parent
a5fcefd179
commit
ee7205d100
@ -831,6 +831,12 @@ public class Utility {
|
||||
}
|
||||
};
|
||||
|
||||
private static final CursorGetter<String> STRING_GETTER = new CursorGetter<String>() {
|
||||
public String get(Cursor cursor, int column) {
|
||||
return cursor.getString(column);
|
||||
}
|
||||
};
|
||||
|
||||
private static final CursorGetter<byte[]> BLOB_GETTER = new CursorGetter<byte[]>() {
|
||||
public byte[] get(Cursor cursor, int column) {
|
||||
return cursor.getBlob(column);
|
||||
@ -899,7 +905,26 @@ public class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #getFirstRowColumn} for a byte array with null as a default value.
|
||||
* {@link #getFirstRowColumn} for a String with null as a default value.
|
||||
*/
|
||||
public static String getFirstRowString(Context context, Uri uri, String[] projection,
|
||||
String selection, String[] selectionArgs, String sortOrder, int column) {
|
||||
return getFirstRowColumn(context, uri, projection, selection, selectionArgs,
|
||||
sortOrder, column, null, STRING_GETTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #getFirstRowColumn} for a String with a provided default value.
|
||||
*/
|
||||
public static String getFirstRowString(Context context, Uri uri, String[] projection,
|
||||
String selection, String[] selectionArgs, String sortOrder, int column,
|
||||
String defaultValue) {
|
||||
return getFirstRowColumn(context, uri, projection, selection, selectionArgs,
|
||||
sortOrder, column, defaultValue, STRING_GETTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #getFirstRowColumn} for a byte array with a provided default value.
|
||||
*/
|
||||
public static byte[] getFirstRowBlob(Context context, Uri uri, String[] projection,
|
||||
String selection, String[] selectionArgs, String sortOrder, int column,
|
||||
|
@ -19,6 +19,7 @@ package com.android.email.activity;
|
||||
import com.android.email.Controller;
|
||||
import com.android.email.R;
|
||||
import com.android.email.Utility;
|
||||
import com.android.email.provider.EmailContent.Mailbox;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@ -100,11 +101,21 @@ public final class ActivityHelper {
|
||||
activity.getResources().getQuantityString(R.plurals.message_deleted_toast, 1));
|
||||
}
|
||||
|
||||
public static void moveMessages(Activity activity, long newMailboxId, long[] messageIds) {
|
||||
// TODO Support moving multiple messages
|
||||
public static void moveMessages(final Activity activity, final long newMailboxId,
|
||||
final long[] messageIds) {
|
||||
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);
|
||||
Utility.runAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String mailboxName = Mailbox.getDisplayName(activity, newMailboxId);
|
||||
if (mailboxName == null) {
|
||||
return; // Mailbox gone??
|
||||
}
|
||||
String message = activity.getResources().getQuantityString(
|
||||
R.plurals.message_moved_toast, messageIds.length, messageIds.length ,
|
||||
mailboxName);
|
||||
Utility.showToast(activity, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2165,6 +2165,11 @@ public abstract class EmailContent {
|
||||
};
|
||||
private static final int MAILBOX_TYPE_TYPE_COLUMN = 0;
|
||||
|
||||
private static final String[] MAILBOX_DISPLAY_NAME_PROJECTION = new String [] {
|
||||
MailboxColumns.DISPLAY_NAME
|
||||
};
|
||||
private static final int MAILBOX_DISPLAY_NAME_COLUMN = 0;
|
||||
|
||||
public static final long NO_MAILBOX = -1;
|
||||
|
||||
// Sentinel values for the mSyncInterval field of both Mailbox records
|
||||
@ -2366,6 +2371,15 @@ public abstract class EmailContent {
|
||||
null, null, null, MAILBOX_TYPE_TYPE_COLUMN, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mailbox display name, or null if mailbox not found.
|
||||
*/
|
||||
public static String getDisplayName(Context context, long mailboxId) {
|
||||
Uri url = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId);
|
||||
return Utility.getFirstRowString(context, url, MAILBOX_DISPLAY_NAME_PROJECTION,
|
||||
null, null, null, MAILBOX_DISPLAY_NAME_COLUMN, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mailboxId ID of a mailbox. This method accepts magic mailbox IDs, such as
|
||||
* {@link #QUERY_ALL_INBOXES}. (They're all non-refreshable.)
|
||||
|
@ -187,6 +187,38 @@ public class UtilityMediumTests extends ProviderTestCase2<EmailProvider> {
|
||||
EmailContent.ID_PROJECTION_COLUMN, -1));
|
||||
}
|
||||
|
||||
public void testGetFirstRowString() {
|
||||
final String[] DISPLAY_NAME_PROJECTION = new String[] {Account.DISPLAY_NAME};
|
||||
|
||||
Account account1 = ProviderTestUtils.setupAccount("1", true, mMockContext);
|
||||
Account account2 = ProviderTestUtils.setupAccount("X1", true, mMockContext);
|
||||
Account account3 = ProviderTestUtils.setupAccount("X2", true, mMockContext);
|
||||
|
||||
// case 1. Account found
|
||||
assertEquals(account2.mDisplayName, Utility.getFirstRowString(
|
||||
mMockContext, Account.CONTENT_URI, DISPLAY_NAME_PROJECTION,
|
||||
Account.DISPLAY_NAME + " like :1", new String[] {"X%"},
|
||||
Account.DISPLAY_NAME, 0));
|
||||
|
||||
// different sort order
|
||||
assertEquals(account3.mDisplayName, Utility.getFirstRowString(
|
||||
mMockContext, Account.CONTENT_URI, DISPLAY_NAME_PROJECTION,
|
||||
Account.DISPLAY_NAME + " like :1", new String[] {"X%"},
|
||||
Account.DISPLAY_NAME + " desc", 0));
|
||||
|
||||
// case 2. no row found
|
||||
assertEquals(null, Utility.getFirstRowString(
|
||||
mMockContext, Account.CONTENT_URI, DISPLAY_NAME_PROJECTION,
|
||||
Account.DISPLAY_NAME + " like :1", new String[] {"NO SUCH ACCOUNT"},
|
||||
null, 0));
|
||||
|
||||
// case 3. no row found with default value
|
||||
assertEquals("-", Utility.getFirstRowString(
|
||||
mMockContext, Account.CONTENT_URI, DISPLAY_NAME_PROJECTION,
|
||||
Account.DISPLAY_NAME + " like :1", new String[] {"NO SUCH ACCOUNT"},
|
||||
null, 0, "-"));
|
||||
}
|
||||
|
||||
public void testBuildMailboxIdSelection() {
|
||||
// Create dummy data...
|
||||
Context c = mMockContext;
|
||||
|
@ -2114,6 +2114,18 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
assertEquals(-1, Mailbox.getMailboxType(c, 999999)); // mailbox not found
|
||||
}
|
||||
|
||||
public void testGetDisplayName() {
|
||||
final Context c = mMockContext;
|
||||
|
||||
Account a = ProviderTestUtils.setupAccount("acct1", true, c);
|
||||
Mailbox bi = ProviderTestUtils.setupMailbox("b1", a.mId, true, c, Mailbox.TYPE_INBOX);
|
||||
Mailbox bm = ProviderTestUtils.setupMailbox("b2", a.mId, true, c, Mailbox.TYPE_MAIL);
|
||||
|
||||
assertEquals("b1", Mailbox.getDisplayName(c, bi.mId));
|
||||
assertEquals("b2", Mailbox.getDisplayName(c, bm.mId));
|
||||
assertEquals(null, Mailbox.getDisplayName(c, 999999)); // mailbox not found
|
||||
}
|
||||
|
||||
public void testMailboxIsRefreshable() {
|
||||
final Context c = mMockContext;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user