Merge "Ignore the first navigation to position One, not zero" into jb-ub-mail
diff --git a/src/com/android/mail/AccountSpinnerAdapter.java b/src/com/android/mail/AccountSpinnerAdapter.java
index c3188e9..659c733 100644
--- a/src/com/android/mail/AccountSpinnerAdapter.java
+++ b/src/com/android/mail/AccountSpinnerAdapter.java
@@ -41,10 +41,6 @@
 public class AccountSpinnerAdapter extends BaseAdapter {
     private final LayoutInflater mInflater;
     /**
-     * The position of the current account being viewed as an index into the mAccounts array.
-     */
-    private int mCurrentAccountPos = -1;
-    /**
      * The position of the current account being viewed.
      */
     private Account mCurrentAccount = null;
@@ -149,25 +145,7 @@
         mShowAllFoldersItem = showAllFolders;
     }
 
-    /**
-     * Find the position of the given needle in the given array of accounts.
-     * @param haystack the array of accounts to search
-     * @param needle the URI of account to find
-     * @return a position between 0 and haystack.length-1 if an account is found, -1 if not found.
-     */
-    private static int findPositionOfAccount(Account[] haystack, Uri needle) {
-        if (haystack != null && haystack.length > 0 && needle != null) {
-            // Need to go through the list of current accounts, and fix the
-            // position.
-            for (int i = 0, size = haystack.length; i < size; ++i) {
-                if (haystack[i].uri.equals(needle)) {
-                    LogUtils.d(LOG_TAG, "findPositionOfAccount: Found needle at position %d", i);
-                    return i;
-                }
-            }
-        }
-        return -1;
-    }
+
     /**
      * Set the accounts for this spinner.
      * @param accounts
@@ -177,8 +155,8 @@
         mAllAccounts = accounts;
         mNumAccounts = accounts.length;
         if (!isCurrentAccountInvalid()) {
-            mCurrentAccountPos = findPositionOfAccount(accounts, currentAccount);
-            LogUtils.d(LOG_TAG, "setAccountArray: mCurrentAccountPos = %d", mCurrentAccountPos);
+            final int pos = Account.findPosition(accounts, currentAccount);
+            LogUtils.d(LOG_TAG, "setAccountArray: mCurrentAccountPos = %d", pos);
         }
         notifyDataSetChanged();
     }
@@ -213,9 +191,9 @@
             return false;
         }
         mCurrentAccount = account;
-        mCurrentAccountPos = findPositionOfAccount(mAllAccounts, account.uri);
-        LogUtils.d(LOG_TAG, "setCurrentAccount: mCurrentAccountPos = %d", mCurrentAccountPos);
-        if (mCurrentAccountPos >= 0) {
+        final int pos = Account.findPosition(mAllAccounts, account.uri);
+        LogUtils.d(LOG_TAG, "setCurrentAccount: mCurrentAccountPos = %d", pos);
+        if (pos >= 0) {
             requestRecentFoldersAndRedraw();
         }
         return true;
@@ -270,7 +248,7 @@
     }
 
     private String getCurrentAccountName() {
-        if (isCurrentAccountInvalid() || mCurrentAccountPos == -1) {
+        if (isCurrentAccountInvalid()) {
             return "";
         }
         return mCurrentAccount.name;
diff --git a/src/com/android/mail/providers/Account.java b/src/com/android/mail/providers/Account.java
index 878e163..52cef65 100644
--- a/src/com/android/mail/providers/Account.java
+++ b/src/com/android/mail/providers/Account.java
@@ -502,4 +502,24 @@
             return new Account[size];
         }
     };
+
+    /**
+     * Find the position of the given needle in the given array of accounts.
+     * @param haystack the array of accounts to search
+     * @param needle the URI of account to find
+     * @return a position between 0 and haystack.length-1 if an account is found, -1 if not found.
+     */
+    public static int findPosition(Account[] haystack, Uri needle) {
+        if (haystack != null && haystack.length > 0 && needle != null) {
+            // Need to go through the list of current accounts, and fix the
+            // position.
+            for (int i = 0, size = haystack.length; i < size; ++i) {
+                if (haystack[i].uri.equals(needle)) {
+                    LogUtils.d(LOG_TAG, "findPositionOfAccount: Found needle at position %d", i);
+                    return i;
+                }
+            }
+        }
+        return -1;
+    }
 }
diff --git a/src/com/android/mail/ui/MailActionBarView.java b/src/com/android/mail/ui/MailActionBarView.java
index 591131d..5d1c3f7 100644
--- a/src/com/android/mail/ui/MailActionBarView.java
+++ b/src/com/android/mail/ui/MailActionBarView.java
@@ -299,7 +299,7 @@
      * @param position the position selected in the drop down.
      */
     private boolean ignoreFirstNavigation(int position) {
-        if (mIgnoreFirstNavigation && position == 0 && mAccount != null) {
+        if (mIgnoreFirstNavigation && position == 1 && mAccount != null) {
             // Ignore the first navigation item selected because it is the list initializing
             // We already have an account.
             LogUtils.d(LOG_TAG, "ignoreFirstNavigation: Ignoring navigation to position 0."