Merge "Change FolderType to a bitmask" into jb-ub-mail-ur9
diff --git a/src/com/android/mail/browse/SelectedConversationsActionMenu.java b/src/com/android/mail/browse/SelectedConversationsActionMenu.java
index 43efc86..e9cf4f6 100644
--- a/src/com/android/mail/browse/SelectedConversationsActionMenu.java
+++ b/src/com/android/mail/browse/SelectedConversationsActionMenu.java
@@ -155,7 +155,7 @@
                 starConversations(true);
                 break;
             case R.id.remove_star:
-                if (mFolder.type == UIProvider.FolderType.STARRED) {
+                if (mFolder.isType(UIProvider.FolderType.STARRED)) {
                     LogUtils.d(LOG_TAG, "We are in a starred folder, removing the star");
                     performDestructiveAction(R.id.remove_star);
                 } else {
@@ -373,7 +373,7 @@
         // archive icon if the setting for that is true.
         final MenuItem removeFolder = menu.findItem(R.id.remove_folder);
         final MenuItem moveTo = menu.findItem(R.id.move_to);
-        final boolean showRemoveFolder = mFolder != null && mFolder.type == FolderType.DEFAULT
+        final boolean showRemoveFolder = mFolder != null && mFolder.isType(FolderType.DEFAULT)
                 && mFolder.supportsCapability(FolderCapabilities.CAN_ACCEPT_MOVED_MESSAGES)
                 && !mFolder.isProviderFolder();
         final boolean showMoveTo = mFolder != null
diff --git a/src/com/android/mail/providers/Folder.java b/src/com/android/mail/providers/Folder.java
index a414f51..a986c5a 100644
--- a/src/com/android/mail/providers/Folder.java
+++ b/src/com/android/mail/providers/Folder.java
@@ -141,7 +141,8 @@
     public int lastSyncResult;
 
     /**
-     * Folder type. 0 is default.
+     * Folder type bit mask. 0 is default.
+     * @see FolderType
      */
     public int type;
 
@@ -437,7 +438,7 @@
             return;
         }
         boolean showBg =
-                !TextUtils.isEmpty(folder.bgColor) && folder.type != FolderType.INBOX_SECTION;
+                !TextUtils.isEmpty(folder.bgColor) && (folder.type & FolderType.INBOX_SECTION) == 0;
         final int backgroundColor = showBg ? Integer.parseInt(folder.bgColor) : 0;
         if (backgroundColor == Utils.getDefaultFolderBackgroundColor(colorBlock.getContext())) {
             showBg = false;
@@ -470,7 +471,7 @@
      * Return if the type of the folder matches a provider defined folder.
      */
     public boolean isProviderFolder() {
-        return type != UIProvider.FolderType.DEFAULT;
+        return isType(type & UIProvider.FolderType.DEFAULT);
     }
 
     public int getBackgroundColor(int defaultColor) {
@@ -562,11 +563,11 @@
             if (toFind.equals(f.uri)) {
                 return true;
             }
-            hasInbox |= (f.type == UIProvider.FolderType.INBOX);
+            hasInbox |= f.isInbox();
         }
         // Did not find the URI of needle directly. If the needle is an Inbox and one of the folders
         // was an inbox, then the needle is contained (check Javadoc for explanation).
-        final boolean needleIsInbox = (needle.type == UIProvider.FolderType.INBOX);
+        final boolean needleIsInbox = needle.isInbox();
         return needleIsInbox ? hasInbox : false;
     }
 
@@ -589,18 +590,26 @@
         return target;
     }
 
