Merge "Single Actionbar: no more split" into jb-ub-mail-ur9
diff --git a/res/layout/folder_expand_item.xml b/res/layout/folder_expand_item.xml
new file mode 100644
index 0000000..5041582
--- /dev/null
+++ b/res/layout/folder_expand_item.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2013 Google Inc.
+     Licensed to The Android Open Source Project.
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- This is a button for expanding/collapsing emails in FLF  -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/folder_expand_item"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="center_vertical">
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/message_details_header_bottom_border_height"
+        android:visibility="visible"
+        android:background="@color/conv_subject_border" />
+
+    <TextView
+        android:id="@+id/folder_expand_text"
+        android:layout_width="match_parent"
+        android:layout_height="48dip"
+        android:layout_marginLeft="@dimen/folder_list_item_left_margin"
+        android:gravity="center_vertical"
+        android:ellipsize="end"
+        android:singleLine="true"
+        android:textAllCaps="true"
+        android:textColor="@color/folder_list_heading_text_color"/>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/message_details_header_bottom_border_height"
+        android:visibility="visible"
+        android:background="@color/conv_subject_border" />
+
+    <ImageView
+        android:layout_gravity="top|right"
+        android:layout_marginTop="14dip"
+        android:layout_marginRight="14dip"
+        android:id="@+id/details_expander"
+        style="@style/MessageHeaderExpanderMinimizedStyle" />
+</FrameLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 525c770..c44e9af 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -167,6 +167,10 @@
     </string>
     <!-- Title for the Folder list screen. [CHAR LIMIT = 30] -->
     <string name="folder_list_title">Folders</string>
+    <!-- Folder list item: show more folders. [CHAR LIMIT = 30] -->
+    <string name="folder_list_more">More</string>
+    <!-- Folder list item: show all accounts. [CHAR LIMIT = 30] -->
+    <string name="folder_list_show_all_accounts">More accounts</string>
     <!-- action bar sub title for manage folder mode. [CHAR LIMIT = 30] -->
     <string name="manage_folders_subtitle">Sync &amp; notify</string>
     <!-- Menu item: options for this folder. When source text cannot be translated within the char limit, please translate the shorter "Folder options" instead. [CHAR LIMIT = 30] -->
diff --git a/src/com/android/mail/adapter/DrawerItem.java b/src/com/android/mail/adapter/DrawerItem.java
index 194828d..f013a03 100644
--- a/src/com/android/mail/adapter/DrawerItem.java
+++ b/src/com/android/mail/adapter/DrawerItem.java
@@ -40,6 +40,8 @@
     public final Folder mFolder;
     public final Account mAccount;
     public final int mResource;
+    /** True if expand item view for expanding accounts. False otherwise */
+    public final boolean mIsExpandForAccount;
     /** Either {@link #VIEW_ACCOUNT}, {@link #VIEW_FOLDER} or {@link #VIEW_HEADER} */
     public final int mType;
     /** A normal folder, also a child, if a parent is specified. */
@@ -48,6 +50,9 @@
     public static final int VIEW_HEADER = 1;
     /** An account object, which allows switching accounts rather than folders. */
     public static final int VIEW_ACCOUNT = 2;
+    /** An expandable object for expanding/collapsing more of the list */
+    public static final int VIEW_MORE = 3;
+    /** TODO: On adding another type, be sure to change getViewTypes() */
 
     /** The parent activity */
     private final ControllableActivity mActivity;
@@ -56,7 +61,7 @@
     /**
      * Either {@link #FOLDER_SYSTEM}, {@link #FOLDER_RECENT} or {@link #FOLDER_USER} when
      * {@link #mType} is {@link #VIEW_FOLDER}, or an {@link #ACCOUNT} in the case of
-     * accounts, and {@link #INERT_HEADER} otherwise.
+     * accounts, {@link #EXPAND} for expand blocks, and {@link #INERT_HEADER} otherwise.
      */
     public final int mFolderType;
     /** An unclickable text-header visually separating the different types. */
@@ -69,6 +74,8 @@
     public static final int FOLDER_USER = 3;
     /** An entry for the accounts the user has on the device. */
     public static final int ACCOUNT = 4;
