Merge "Flesh out attachment download details"
diff --git a/res/layout-sw600dp/account_switch_spinner_item.xml b/res/layout-sw600dp/account_switch_spinner_item.xml
index ead0665..b0cbab7 100644
--- a/res/layout-sw600dp/account_switch_spinner_item.xml
+++ b/res/layout-sw600dp/account_switch_spinner_item.xml
@@ -17,49 +17,41 @@
 -->
 
     <!-- style="@style/AccountSwitchSpinnerItem" -->
-<LinearLayout
+<RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_height="match_parent"
     android:layout_width="match_parent"
     android:paddingLeft="0dip"
     android:layout_marginLeft="0dip">
 
-    <!-- This spacer is here just to soak up horizontal space. -->
-    <!-- If this is omitted, the spinner triangle is too far from the text. -->
-    <FrameLayout
-        android:id="@+id/spinner_frame"
+    <LinearLayout
+        android:id="@+id/spinner"
         android:layout_width="@dimen/spinner_frame_width"
         android:layout_height="match_parent"
+        android:orientation="vertical"
+        android:gravity="center_vertical"
+        android:background="@drawable/spinner_ab_holo_light"
         android:layout_alignParentLeft="true">
-
-            <!-- style="?android:attr/actionDropDownStyle" -->
-        <LinearLayout
-            android:id="@+id/spinner"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:orientation="vertical"
-            android:gravity="center_vertical">
-            <TextView
-                android:id="@+id/account_spinner_folder"
-                style="@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse"
-                android:singleLine="true"
-                android:ellipsize="end"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content" />
-            <TextView
-                android:id="@+id/account_spinner_account_name"
-                style="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle.Inverse"
-                android:singleLine="true"
-                android:ellipsize="end"
-                android:layout_marginRight="4dp"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content" />
-        </LinearLayout>
-
-    </FrameLayout>
+        <TextView
+            android:id="@+id/account_spinner_folder"
+            style="@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse"
+            android:singleLine="true"
+            android:ellipsize="end"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" />
+        <TextView
+            android:id="@+id/account_spinner_account_name"
+            style="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle.Inverse"
+            android:singleLine="true"
+            android:ellipsize="end"
+            android:layout_marginRight="4dp"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" />
+    </LinearLayout>
 
     <TextView
         android:id="@+id/unread"
-        style="@style/unreadCountActionBarTablet" />
-
-</LinearLayout>
+        android:layout_marginLeft="4dp"
+        style="@style/UnreadCountActionBar"
+        android:layout_toRightOf="@id/spinner" />
+</RelativeLayout>
diff --git a/res/layout/compose_from.xml b/res/layout/compose_from.xml
index a22821e..47ab5a6 100644
--- a/res/layout/compose_from.xml
+++ b/res/layout/compose_from.xml
@@ -39,7 +39,7 @@
         style="@style/RecipientComposeFieldLayout"
         android:layout_height="match_parent">
 
-        <TextView android:id="@+id/account_name"
+        <TextView android:id="@+id/from_account_name"
             android:layout_width="match_parent"
             android:paddingLeft="8dip"
             android:singleLine="true"
diff --git a/res/layout/one_button_button_bar.xml b/res/layout/one_button_button_bar.xml
index 018a177..72910ba 100644
--- a/res/layout/one_button_button_bar.xml
+++ b/res/layout/one_button_button_bar.xml
@@ -34,7 +34,7 @@
         android:measureWithLargestChild="true"
         android:background="@null">
         <Button
-            android:id="@+id/cancel"
+            android:id="@+id/first_button"
             style="?android:attr/buttonBarButtonStyle"
             android:layout_weight="1"
             android:layout_width="0dip"
diff --git a/src/com/android/mail/browse/ConversationCursor.java b/src/com/android/mail/browse/ConversationCursor.java
index 1fafa78..4ea87bc 100644
--- a/src/com/android/mail/browse/ConversationCursor.java
+++ b/src/com/android/mail/browse/ConversationCursor.java
@@ -70,6 +70,8 @@
     private static final String REQUERY_COLUMN = "__requery__";
     // A sentinel value for the "index" of the deleted column; it's an int that is otherwise invalid
     private static final int DELETED_COLUMN_INDEX = -1;