+    public boolean isType(final int folderType) {
+        return (type & folderType) != 0;
+    }
+
+    public boolean isInbox() {
+        return isType(UIProvider.FolderType.INBOX);
+    }
+
     /**
      * Return if this is the trash folder.
      */
     public boolean isTrash() {
-        return type == UIProvider.FolderType.TRASH;
+        return isType(UIProvider.FolderType.TRASH);
     }
 
     /**
      * Return if this is a draft folder.
      */
     public boolean isDraft() {
-        return type == UIProvider.FolderType.DRAFT;
+        return isType(UIProvider.FolderType.DRAFT);
     }
 
     /**
@@ -615,7 +624,7 @@
      * Whether this is the special folder just used to display all mail for an account.
      */
     public boolean isViewAll() {
-        return type == UIProvider.FolderType.ALL_MAIL;
+        return isType(UIProvider.FolderType.ALL_MAIL);
     }
 
     /**
diff --git a/src/com/android/mail/providers/UIProvider.java b/src/com/android/mail/providers/UIProvider.java
index 86ab8aa..1ec1dbf 100644
--- a/src/com/android/mail/providers/UIProvider.java
+++ b/src/com/android/mail/providers/UIProvider.java
@@ -644,27 +644,27 @@
 
     public static final class FolderType {
         /** A user defined label. */
-        public static final int DEFAULT = 0;
+        public static final int DEFAULT = 1 << 0;
         /** A system defined inbox */
-        public static final int INBOX = 1;
+        public static final int INBOX = 1 << 1;
         /** A system defined containing mails to be edited before sending. */
-        public static final int DRAFT = 2;
+        public static final int DRAFT = 1 << 2;
         /** A system defined folder containing mails <b>to be</b> sent */
-        public static final int OUTBOX = 3;
+        public static final int OUTBOX = 1 << 3;
         /** A system defined folder containing sent mails */
-        public static final int SENT = 4;
+        public static final int SENT = 1 << 4;
         /** A system defined trash folder */
-        public static final int TRASH = 5;
+        public static final int TRASH = 1 << 5;
         /** A system defined spam folder */
-        public static final int SPAM = 6;
+        public static final int SPAM = 1 << 6;
         /** A system defined starred folder */
-        public static final int STARRED = 7;
+        public static final int STARRED = 1 << 7;
         /** Any other system label that we do not have a specific name for. */
-        public static final int OTHER_PROVIDER_FOLDER = 8;
+        public static final int OTHER_PROVIDER_FOLDER = 1 << 8;
         /** All mail folder **/
-        public static final int ALL_MAIL = 9;
+        public static final int ALL_MAIL = 1 << 9;
         /** Gmail's inbox sections **/