+    /** A clickable block to expand list as requested */
+    public static final int EXPAND = 5;
 
     /** True if this view is enabled, false otherwise. */
     private boolean isEnabled = false;
@@ -89,6 +96,7 @@
         mType = VIEW_FOLDER;
         mFolderType = folderType;
         mPosition = cursorPosition;
+        mIsExpandForAccount = false;
     }
 
     /**
@@ -103,6 +111,7 @@
         mResource = -1;
         mFolderType = ACCOUNT;
         mAccount = account;
+        mIsExpandForAccount = false;
     }
 
     /**
@@ -117,6 +126,23 @@
         mType = VIEW_HEADER;
         mFolderType = INERT_HEADER;
         mAccount = null;
+        mIsExpandForAccount = false;
+    }
+
+    /**
+     * Creates an item for expanding or contracting for emails/items
+     * @param resource the string resource: R.string.folder_list_*
+     * @param isExpand true if "more" and false if "less"
+     */
+    public DrawerItem(ControllableActivity activity, int resource, boolean isExpandForAccount) {
+        mActivity = activity;
+        mInflater = LayoutInflater.from(mActivity.getActivityContext());
+        mFolder = null;
+        mType = VIEW_MORE;
+        mResource = resource;
+        mFolderType = EXPAND;
+        mAccount = null;
+        mIsExpandForAccount = isExpandForAccount;
     }
 
     public View getView(int position, View convertView, ViewGroup parent) {
@@ -131,6 +157,9 @@
             case VIEW_ACCOUNT:
                 result = getAccountView(position, convertView, parent);
                 break;
+            case VIEW_MORE:
+                result = getExpandView(position, convertView, parent);
+                break;
             default:
                 LogUtils.wtf(LOG_TAG, "DrawerItem.getView(%d) for an invalid type!", mType);
                 result = null;
@@ -139,6 +168,15 @@
     }
 
     /**
+     * Book-keeping for how many different view types there are. Be sure to
+     * increment this appropriately once adding more types as drawer items
+     * @return number of different types of view items
+     */
+    public static int getViewTypes() {
+        return VIEW_MORE + 1;
+    }
+
+    /**
      * Returns whether this view is enabled or not.
      * @return
      */
@@ -153,6 +191,9 @@
             case VIEW_ACCOUNT:
                 // Accounts are only enabled if they are not the current account.
                 return !currentAccountUri.equals(mAccount.uri);
+            case VIEW_MORE:
+                // 'Expand/Collapse' items are always enabled.
+                return true;
             default:
                 LogUtils.wtf(LOG_TAG, "DrawerItem.isItemEnabled() for invalid type %d", mType);
                 return false;
@@ -176,6 +217,9 @@
             case VIEW_ACCOUNT:
                 // Accounts are never highlighted
                 return false;
+            case VIEW_MORE:
+                // Expand/Collapse items are never highlighted
+                return false;
             default:
                 LogUtils.wtf(LOG_TAG, "DrawerItem.isHighlighted() for invalid type %d", mType);
                 return false;
@@ -247,5 +291,28 @@
         Folder.setIcon(mFolder, (ImageView) folderItemView.findViewById(R.id.folder_icon));
         return folderItemView;
     }
+
+    /**
+     * Return a view for the 'Expand/Collapse' item.
+     * @param position a zero indexed position into the top level list.
+     * @param convertView a view, possibly null, to be recycled.
+     * @param parent the parent hosting this view.
+     * @return a view showing an item for folder/account expansion at given position.
+     */
+    private View getExpandView(int position, View convertView, ViewGroup parent) {
+        final ViewGroup headerView;
+        if (convertView != null) {
+            headerView = (ViewGroup) convertView;
+        } else {
+            headerView = (ViewGroup) mInflater.inflate(
+                    R.layout.folder_expand_item, parent, false);
+        }
+        TextView direction =
+                (TextView)headerView.findViewById(R.id.folder_expand_text);
+        if(direction != null) {
+            direction.setText(mResource);
+        }
+        return headerView;
+    }
 }
 
