Added unread counts to account in drawer

Accounts now have unread counts on the right in the
drawer, similar to folder item views.

I'll be refactoring account view into its own 
class/xml at some point on 3/18 or 3/19.

Change-Id: I181dd7a9d8af37bcc6605163d90503cc615b432f
diff --git a/src/com/android/mail/adapter/DrawerItem.java b/src/com/android/mail/adapter/DrawerItem.java
index f013a03..84b6540 100644
--- a/src/com/android/mail/adapter/DrawerItem.java
+++ b/src/com/android/mail/adapter/DrawerItem.java
@@ -103,12 +103,12 @@
      * Creates an item from an account.
      * @param account an account that this item represents.
      */
-    public DrawerItem(ControllableActivity activity, Account account) {
+    public DrawerItem(ControllableActivity activity, Account account, int count) {
         mActivity = activity;
         mInflater = LayoutInflater.from(mActivity.getActivityContext());
         mFolder = null;
         mType = VIEW_ACCOUNT;
-        mResource = -1;
+        mResource = count;
         mFolderType = ACCOUNT;
         mAccount = account;
         mIsExpandForAccount = false;
@@ -244,7 +244,7 @@
                     (FolderItemView) mInflater.inflate(R.layout.folder_item, null, false);
         }
         // Temporary. Ideally we want a totally different item.
-        folderItemView.bind(mAccount, mActivity);
+        folderItemView.bind(mAccount, mActivity, mResource);
         View v = folderItemView.findViewById(R.id.color_block);
         v.setBackgroundColor(mAccount.color);
         v = folderItemView.findViewById(R.id.folder_icon);
diff --git a/src/com/android/mail/ui/FolderItemView.java b/src/com/android/mail/ui/FolderItemView.java
index 13f0aee..8235602 100644
--- a/src/com/android/mail/ui/FolderItemView.java
+++ b/src/com/android/mail/ui/FolderItemView.java
@@ -132,13 +132,14 @@
         }
     }
 
-    public void bind(Account account, DropHandler dropHandler) {
+    public void bind(Account account, DropHandler dropHandler, int count) {
         mFolder = null;
         mDropHandler = dropHandler;
         mFolderTextView.setText(account.name);
         mFolderParentIcon.setVisibility(View.GONE);
         mUnreadCountTextView.setVisibility(View.GONE);
         setUnseenCount(Color.BLACK, 0);
+        setUnreadCount(count);
     }
 
     /**
diff --git a/src/com/android/mail/ui/FolderListFragment.java b/src/com/android/mail/ui/FolderListFragment.java
index eab850d..fb1947a 100644
--- a/src/com/android/mail/ui/FolderListFragment.java
+++ b/src/com/android/mail/ui/FolderListFragment.java
@@ -456,6 +456,8 @@
         private final List<DrawerItem> mItemList = new ArrayList<DrawerItem>();
         /** Cursor into the folder list. This might be null. */
         private Cursor mCursor = null;
+        /** Watcher for tracking and receiving unread counts for mail */
+        private FolderWatcher mFolderWatcher = null;
         private boolean mShowLessFolders;
         private boolean mShowLessAccounts;
 
@@ -473,8 +475,13 @@
             } else {
                 mRecentFolders = null;
             }
+            mFolderWatcher = new FolderWatcher(mActivity, this);
             mShowLessFolders = showLess;
             mShowLessAccounts = showLessAccounts;
+            for (int i=0; i < mAllAccounts.length; i++) {
+                final Uri uri = mAllAccounts[i].settings.defaultInbox;
+                mFolderWatcher.startWatching(uri);
+            }
         }
 
         @Override
@@ -605,17 +612,24 @@
                 // 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));
+                int unreadCount;
+                if (mShowLessAccounts && mAllAccounts.length > MAX_ACCOUNTS) {
+                    mItemList.add(new DrawerItem(
+                            mActivity, R.string.folder_list_show_all_accounts, true));
+                    unreadCount = mFolderWatcher.get(
+                            mCurrentAccount.settings.defaultInbox).unreadCount;
+                    mItemList.add(new DrawerItem(mActivity, mCurrentAccount, unreadCount));
                 } else {
                     Uri currentAccountUri = getCurrentAccountUri();
-                    for (final Account c: mAllAccounts){
-                        if(!currentAccountUri.equals(c.uri))
-                            mItemList.add(new DrawerItem(mActivity, c));
+                    for (final Account c : mAllAccounts) {
+                        if (!currentAccountUri.equals(c.uri)) {
+                            unreadCount = mFolderWatcher.get(c.settings.defaultInbox).unreadCount;
+                            mItemList.add(new DrawerItem(mActivity, c, unreadCount));
+                        }
                     }
-                    mItemList.add(new DrawerItem(mActivity, mCurrentAccount));
+                    unreadCount = mFolderWatcher.get(
+                            mCurrentAccount.settings.defaultInbox).unreadCount;
+                    mItemList.add(new DrawerItem(mActivity, mCurrentAccount, unreadCount));
                 }
             }
             if (!mIsSectioned) {