-        public static final int INBOX_SECTION = 10;
+        public static final int INBOX_SECTION = 1 << 10;
     }
 
     public static final class FolderCapabilities {
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 0f07ef0..a18f392 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -2607,13 +2607,13 @@
         if (!supportsDrag(event, folder)) {
             return;
         }
-        if (folder.type == UIProvider.FolderType.STARRED) {
+        if (folder.isType(UIProvider.FolderType.STARRED)) {
             // Moving a conversation to the starred folder adds the star and
             // removes the current label
             handleDropInStarred(folder);
             return;
         }
-        if (mFolder.type == UIProvider.FolderType.STARRED) {
+        if (mFolder.isType(UIProvider.FolderType.STARRED)) {
             handleDragFromStarred(folder);
             return;
         }
diff --git a/src/com/android/mail/ui/ConversationListFragment.java b/src/com/android/mail/ui/ConversationListFragment.java
index 12d2087..d91a95b 100644
--- a/src/com/android/mail/ui/ConversationListFragment.java
+++ b/src/com/android/mail/ui/ConversationListFragment.java
@@ -741,7 +741,7 @@
             int action;
             mListView.enableSwipe(true);
             if (ConversationListContext.isSearchResult(mViewContext)
-                    || (mFolder != null && mFolder.type == FolderType.SPAM)) {
+                    || (mFolder != null && mFolder.isType(FolderType.SPAM))) {
                 action = R.id.delete;
             } else if (mFolder == null) {
                 action = R.id.remove_folder;
diff --git a/src/com/android/mail/ui/FolderItemView.java b/src/com/android/mail/ui/FolderItemView.java
index 8235602..3c1afde 100644
--- a/src/com/android/mail/ui/FolderItemView.java
+++ b/src/com/android/mail/ui/FolderItemView.java
@@ -22,7 +22,6 @@
 
 import com.android.mail.providers.Account;
 import com.android.mail.providers.Folder;
-import com.android.mail.providers.UIProvider.FolderType;
 import com.android.mail.utils.LogTag;
 import com.android.mail.utils.LogUtils;
 import com.android.mail.utils.Utils;
@@ -123,7 +122,7 @@
         mDropHandler = dropHandler;
         mFolderTextView.setText(folder.name);
         mFolderParentIcon.setVisibility(mFolder.hasChildren ? View.VISIBLE : View.GONE);
-        if (folder.type == FolderType.INBOX_SECTION && mFolder.unseenCount > 0) {
+        if (mFolder.isInbox() && mFolder.unseenCount > 0) {
             mUnreadCountTextView.setVisibility(View.GONE);
             setUnseenCount(mFolder.getBackgroundColor(Color.BLACK), mFolder.unseenCount);
         } else {
diff --git a/src/com/android/mail/ui/FolderListFragment.java b/src/com/android/mail/ui/FolderListFragment.java
index 7ebea4a..e7aca91 100644
--- a/src/com/android/mail/ui/FolderListFragment.java
+++ b/src/com/android/mail/ui/FolderListFragment.java
@@ -23,7 +23,6 @@
 import android.content.CursorLoader;
 import android.content.Loader;
 import android.database.Cursor;
-import android.database.DataSetObserver;
 import android.net.Uri;
 import android.os.Bundle;
 import android.view.LayoutInflater;
@@ -655,7 +654,7 @@
                 // Adapter for a flat list. Everything is a FOLDER_USER, and there are no headers.
                 do {
                     final Folder f = Folder.getDeficientDisplayOnlyFolder(mCursor);
-                    if (mExcludedFolderTypes == null || !mExcludedFolderTypes.contains(f.type)) {
+                    if (!isFolderTypeExcluded(f.type)) {
                         mItemList.add(new DrawerItem(mActivity, f, DrawerItem.FOLDER_USER,
                                 mCursor.getPosition()));
                     }
@@ -672,7 +671,7 @@
             final List<DrawerItem> userFolderList = new ArrayList<DrawerItem>();
             do {
                 final Folder f = Folder.getDeficientDisplayOnlyFolder(mCursor);
-                if (mExcludedFolderTypes == null || !mExcludedFolderTypes.contains(f.type)) {
+                if (!isFolderTypeExcluded(f.type)) {
                     if (f.isProviderFolder()) {
                         mItemList.add(new DrawerItem(mActivity, f, DrawerItem.FOLDER_SYSTEM,
                                 mCursor.getPosition()));
@@ -694,7 +693,7 @@
             if (mExcludedFolderTypes != null) {
                 final Iterator<Folder> iterator = recentFolderList.iterator();
                 while (iterator.hasNext()) {
-                    if (mExcludedFolderTypes.contains(iterator.next().type)) {
+                    if (isFolderTypeExcluded(iterator.next().type)) {
                         iterator.remove();
                     }
                 }
@@ -968,4 +967,22 @@
     public boolean showingHierarchy() {
         return mParentFolder != null;
     }
+
+    /**
+     * Checks if the specified folder type bitmask contains a folder type that we want to exclude
+     * from displaying.
+     */
+    private boolean isFolderTypeExcluded(final int folderType) {
+        if (mExcludedFolderTypes == null) {
+            return false;
+        }
+
+        for (final int excludedType : mExcludedFolderTypes) {
+            if ((excludedType & folderType) != 0) {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }
diff --git a/src/com/android/mail/ui/FolderOperation.java b/src/com/android/mail/ui/FolderOperation.java
index eeb812b..28fef50 100644
--- a/src/com/android/mail/ui/FolderOperation.java
+++ b/src/com/android/mail/ui/FolderOperation.java
@@ -18,7 +18,6 @@
 package com.android.mail.ui;
 
 import com.android.mail.providers.Folder;
-import com.android.mail.providers.UIProvider;
 import com.google.common.base.Objects;
 import com.google.common.collect.ImmutableList;
 
@@ -72,7 +71,7 @@
             if (Objects.equal(op.mFolder.uri, folder.uri) && !op.mAdd) {
                 return true;
             }
-            if (folder.isTrash() && op.mFolder.type == UIProvider.FolderType.INBOX) {
+            if (folder.isTrash() && op.mFolder.isInbox()) {
                 return true;
             }
         }
diff --git a/src/com/android/mail/ui/FolderSelectorAdapter.java b/src/com/android/mail/ui/FolderSelectorAdapter.java
index d5d85af..96e1d56 100644
--- a/src/com/android/mail/ui/FolderSelectorAdapter.java
+++ b/src/com/android/mail/ui/FolderSelectorAdapter.java
@@ -20,7 +20,6 @@
 import com.android.mail.R;
 import com.android.mail.providers.Folder;
 import com.android.mail.providers.UIProvider.FolderCapabilities;
-import com.android.mail.providers.UIProvider.FolderType;
 import com.google.common.base.Objects;
 import com.google.common.collect.Lists;
 
@@ -146,7 +145,7 @@
     protected boolean meetsRequirements(Folder folder) {
         // We only want to show the non-Trash folders that can accept moved messages
         return folder.supportsCapability(FolderCapabilities.CAN_ACCEPT_MOVED_MESSAGES) &&
-                folder.type != FolderType.TRASH && !Objects.equal(folder, mExcludedFolder);
+                !folder.isTrash() && !Objects.equal(folder, mExcludedFolder);
     }
 
     @Override
diff --git a/src/com/android/mail/utils/NotificationActionUtils.java b/src/com/android/mail/utils/NotificationActionUtils.java
index 208e0c1..09554bc 100644
--- a/src/com/android/mail/utils/NotificationActionUtils.java
+++ b/src/com/android/mail/utils/NotificationActionUtils.java
@@ -222,7 +222,7 @@
         final List<NotificationActionType> sortedActions =
                 new ArrayList<NotificationActionType>(unsortedActions.size());
 
-        if (folder.type == FolderType.INBOX || folder.type == FolderType.INBOX_SECTION) {
+        if (folder.isInbox()) {
             // Inbox
             /*
              * Action 1: Archive, Delete, Mute, Mark read, Add star, Mark important, Reply, Reply
@@ -495,8 +495,7 @@
         public int getActionTextResId() {
             switch (mNotificationActionType) {
                 case ARCHIVE_REMOVE_LABEL:
-                    if (mFolder.type == FolderType.INBOX
-                            || mFolder.type == FolderType.INBOX_SECTION) {
+                    if (mFolder.isInbox()) {
                         return R.string.notification_action_undo_archive;
                     } else {
                         return R.string.notification_action_undo_remove_label;
@@ -671,7 +670,7 @@
 
         switch (destructAction) {
             case ARCHIVE_REMOVE_LABEL: {
-                if (folder.type == FolderType.INBOX || folder.type == FolderType.INBOX_SECTION) {
+                if (folder.isInbox()) {
                     // Inbox, so archive
                     final ContentValues values = new ContentValues(1);
                     values.put(UIProvider.ConversationOperations.OPERATION_KEY,
diff --git a/src/com/android/mail/utils/Utils.java b/src/com/android/mail/utils/Utils.java
index a0453a5..6f967a8 100644
--- a/src/com/android/mail/utils/Utils.java
+++ b/src/com/android/mail/utils/Utils.java
@@ -1199,23 +1199,17 @@
      * the unread count, but for some folder types (outbox, drafts, trash) this will return the
      * total count.
      */
-    public static int getFolderUnreadDisplayCount(Folder folder) {
-        final int count;
+    public static int getFolderUnreadDisplayCount(final Folder folder) {
         if (folder != null) {
-            switch (folder.type) {
-                case UIProvider.FolderType.DRAFT:
-                case UIProvider.FolderType.TRASH:
-                case UIProvider.FolderType.OUTBOX:
-                    count = folder.totalCount;
-                    break;
-                default:
-                    count = folder.unreadCount;
-                    break;
+            if (folder.isDraft() || folder.isTrash()
+                    || folder.isType(UIProvider.FolderType.OUTBOX)) {
+                return folder.totalCount;
+            } else {
+                return folder.unreadCount;
             }
-        } else {
-            count = 0;
         }
-        return count;
+
+        return 0;
     }
 
     /**