diff --git a/src/com/android/mail/providers/Settings.java b/src/com/android/mail/providers/Settings.java
index 9400828..6cb7c3a 100644
--- a/src/com/android/mail/providers/Settings.java
+++ b/src/com/android/mail/providers/Settings.java
@@ -360,6 +360,19 @@
     }
 
     /**
+     * @return true if {@link UIProvider.ConversationViewMode.OVERVIEW} mode is set. In the event
+     * that the setting is not yet set, fall back to
+     * {@link UIProvider.ConversationViewMode.DEFAULT}.
+     */
+    public boolean isOverviewMode() {
+        final boolean isDefined = (conversationViewMode
+                != UIProvider.ConversationViewMode.UNDEFINED);
+        final int val = (conversationViewMode != UIProvider.ConversationViewMode.UNDEFINED) ?
+                conversationViewMode : UIProvider.ConversationViewMode.DEFAULT;
+        return (val == UIProvider.ConversationViewMode.OVERVIEW);
+    }
+
+    /**
      * Return the swipe setting for the settings provided. It is safe to pass this method
      * a null object. It always returns a valid {@link Swipe} setting.
      * @return the auto advance setting, a constant from {@link Swipe}
diff --git a/src/com/android/mail/providers/UIProvider.java b/src/com/android/mail/providers/UIProvider.java
index 752ccf7..c624e10 100644
--- a/src/com/android/mail/providers/UIProvider.java
+++ b/src/com/android/mail/providers/UIProvider.java
@@ -1931,6 +1931,7 @@
          * require panning
          */
         public static final int READING = 1;
