MessageList: Go to Welcome if account not found.
If the account specified with an Intent doesn't exist, show the Welcome activity instead, which will navigate the user to the appropriate activity. (e.g. account list if there're more than one account) Bug 2479609
This commit is contained in:
parent
678ab2c780
commit
652be6fb3d
@ -250,9 +250,6 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
|
||||
* Show the appropriate account/mailbox specified by an {@link Intent}.
|
||||
*/
|
||||
private void selectAccountAndMailbox(Intent intent) {
|
||||
|
||||
// TODO if we don't know the specified mailbox/account, move to the welcome screen.
|
||||
|
||||
mMailboxId = intent.getLongExtra(EXTRA_MAILBOX_ID, -1);
|
||||
if (mMailboxId != -1) {
|
||||
// Specific mailbox ID was provided - go directly to it
|
||||
@ -1046,9 +1043,10 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
|
||||
*/
|
||||
private class FindMailboxTask extends AsyncTask<Void, Void, Long> {
|
||||
|
||||
private long mAccountId;
|
||||
private int mMailboxType;
|
||||
private boolean mOkToRecurse;
|
||||
private final long mAccountId;
|
||||
private final int mMailboxType;
|
||||
private final boolean mOkToRecurse;
|
||||
private boolean showWelcomeActivity;
|
||||
|
||||
/**
|
||||
* Special constructor to cache some local info
|
||||
@ -1063,26 +1061,38 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
|
||||
protected Long doInBackground(Void... params) {
|
||||
// See if we can find the requested mailbox in the DB.
|
||||
long mailboxId = Mailbox.findMailboxOfType(MessageList.this, mAccountId, mMailboxType);
|
||||
if (mailboxId == Mailbox.NO_MAILBOX && mOkToRecurse) {
|
||||
// Not found - launch network lookup
|
||||
mControllerCallback.mWaitForMailboxType = mMailboxType;
|
||||
mController.updateMailboxList(mAccountId, mControllerCallback);
|
||||
if (mailboxId == Mailbox.NO_MAILBOX) {
|
||||
// Mailbox not found. Does the account really exists?
|
||||
final boolean accountExists = Account.isValidId(MessageList.this, mAccountId);
|
||||
if (accountExists && mOkToRecurse) {
|
||||
// launch network lookup
|
||||
mControllerCallback.mWaitForMailboxType = mMailboxType;
|
||||
mController.updateMailboxList(mAccountId, mControllerCallback);
|
||||
} else {
|
||||
// We don't want to do the network lookup, or the account doesn't exist in the
|
||||
// first place.
|
||||
showWelcomeActivity = true;
|
||||
}
|
||||
}
|
||||
return mailboxId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Long mailboxId) {
|
||||
if (mailboxId == null) {
|
||||
if (showWelcomeActivity) {
|
||||
// Let the Welcome activity show the default screen.
|
||||
Welcome.actionStart(MessageList.this);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
if (mailboxId != Mailbox.NO_MAILBOX) {
|
||||
mMailboxId = mailboxId;
|
||||
mSetTitleTask = new SetTitleTask(mMailboxId);
|
||||
mSetTitleTask.execute();
|
||||
mLoadMessagesTask = new LoadMessagesTask(mMailboxId, mAccountId);
|
||||
mLoadMessagesTask.execute();
|
||||
if (mailboxId == null || mailboxId == Mailbox.NO_MAILBOX) {
|
||||
return;
|
||||
}
|
||||
mMailboxId = mailboxId;
|
||||
mSetTitleTask = new SetTitleTask(mMailboxId);
|
||||
mSetTitleTask.execute();
|
||||
mLoadMessagesTask = new LoadMessagesTask(mMailboxId, mAccountId);
|
||||
mLoadMessagesTask.execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1338,6 +1338,23 @@ public abstract class EmailContent {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if an {@code accountId} is assigned to any existing account.
|
||||
*/
|
||||
public static boolean isValidId(Context context, long accountId) {
|
||||
Cursor cursor = context.getContentResolver().query(
|
||||
ContentUris.withAppendedId(CONTENT_URI, accountId), ID_PROJECTION,
|
||||
null, null, null);
|
||||
try {
|
||||
if (cursor.moveToFirst()) {
|
||||
return true;
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
return false; // Not found.
|
||||
}
|
||||
|
||||
/**
|
||||
* Override update to enforce a single default account, and do it atomically
|
||||
*/
|
||||
|
@ -167,6 +167,16 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
return Account.CONTENT_URI.buildUpon().appendEncodedPath("" + account.mId).build();
|
||||
}
|
||||
|
||||
public void testAccountIsValidId() {
|
||||
final Account account1 = ProviderTestUtils.setupAccount("account-1", true, mMockContext);
|
||||
final Account account2 = ProviderTestUtils.setupAccount("account-2", true, mMockContext);
|
||||
|
||||
assertTrue(Account.isValidId(mMockContext, account1.mId));
|
||||
assertTrue(Account.isValidId(mMockContext, account2.mId));
|
||||
|
||||
assertFalse(Account.isValidId(mMockContext, 1234567)); // Some random ID
|
||||
}
|
||||
|
||||
private final static String[] MAILBOX_UNREAD_COUNT_PROJECTION = new String [] {
|
||||
MailboxColumns.UNREAD_COUNT
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user