+    // Empty deletion list
+    private static final ArrayList<Integer> EMPTY_DELETION_LIST = new ArrayList<Integer>();
     // The current conversation cursor
     private static ConversationCursor sConversationCursor;
     // The index of the Uri whose data is reflected in the cached row
@@ -462,11 +464,15 @@
         if (DEBUG) {
             LogUtils.d(TAG, "[getRefreshDeletions() called]");
         }
+        // It's possible that the requery cursor is null in the case that loadInBackground() causes
+        // ConversationCursor.create to do a sync() between the time that refreshReady() is called
+        // and the subsequent call to getRefreshDeletions().  This is harmless, and an empty
+        // result list is correct.
+        if (sRequeryCursor == null) {
+            return EMPTY_DELETION_LIST;
+        }
         Cursor deviceCursor = sConversationCursor;
         Cursor serverCursor = sRequeryCursor;
-        // TODO: (mindyp) saw some instability here. Adding an assert to try to
-        // catch it.
-        assert(sRequeryCursor != null);
         ArrayList<Integer> deleteList = new ArrayList<Integer>();
         int serverCount = serverCursor.getCount();
         int deviceCount = deviceCursor.getCount();
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index 83a808b..9866f4f 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -154,6 +154,7 @@
     private QuotedTextView mQuotedTextView;
     private TextView mBodyView;
     private View mFromStatic;
+    private TextView mFromStaticText;
     private View mFromSpinnerWrapper;
     private FromAddressSpinner mFromSpinner;
     private boolean mAddingAttachment;
@@ -295,6 +296,7 @@
         // mail from / save drafts to.
         mFromStatic.setVisibility(
                 showSpinner ? View.GONE : View.VISIBLE);
+        mFromStaticText.setText(mAccount.name);
         mFromSpinnerWrapper.setVisibility(
                 showSpinner ? View.VISIBLE : View.GONE);
     }
@@ -320,6 +322,7 @@
         mQuotedTextView.setRespondInlineListener(this);
         mBodyView = (TextView) findViewById(R.id.body);
         mFromStatic = findViewById(R.id.static_from_content);
+        mFromStaticText = (TextView) findViewById(R.id.from_account_name);
         mFromSpinnerWrapper = findViewById(R.id.spinner_from_content);
         mFromSpinner = (FromAddressSpinner) findViewById(R.id.from_picker);
     }
diff --git a/src/com/android/mail/providers/Message.java b/src/com/android/mail/providers/Message.java
index 57b15e4..a51e6e3 100644
--- a/src/com/android/mail/providers/Message.java
+++ b/src/com/android/mail/providers/Message.java
@@ -159,8 +159,10 @@
             appendRefMessageContent = cursor
                     .getInt(UIProvider.MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN) != 0;
             hasAttachments = cursor.getInt(UIProvider.MESSAGE_HAS_ATTACHMENTS_COLUMN) != 0;
-            attachmentListUri = hasAttachments ? Uri.parse(cursor
-                    .getString(UIProvider.MESSAGE_ATTACHMENT_LIST_URI_COLUMN)) : null;
+            final String attachmentsUri = cursor
+                    .getString(UIProvider.MESSAGE_ATTACHMENT_LIST_URI_COLUMN);
+            attachmentListUri = hasAttachments && !TextUtils.isEmpty(attachmentsUri) ? Uri
+                    .parse(attachmentsUri) : null;
             messageFlags = cursor.getLong(UIProvider.MESSAGE_FLAGS_COLUMN);
             joinedAttachmentInfos = cursor
                     .getString(UIProvider.MESSAGE_JOINED_ATTACHMENT_INFOS_COLUMN);
diff --git a/src/com/android/mail/providers/protos/mock/MockUiProvider.java b/src/com/android/mail/providers/protos/mock/MockUiProvider.java
index 98082e8..67464e4 100644
--- a/src/com/android/mail/providers/protos/mock/MockUiProvider.java
+++ b/src/com/android/mail/providers/protos/mock/MockUiProvider.java
@@ -34,6 +34,7 @@
 import com.android.mail.providers.UIProvider.FolderCapabilities;
 import com.android.mail.providers.UIProvider.FolderColumns;
 import com.android.mail.providers.UIProvider.MessageColumns;