+        public static final int DEFAULT = OVERVIEW;
     }
 
     public static final class SnapHeaderValue {
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 65b55fb..f2f86fb 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -2800,7 +2800,8 @@
                     return loader;
                 case LOADER_RECENT_FOLDERS:
                     LogUtils.d(LOG_TAG, "LOADER_RECENT_FOLDERS created");
-                    if (mAccount != null && mAccount.recentFolderListUri != null) {
+                    if (mAccount != null && mAccount.recentFolderListUri != null
+                            && !mAccount.recentFolderListUri.equals(Uri.EMPTY)) {
                         return new ObjectCursorLoader<Folder>(mContext,
                                 mAccount.recentFolderListUri, everything, Folder.FACTORY);
                     }
diff --git a/src/com/android/mail/ui/ConversationViewFragment.java b/src/com/android/mail/ui/ConversationViewFragment.java
index 10f32b3..7bed51b 100644
--- a/src/com/android/mail/ui/ConversationViewFragment.java
+++ b/src/com/android/mail/ui/ConversationViewFragment.java
@@ -1037,7 +1037,7 @@
     }
 
     private static boolean isOverviewMode(Account acct) {
-        return acct.settings.conversationViewMode == UIProvider.ConversationViewMode.OVERVIEW;
+        return acct.settings.isOverviewMode();
     }
 
     private void setupOverviewMode() {
diff --git a/src/com/android/mail/ui/FolderListFragment.java b/src/com/android/mail/ui/FolderListFragment.java
index 61525b3..d30b3f0 100644
--- a/src/com/android/mail/ui/FolderListFragment.java
+++ b/src/com/android/mail/ui/FolderListFragment.java
@@ -59,6 +59,8 @@
     private Uri mFolderListUri;
     /** True if you want a sectioned FolderList, false otherwise. */
     private boolean mIsSectioned;
+    /** Is the current device using tablet UI (true if 2-pane, false if 1-pane) */
+    private boolean mIsTabletUI;
     /** An {@link ArrayList} of {@link FolderType}s to exclude from displaying. */
     private ArrayList<Integer> mExcludedFolderTypes;
     /** Object that changes folders on our behalf. */
@@ -83,8 +85,12 @@
     private static final String ARG_FOLDER_URI = "arg-folder-list-uri";
     /** Key to store {@link #mIsSectioned} */
     private static final String ARG_IS_SECTIONED = "arg-is-sectioned";
+    /** Key to store {@link #mIsTabletUI} */
+    private static final String ARG_IS_TABLET_UI = "arg-is-tablet-ui";
     /** Key to store {@link #mExcludedFolderTypes} */
     private static final String ARG_EXCLUDED_FOLDER_TYPES = "arg-excluded-folder-types";
+    /** Should the {@link FolderListFragment} show less labels to begin with? */
+    private static final boolean ARE_ITEMS_COLLAPSED = true;
 
     private static final String BUNDLE_LIST_STATE = "flf-list-state";
     private static final String BUNDLE_SELECTED_FOLDER = "flf-selected-folder";
@@ -137,21 +143,24 @@
     /**
      * Creates a new instance of {@link ConversationListFragment}, initialized
      * to display conversation list context.
-     * @param isSectioned TODO(viki):
+     * @param isSectioned True if sections should be shown for folder list
+     * @param isTabletUI True if two-pane layout, false if not
      */
     public static FolderListFragment newInstance(Folder parentFolder, Uri folderUri,
-            boolean isSectioned) {
-        return newInstance(parentFolder, folderUri, isSectioned, null);
+            boolean isSectioned, boolean isTabletUI) {
+        return newInstance(parentFolder, folderUri, isSectioned, null, isTabletUI);
     }
 
     /**
      * Creates a new instance of {@link ConversationListFragment}, initialized
      * to display conversation list context.
-     * @param isSectioned TODO(viki):
+     * @param isSectioned True if sections should be shown for folder list
      * @param excludedFolderTypes A list of {@link FolderType}s to exclude from displaying
+     * @param isTabletUI True if two-pane layout, false if not
      */
     public static FolderListFragment newInstance(Folder parentFolder, Uri folderUri,
-            boolean isSectioned, final ArrayList<Integer> excludedFolderTypes) {
+            boolean isSectioned, final ArrayList<Integer> excludedFolderTypes,
+            boolean isTabletUI) {
         final FolderListFragment fragment = new FolderListFragment();
         final Bundle args = new Bundle();
         if (parentFolder != null) {
@@ -159,6 +168,7 @@
         }
         args.putString(ARG_FOLDER_URI, folderUri.toString());
         args.putBoolean(ARG_IS_SECTIONED, isSectioned);
+        args.putBoolean(ARG_IS_TABLET_UI, isTabletUI);
         if (excludedFolderTypes != null) {
             args.putIntegerArrayList(ARG_EXCLUDED_FOLDER_TYPES, excludedFolderTypes);
         }
@@ -222,7 +232,12 @@
             mCursorAdapter = new HierarchicalFolderListAdapter(null, mParentFolder);
             selectedFolder = mActivity.getHierarchyFolder();
         } else {
-            mCursorAdapter = new FolderListAdapter(mIsSectioned);
+            // Initiate FLA with accounts and folders collapsed in the list
+            // The second param is for whether folders should be collapsed
+            // The third param is for whether accounts should be collapsed
+            mCursorAdapter = new FolderListAdapter(mIsSectioned,
+                    !mIsTabletUI && ARE_ITEMS_COLLAPSED,
+                    !mIsTabletUI && ARE_ITEMS_COLLAPSED);
             selectedFolder = controller == null ? null : controller.getFolder();
         }
         // Is the selected folder fresher than the one we have restored from a bundle?
@@ -241,6 +256,7 @@
         mFolderListUri = Uri.parse(args.getString(ARG_FOLDER_URI));
         mParentFolder = (Folder) args.getParcelable(ARG_PARENT_FOLDER);
         mIsSectioned = args.getBoolean(ARG_IS_SECTIONED);
+        mIsTabletUI = args.getBoolean(ARG_IS_TABLET_UI);
         mExcludedFolderTypes = args.getIntegerArrayList(ARG_EXCLUDED_FOLDER_TYPES);
         final View rootView = inflater.inflate(R.layout.folder_list, null);
         mListView = (ListView) rootView.findViewById(android.R.id.list);
@@ -328,16 +344,25 @@
         final Folder folder;
         if (item instanceof DrawerItem) {
             final DrawerItem folderItem = (DrawerItem) item;
-            // Could be a folder or an account.
-            if (mCursorAdapter.getItemType(folderItem) == DrawerItem.VIEW_ACCOUNT) {
+            // Could be a folder, account, or expand block.
+            final int itemType = mCursorAdapter.getItemType(folderItem);
+            if (itemType == DrawerItem.VIEW_ACCOUNT) {
                 // Account, so switch.
                 folder = null;
                 final Account account = mCursorAdapter.getFullAccount(folderItem);
                 mAccountChanger.changeAccount(account);
-            } else {
+            } else if (itemType == DrawerItem.VIEW_FOLDER) {
                 // Folder type, so change folders only.
                 folder = mCursorAdapter.getFullFolder(folderItem);
                 mSelectedFolderType = folderItem.mFolderType;
+            } else {
+                // Block for expanding/contracting labels/accounts
+                folder = null;
+                if(!folderItem.mIsExpandForAccount) {
+                    mCursorAdapter.toggleShowLessFolders();
+                } else {
+                    mCursorAdapter.toggleShowLessAccounts();
+                }
             }
         } else if (item instanceof Folder) {
             folder = (Folder) item;
@@ -352,9 +377,6 @@
             folder.parent = folder.equals(mParentFolder) ? null : mParentFolder;
             // Go to the conversation list for this folder.
             mFolderChanger.onFolderSelected(folder);
-        } else {
-            LogUtils.d(LOG_TAG, "FolderListFragment unable to get a full fledged folder" +
-                    " to hand to the listener for position %d", position);
         }
     }
 
@@ -402,15 +424,20 @@
     private interface FolderListFragmentCursorAdapter extends ListAdapter {
         /** Update the folder list cursor with the cursor given here. */
         void setCursor(Cursor cursor);
+        /** Toggles showing more accounts or less accounts. */
+        boolean toggleShowLessAccounts();
+        /** Toggles showing more folders or less. */
+        boolean toggleShowLessFolders();
         /**
-         * Given an item, find the type of the item, which is either {@link
-         * DrawerItem#VIEW_FOLDER} or {@link DrawerItem#VIEW_ACCOUNT}
+         * Given an item, find the type of the item, which is {@link
+         * DrawerItem#VIEW_FOLDER}, {@link DrawerItem#VIEW_ACCOUNT} or
+         * {@link DrawerItem#VIEW_MORE}
          * @return the type of the item.
          */
         int getItemType(DrawerItem item);
-        /** Get the folder associated with this item **/
+        /** Get the folder associated with this item. **/
         Folder getFullFolder(DrawerItem item);
-        /** Get the account associated with this item **/
+        /** Get the account associated with this item. **/
         Account getFullAccount(DrawerItem item);
         /** Remove all observers and destroy the object. */
         void destroy();
@@ -430,6 +457,11 @@
             }
         };
 
+        /** After given number of accounts, show "more" until expanded. */
+        private static final int MAX_ACCOUNTS = 2;
+        /** After the given number of labels, show "more" until expanded. */
+        private static final int MAX_FOLDERS = 7;
+
         private final RecentFolderList mRecentFolders;
         /** True if the list is sectioned, false otherwise */
         private final boolean mIsSectioned;
@@ -437,13 +469,15 @@
         private final List<DrawerItem> mItemList = new ArrayList<DrawerItem>();
         /** Cursor into the folder list. This might be null. */
         private Cursor mCursor = null;
+        private boolean mShowLessFolders;
+        private boolean mShowLessAccounts;
 
         /**
          * Creates a {@link FolderListAdapter}.This is a flat folder list of all the folders for the
          * given account.
          * @param isSectioned TODO(viki):
          */
-        public FolderListAdapter(boolean isSectioned) {
+        public FolderListAdapter(boolean isSectioned, boolean showLess, boolean showLessAccounts) {
             super();
             mIsSectioned = isSectioned;
             final RecentFolderController controller = mActivity.getRecentFolderController();
@@ -452,6 +486,8 @@
             } else {
                 mRecentFolders = null;
             }
+            mShowLessFolders = showLess;
+            mShowLessAccounts = showLessAccounts;
         }
 
         @Override
@@ -481,7 +517,7 @@
         @Override
         public int getViewTypeCount() {
             // Accounts, headers and folders
-            return 3;
+            return DrawerItem.getViewTypes();
         }
 
         @Override
@@ -531,19 +567,68 @@
         }
 
         /**
-         * Recalculates the system, recent and user label lists. Notifies that the data has changed.
-         * This method modifies all the three lists on every single invocation.
+         * Toggle boolean for what folders are shown and which ones are
+         * hidden. Redraws list after toggling to show changes.
+         * @return true if folders are hidden, false if all are shown
+         */
+        @Override
+        public boolean toggleShowLessFolders() {
+            mShowLessFolders = !mShowLessFolders;
+            recalculateList();
+            return mShowLessFolders;
+        }
+
+        /**
+         * Toggle boolean for what accounts are shown and which ones are
+         * hidden. Redraws list after toggling to show changes.
+         * @return true if accounts are hidden, false if all are shown
+         */
+        @Override
+        public boolean toggleShowLessAccounts() {
+            mShowLessAccounts = !mShowLessAccounts;
+            recalculateList();
+            return mShowLessAccounts;
+        }
+
+        /**
+         * Responsible for verifying mCursor, adding collapsed view items
+         * when necessary, and notifying the data set has changed.
          */
         private void recalculateList() {
             if (mCursor == null || mCursor.isClosed() || mCursor.getCount() <= 0
                     || !mCursor.moveToFirst()) {
                 return;
             }
+            recalculateListFolders();
+            if(mShowLessFolders) {
+                mItemList.add(new DrawerItem(mActivity, R.string.folder_list_more, false));
+            }
+            // Ask the list to invalidate its views.
+            notifyDataSetChanged();
+        }
+
+        /**
+         * Recalculates the system, recent and user label lists.
+         * This method modifies all the three lists on every single invocation.
+         */
+        private void recalculateListFolders() {
             mItemList.clear();
             if (mAllAccounts != null) {
                 // Add the accounts at the top.
-                for (final Account c: mAllAccounts){
-                    mItemList.add(new DrawerItem(mActivity, c));
+                // TODO(shahrk): The logic here is messy and will be changed
+                //               to properly add/reflect on LRU/MRU account
+                //               changes similar to RecentFoldersList
+                if(mShowLessAccounts && mAllAccounts.length > MAX_ACCOUNTS) {
+                    mItemList.add(new DrawerItem(mActivity,
+                            R.string.folder_list_show_all_accounts, true));
+                    mItemList.add(new DrawerItem(mActivity, mCurrentAccount));
+                } else {
+                    Uri currentAccountUri = getCurrentAccountUri();
+                    for (final Account c: mAllAccounts){
+                        if(!currentAccountUri.equals(c.uri))
+                            mItemList.add(new DrawerItem(mActivity, c));
+                    }
+                    mItemList.add(new DrawerItem(mActivity, mCurrentAccount));
                 }
             }
             if (!mIsSectioned) {
@@ -560,6 +645,8 @@
                 return;
             }
 
+            // Tracks how many folders have been added through the rest of the function
+            int folderCount = 0;
             // Otherwise, this is an adapter for a sectioned list.
             // First add all the system folders.
             final List<DrawerItem> userFolderList = new ArrayList<DrawerItem>();
@@ -569,6 +656,11 @@
                     if (f.isProviderFolder()) {
                         mItemList.add(new DrawerItem(mActivity, f, DrawerItem.FOLDER_SYSTEM,
                                 mCursor.getPosition()));
+                        // Check if show less is enabled and we've passed max folders
+                        folderCount++;
+                        if(mShowLessFolders && folderCount >= MAX_FOLDERS) {
+                            return;
+                        }
                     } else {
                         userFolderList.add(new DrawerItem(
                                 mActivity, f, DrawerItem.FOLDER_USER, mCursor.getPosition()));
@@ -592,6 +684,11 @@
                 mItemList.add(new DrawerItem(mActivity, R.string.recent_folders_heading));
                 for (Folder f : recentFolderList) {
                     mItemList.add(new DrawerItem(mActivity, f, DrawerItem.FOLDER_RECENT, -1));
+                    // Check if show less is enabled and we've passed max folders
+                    folderCount++;
+                    if(mShowLessFolders && folderCount >= MAX_FOLDERS) {
+                        return;
+                    }
                 }
             }
             // If there are user folders, add them and a header.
@@ -599,10 +696,13 @@
                 mItemList.add(new DrawerItem(mActivity, R.string.all_folders_heading));
                 for (final DrawerItem i : userFolderList) {
                     mItemList.add(i);
+                    // Check if show less is enabled and we've passed max folders
+                    folderCount++;
+                    if(mShowLessFolders && folderCount >= MAX_FOLDERS) {
+                        return;
+                    }
                 }
             }
-            // Ask the list to invalidate its views.
-            notifyDataSetChanged();
         }
 
         @Override
