Guard against invalid selections in spinner

This is a stop gap fix for b/4584196
There was a race condition in which the actionbar callback happened
prior to the fragments being ready, and so any callbacks on a mailbox
would explode (and the spinner mistakenly thought the header was a
        mailbox)

Change-Id: Id0a24d252472faf97088175b5c413ef554dc3b76
This commit is contained in:
Ben Komalo 2011-06-09 11:38:11 -07:00
parent b4f6404cd1
commit 479fdf03aa
3 changed files with 13 additions and 2 deletions

View File

@ -209,6 +209,12 @@ public class AccountSelectorAdapter extends CursorAdapter {
return (c.getLong(c.getColumnIndex(ROW_TYPE)) == ROW_TYPE_ACCOUNT);
}
public boolean isMailboxItem(int position) {
Cursor c = getCursor();
c.moveToPosition(position);
return (c.getLong(c.getColumnIndex(ROW_TYPE)) == ROW_TYPE_MAILBOX);
}
private String getAccountDisplayName(int position) {
final Cursor c = getCursor();
return c.moveToPosition(position) ? getAccountDisplayName(c) : null;

View File

@ -17,6 +17,7 @@
package com.android.email.activity;
import com.android.email.R;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.provider.Mailbox;
@ -27,6 +28,7 @@ import android.content.Context;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
@ -236,7 +238,7 @@ public class ActionBarController {
if (mAccountsSelectorAdapter.isAccountItem(itemPosition)
&& itemId != mCallback.getUIAccountId()) {
mCallback.onAccountSelected(itemId);
} else if (!mAccountsSelectorAdapter.isAccountItem(itemPosition)) {
} else if (mAccountsSelectorAdapter.isMailboxItem(itemPosition)) {
mCallback.onMailboxSelected(itemId);
// We need to update the selection, otherwise the user is unable to select the
// recent folder a second time w/o first selecting another item in the spinner
@ -244,6 +246,9 @@ public class ActionBarController {
if (selectedPosition != AccountSelectorAdapter.UNKNOWN_POSITION) {
mActionBar.setSelectedNavigationItem(selectedPosition);
}
} else {
Log.i(Logging.LOG_TAG,
"Invalid type selected in ActionBarController at index " + itemPosition);
}
return true;
}

View File

@ -239,7 +239,7 @@ class UIControllerOnePane extends UIControllerBase {
if (mailboxId == Mailbox.NO_MAILBOX) {
showAllMailboxes();
} else {
UIControllerOnePane.this.openMailbox(getUIAccountId(), mailboxId);
openMailbox(getUIAccountId(), mailboxId);
}
}