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.Context;
import android.content.Loader; import android.content.Loader;
import android.database.Cursor; import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@ -122,6 +123,8 @@ public class MessageListFragment extends ListFragment
private Utility.ListStateSaver mSavedListState; private Utility.ListStateSaver mSavedListState;
private MessageOpenTask mMessageOpenTask;
/** /**
* Callback interface that owning activities must implement * Callback interface that owning activities must implement
*/ */
@ -254,6 +257,8 @@ public class MessageListFragment extends ListFragment
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Email.LOG_TAG, "MessageListFragment onDestroy"); Log.d(Email.LOG_TAG, "MessageListFragment onDestroy");
} }
Utility.cancelTaskInterrupt(mMessageOpenTask);
mMessageOpenTask = null;
mRefreshManager.unregisterListener(mRefreshListener); mRefreshManager.unregisterListener(mRefreshListener);
super.onDestroy(); super.onDestroy();
} }
@ -386,28 +391,54 @@ public class MessageListFragment extends ListFragment
mListAdapter.toggleSelected(itemView); mListAdapter.toggleSelected(itemView);
} }
private void onMessageOpen(final long mailboxId, final long messageId) { /**
final int type; * Called when a message on the list is selected
if (mMailbox == null) { // Magic mailbox *
if (mMailboxId == Mailbox.QUERY_ALL_DRAFTS) { * @param messageMailboxId the actual mailbox ID of the message. Note it's different from
type = Callback.TYPE_DRAFT; * {@link #mMailboxId} in combined mailboxes. ({@link #mMailboxId} can take values such as
} else { * {@link Mailbox#QUERY_ALL_INBOXES})
type = Callback.TYPE_REGULAR; * @param messageId ID of the msesage to open.
} */
} else { private void onMessageOpen(final long messageMailboxId, final long messageId) {
switch (mMailbox.mType) { 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: case EmailContent.Mailbox.TYPE_DRAFTS:
type = Callback.TYPE_DRAFT; return Callback.TYPE_DRAFT;
break;
case EmailContent.Mailbox.TYPE_TRASH: case EmailContent.Mailbox.TYPE_TRASH:
type = Callback.TYPE_TRASH; return Callback.TYPE_TRASH;
break;
default: default:
type = Callback.TYPE_REGULAR; return Callback.TYPE_REGULAR;
break;
} }
} }
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() { public void onMultiToggleRead() {

View File

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

View File

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