@@ -762,6 +862,16 @@
         public Account getFullAccount(DrawerItem item) {
             return null;
         }
+
+        @Override
+        public boolean toggleShowLessFolders() {
+            return false;
+        }
+
+        @Override
+        public boolean toggleShowLessAccounts() {
+            return false;
+        }
     }
 
     /**
diff --git a/src/com/android/mail/ui/FolderSelectionActivity.java b/src/com/android/mail/ui/FolderSelectionActivity.java
index e71981f..3bee9b0 100644
--- a/src/com/android/mail/ui/FolderSelectionActivity.java
+++ b/src/com/android/mail/ui/FolderSelectionActivity.java
@@ -110,7 +110,7 @@
     private void createFolderListFragment(Folder parent, Uri uri) {
         final FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
         final Fragment fragment = FolderListFragment.newInstance(parent, uri, false,
-                getExcludedFolderTypes());
+                getExcludedFolderTypes(), true);
         fragmentTransaction.replace(R.id.content_pane, fragment);
         fragmentTransaction.commitAllowingStateLoss();
     }
diff --git a/src/com/android/mail/ui/OnePaneController.java b/src/com/android/mail/ui/OnePaneController.java
index cf2266e..44d7ed9 100644
--- a/src/com/android/mail/ui/OnePaneController.java
+++ b/src/com/android/mail/ui/OnePaneController.java
@@ -337,7 +337,7 @@
          */
         replaceFragment(
                 FolderListFragment.newInstance(null, mAccount.folderListUri,
-                        SECTIONS_AND_RECENT_FOLDERS_ENABLED),
+                        SECTIONS_AND_RECENT_FOLDERS_ENABLED, false),
                 FragmentTransaction.TRANSIT_FRAGMENT_OPEN, TAG_FOLDER_LIST,
                 R.id.drawer_pullout);
 
