Use real default inbox setting.

Change-Id: Id8692cae322f1c0eea369ebc79c856da504f8390
diff --git a/src/com/android/mail/providers/Account.java b/src/com/android/mail/providers/Account.java
index 50170bb..4eb59ed 100644
--- a/src/com/android/mail/providers/Account.java
+++ b/src/com/android/mail/providers/Account.java
@@ -296,12 +296,6 @@
         return null;
     }
 
-    public Folder getAccountInbox() {
-        // TODO: (mindyp) fill in with call to settings or reading of account settings
-        // to get the default inbox for this account.
-        return Folder.getInbox();
-    }
-
     @SuppressWarnings("hiding")
     public static final Creator<Account> CREATOR = new Creator<Account>() {
         @Override
diff --git a/src/com/android/mail/providers/Folder.java b/src/com/android/mail/providers/Folder.java
index 8a1674c..4a86187 100644
--- a/src/com/android/mail/providers/Folder.java
+++ b/src/com/android/mail/providers/Folder.java
@@ -323,13 +323,4 @@
     public boolean supportsCapability(int capability) {
         return (capabilities & capability) != 0;
     }
-
-    /**
-     * Get a fake inbox folder.
-     */
-    public static Folder getInbox() {
-        Folder inbox = new Folder();
-        inbox.name = "inbox";
-        return inbox;
-    }
 }
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 66f6be9..67f066f 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -124,7 +124,7 @@
         }
     };
     private final Set<Uri> mCurrentAccountUris = Sets.newHashSet();
-    private Settings mCachedSettings;
+    protected Settings mCachedSettings;
 
     protected static final String LOG_TAG = new LogUtils().getLogTag();
     private static final int ACCOUNT_CURSOR_LOADER = 0;
@@ -272,6 +272,7 @@
 
     public void onSettingsChanged(Settings settings) {
         mCachedSettings = settings;
+        resetActionBarIcon();
     }
 
     private void fetchAccountFolderInfo() {
diff --git a/src/com/android/mail/ui/FolderSelectionActivity.java b/src/com/android/mail/ui/FolderSelectionActivity.java
index d57d8cb..36f7d7d 100644
--- a/src/com/android/mail/ui/FolderSelectionActivity.java
+++ b/src/com/android/mail/ui/FolderSelectionActivity.java
@@ -165,8 +165,7 @@
                  * account, calculate the human readable name of the label and
                  * use it as the shortcut name, etc...
                  */
-                final Intent clickIntent = Utils.createViewConversationIntent(this, mAccount,
-                        mSelectedFolder, UIProvider.INVALID_CONVERSATION_ID);
+                final Intent clickIntent = Utils.createViewFolderIntent(mSelectedFolder, mAccount);
                 resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, clickIntent);
                 resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                         Intent.ShortcutIconResource.fromContext(this,
diff --git a/src/com/android/mail/ui/OnePaneController.java b/src/com/android/mail/ui/OnePaneController.java
index 0249f04..f2bcd3a 100644
--- a/src/com/android/mail/ui/OnePaneController.java
+++ b/src/com/android/mail/ui/OnePaneController.java
@@ -20,6 +20,7 @@
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
+import android.net.Uri;
 import android.os.Bundle;
 
 import com.android.mail.ConversationListContext;
@@ -76,7 +77,10 @@
     @Override
     public void resetActionBarIcon() {
         final int mode = mViewMode.getMode();
-        if (!inInbox() || (mode == ViewMode.CONVERSATION_LIST && mConvListContext.isSearchResult())
+        // If the settings aren't loaded yet, we may not know what the default
+        // inbox is, so err toward this being the account inbox.
+        if ((mCachedSettings != null && mConvListContext != null && !inInbox())
+                || (mode == ViewMode.CONVERSATION_LIST && mConvListContext.isSearchResult())
                 || mode == ViewMode.CONVERSATION || mode == ViewMode.FOLDER_LIST) {
             mActionBarView.setBackButton();
         } else {
@@ -85,9 +89,9 @@
     }
 
     private boolean inInbox() {
-        return mConvListContext != null && mConvListContext.folder != null ?
-                (!mConvListContext.isSearchResult() && mConvListContext.folder.name
-                .toLowerCase().equals(mAccount.getAccountInbox().name.toLowerCase())) : false;
+        Uri inboxUri = mCachedSettings != null ? mCachedSettings.defaultInbox : null;
+        return mConvListContext != null && mConvListContext.folder != null ? (!mConvListContext
+                .isSearchResult() && mConvListContext.folder.uri.equals(inboxUri)) : false;
     }
 
     @Override
diff --git a/src/com/android/mail/utils/Utils.java b/src/com/android/mail/utils/Utils.java
index b674b4a..d311242 100644
--- a/src/com/android/mail/utils/Utils.java
+++ b/src/com/android/mail/utils/Utils.java
@@ -596,30 +596,6 @@
     }
 
     /**
-     * @return an intent which, if launched, will display the corresponding conversation
-     */
-    public static Intent createViewConversationIntent(Context context,
-            Account account, Folder folder, long conversationId) {
-        final Intent intent = new Intent(Intent.ACTION_VIEW);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
-        Uri.Builder builder = new Uri.Builder();
-        builder.scheme("content");
-        builder.authority(UIProvider.AUTHORITY);
-        builder.appendEncodedPath("account/" + account);
-        final String intentLabel = folder.name != null ? folder.name
-                : account.getAccountInbox().name;
-        builder.appendPath("label");
-        builder.appendPath(intentLabel);
-
-        if (conversationId != UIProvider.INVALID_CONVERSATION_ID) {
-            builder.appendEncodedPath("conversationId/" + conversationId);
-        }
-        intent.setDataAndType(builder.build(), "application/" + UIProvider.AUTHORITY);
-
-        return intent;
-    }
-
-    /**
      * Helper method to show context-aware Gmail help.
      *
      * @param context Context to be used to open the help.