+import com.android.mail.providers.UIProvider.SettingsColumns;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
@@ -126,6 +127,10 @@
                 ImmutableList.of(folderDetailsMap1));
         builder.put(accountDetailsMap0.get(AccountColumns.FOLDER_LIST_URI).toString(),
                 ImmutableList.of(folderDetailsMap0, folderDetailsMap1));
+        Map<String, Object> settings0 = createSettingsDetailsMap(folderDetailsMap0.get(
+                FolderColumns.URI).toString());
+        builder.put(accountDetailsMap0.get(AccountColumns.SETTINGS_QUERY_URI).toString(),
+                ImmutableList.of(settings0));
 
         Map<String, Object> folderDetailsMap2 = createFolderDetailsMap(2, "two", 2, 2);
         builder.put(folderDetailsMap2.get(FolderColumns.URI).toString(),
@@ -135,6 +140,10 @@
                 ImmutableList.of(folderDetailsMap3));
         builder.put(accountDetailsMap1.get(AccountColumns.FOLDER_LIST_URI).toString(),
                 ImmutableList.of(folderDetailsMap2, folderDetailsMap3));
+        Map<String, Object> settings1 = createSettingsDetailsMap(folderDetailsMap2.get(
+                FolderColumns.URI).toString());
+        builder.put(accountDetailsMap1.get(AccountColumns.SETTINGS_QUERY_URI).toString(),
+                ImmutableList.of(settings1));
 
         Map<String, Object> conv2 = createConversationDetailsMap("zeroConv2".hashCode(),
                 "zeroConv2", 0);
@@ -161,6 +170,12 @@
         MOCK_QUERY_RESULTS = builder.build();
     }
 
+    private static Map<String, Object> createSettingsDetailsMap(String uri) {
+        Map<String, Object> settingsMap = Maps.newHashMap();
+        settingsMap.put(SettingsColumns.DEFAULT_INBOX, uri);
+        return settingsMap;
+    }
+
     private static Map<String, Object> createConversationDetailsMap(int conversationId,
             String subject, int hasAttachments) {
         final String conversationUri = "content://" + AUTHORITY + "/conversation/" + conversationId;
diff --git a/src/com/android/mail/ui/FolderSelectionActivity.java b/src/com/android/mail/ui/FolderSelectionActivity.java
index 137cc60..bbf8093 100644
--- a/src/com/android/mail/ui/FolderSelectionActivity.java
+++ b/src/com/android/mail/ui/FolderSelectionActivity.java
@@ -89,9 +89,11 @@
         }
 
         mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT_SHORTCUT);
-        Button cancelButton = (Button) findViewById(R.id.cancel);
-        cancelButton.setVisibility(View.VISIBLE);
-        cancelButton.setOnClickListener(this);
+        Button firstButton = (Button) findViewById(R.id.first_button);
+        firstButton.setVisibility(View.VISIBLE);
+        // TODO(mindyp) disable the manage labels buttons until we have a mange labels screen.
+        firstButton.setEnabled(false);
+        firstButton.setOnClickListener(this);
 
         FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
         Fragment fragment = FolderListFragment.newInstance(this, mAccount.folderListUri);
diff --git a/src/com/android/mail/ui/OnePaneController.java b/src/com/android/mail/ui/OnePaneController.java
index f2bcd3a..9074050 100644
--- a/src/com/android/mail/ui/OnePaneController.java
+++ b/src/com/android/mail/ui/OnePaneController.java
@@ -205,6 +205,7 @@
     }
 
     private void transitionToInbox() {
+        mViewMode.enterConversationListMode();
         ConversationListContext listContext = ConversationListContext.forFolder(mContext,
                 mAccount, mInbox);
         // Set the correct context for what the conversation view will be now.
@@ -244,9 +245,9 @@
     }
 
     private void transitionBackToConversationListMode() {
+        mViewMode.enterConversationListMode();
         mActivity.getFragmentManager().popBackStack(mLastConversationTransactionId,
                 FragmentManager.POP_BACK_STACK_INCLUSIVE);
-        mViewMode.enterConversationListMode();
         resetActionBarIcon();
     }
 }