@@ -455,7 +455,7 @@
             // showing this folder's children if we are not already
             // looking at the child view for this folder.
             mLastFolderListTransactionId = replaceFragment(FolderListFragment.newInstance(
-                    top, top.childFoldersListUri, SECTIONS_AND_RECENT_FOLDERS_ENABLED),
+                    top, top.childFoldersListUri, SECTIONS_AND_RECENT_FOLDERS_ENABLED, false),
                     FragmentTransaction.TRANSIT_FRAGMENT_OPEN, TAG_FOLDER_LIST,
                     R.id.content_pane);
             // Show the up affordance when digging into child folders.
@@ -496,7 +496,8 @@
             // showing this folder's children if we are not already
             // looking at the child view for this folder.
             mLastFolderListTransactionId = replaceFragment(
-                    FolderListFragment.newInstance(folder, folder.childFoldersListUri, false),
+                    FolderListFragment.newInstance(folder, folder.childFoldersListUri,
+                            SECTIONS_AND_RECENT_FOLDERS_ENABLED, false),
                     FragmentTransaction.TRANSIT_FRAGMENT_OPEN, TAG_FOLDER_LIST, R.id.content_pane);
             // Show the up affordance when digging into child folders.
             mActionBarView.setBackButton();
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index 4b44b1c..4b45e3d 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -105,7 +105,8 @@
     private void createFolderListFragment(Folder parent, Uri uri) {
         setHierarchyFolder(parent);
         // Create a sectioned FolderListFragment.
-        FolderListFragment folderListFragment = FolderListFragment.newInstance(parent, uri, true);
+        FolderListFragment folderListFragment = FolderListFragment.newInstance(parent, uri, true,
+                true);
         FragmentTransaction fragmentTransaction = mActivity.getFragmentManager().beginTransaction();
         if (Utils.useFolderListFragmentTransition(mActivity.getActivityContext())) {
             fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);