Open MessageComponse when draft in All Starred is selected

Also removed a silly unnecessary code in Mailbox.isRefreshable.

Bug 2968445

Change-Id: I75187e5abf1c3e67c8b9ead38c7f749fc8b6cfb0
This commit is contained in:
Makoto Onuki 2010-09-01 14:34:55 -07:00
parent 975b5c71ab
commit a25aa613f7
3 changed files with 72 additions and 23 deletions

View File

@ -34,6 +34,7 @@ import android.app.LoaderManager;
import android.content.Context;
import android.content.Loader;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@ -122,6 +123,8 @@ public class MessageListFragment extends ListFragment
private Utility.ListStateSaver mSavedListState;
private MessageOpenTask mMessageOpenTask;
/**
* Callback interface that owning activities must implement
*/
@ -254,6 +257,8 @@ public class MessageListFragment extends ListFragment
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Email.LOG_TAG, "MessageListFragment onDestroy");
}
Utility.cancelTaskInterrupt(mMessageOpenTask);
mMessageOpenTask = null;
mRefreshManager.unregisterListener(mRefreshListener);
super.onDestroy();
}
@ -386,28 +391,54 @@ public class MessageListFragment extends ListFragment
mListAdapter.toggleSelected(itemView);
}
private void onMessageOpen(final long mailboxId, final long messageId) {
final int type;
if (mMailbox == null) { // Magic mailbox
if (mMailboxId == Mailbox.QUERY_ALL_DRAFTS) {
type = Callback.TYPE_DRAFT;
} else {
type = Callback.TYPE_REGULAR;
}
} else {
switch (mMailbox.mType) {
/**
* Called when a message on the list is selected
*
* @param messageMailboxId the actual mailbox ID of the message. Note it's different from
* {@link #mMailboxId} in combined mailboxes. ({@link #mMailboxId} can take values such as
* {@link Mailbox#QUERY_ALL_INBOXES})
* @param messageId ID of the msesage to open.
*/
private void onMessageOpen(final long messageMailboxId, final long messageId) {
Utility.cancelTaskInterrupt(mMessageOpenTask);
mMessageOpenTask = new MessageOpenTask(messageMailboxId, messageId);
mMessageOpenTask.execute();
}
/**
* Task to look up the mailbox type for a message, and kicks the callback.
*/
private class MessageOpenTask extends AsyncTask<Void, Void, Integer> {
private final long mMessageMailboxId;
private final long mMessageId;
public MessageOpenTask(long messageMailboxId, long messageId) {
mMessageMailboxId = messageMailboxId;
mMessageId = messageId;
}
@Override
protected Integer doInBackground(Void... params) {
// Restore the mailbox type. Note we can't use mMailbox.mType here, because
// we don't have mMailbox for combined mailbox.
// ("All Starred" can contain any kind of messages.)
switch (Mailbox.getMailboxType(mActivity, mMessageMailboxId)) {
case EmailContent.Mailbox.TYPE_DRAFTS:
type = Callback.TYPE_DRAFT;
break;
return Callback.TYPE_DRAFT;
case EmailContent.Mailbox.TYPE_TRASH:
type = Callback.TYPE_TRASH;
break;
return Callback.TYPE_TRASH;
default:
type = Callback.TYPE_REGULAR;
break;
return Callback.TYPE_REGULAR;
}
}
mCallback.onMessageOpen(messageId, mailboxId, getMailboxId(), type);
@Override
protected void onPostExecute(Integer type) {
if (isCancelled() || type == null) {
return;
}
mCallback.onMessageOpen(mMessageId, mMessageMailboxId, getMailboxId(), type);
}
}
public void onMultiToggleRead() {

View File

@ -2289,6 +2289,15 @@ public abstract class EmailContent {
return null;
}
/**
* @return mailbox type, or -1 if mailbox not found.
*/
public static int getMailboxType(Context context, long mailboxId) {
Uri url = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId);
return Utility.getFirstRowInt(context, url, MAILBOX_TYPE_PROJECTION,
null, null, null, MAILBOX_TYPE_TYPE_COLUMN, -1);
}
/**
* @return true if a mailbox is refreshable.
*/
@ -2296,11 +2305,8 @@ public abstract class EmailContent {
if (mailboxId < 0) {
return false; // magic mailboxes
}
Uri url = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId);
int type = Utility.getFirstRowInt(context, url, MAILBOX_TYPE_PROJECTION,
null, null, null, MAILBOX_TYPE_TYPE_COLUMN);
Mailbox mailbox = Mailbox.restoreMailboxWithId(context, mailboxId);
switch (mailbox.mType) {
switch (getMailboxType(context, mailboxId)) {
case -1: // not found
case TYPE_DRAFTS:
case TYPE_OUTBOX:
return false;

View File

@ -2004,6 +2004,18 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
assertEquals(b2i.mId, Account.getInboxId(c, a2.mId));
}
public void testGetMailboxType() {
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("b1", a.mId, true, c, Mailbox.TYPE_MAIL);
assertEquals(Mailbox.TYPE_INBOX, Mailbox.getMailboxType(c, bi.mId));
assertEquals(Mailbox.TYPE_MAIL, Mailbox.getMailboxType(c, bm.mId));
assertEquals(-1, Mailbox.getMailboxType(c, 999999)); // mailbox not found
}
public void testMailboxIsRefreshable() {
final Context c = mMockContext;
@ -2019,7 +2031,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
assertFalse(Mailbox.isRefreshable(c, bo.mId));
// No such mailbox
assertFalse(Mailbox.isRefreshable(c, -1));
assertFalse(Mailbox.isRefreshable(c, 9999999));
// Magic mailboxes can't be refreshed.
assertFalse(Mailbox.isRefreshable(c, Mailbox.QUERY_ALL_DRAFTS));