Home | History | Annotate | Download | only in drawer
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.mail.drawer;
     18 
     19 import android.view.View;
     20 import android.view.ViewGroup;
     21 
     22 import com.android.bitmap.BitmapCache;
     23 import com.android.mail.R;
     24 import com.android.mail.bitmap.ContactResolver;
     25 import com.android.mail.providers.Account;
     26 import com.android.mail.ui.AccountItemView;
     27 import com.android.mail.ui.ControllableActivity;
     28 import com.android.mail.utils.FolderUri;
     29 
     30 class AccountDrawerItem extends DrawerItem {
     31     /** True if the drawer item represents the current account, false otherwise */
     32     private final boolean mIsSelected;
     33     private final BitmapCache mImagesCache;
     34     private final ContactResolver mContactResolver;
     35 
     36     AccountDrawerItem(ControllableActivity activity, Account account,
     37             int unreadCount, boolean isCurrentAccount, BitmapCache cache,
     38             ContactResolver contactResolver) {
     39         super(activity, null, NONFOLDER_ITEM, account);
     40         mIsSelected = isCurrentAccount;
     41         mImagesCache = cache;
     42         mContactResolver = contactResolver;
     43         // TODO: Unread count should eventually percolate through to the account switcher
     44     }
     45 
     46     @Override
     47     public String toString() {
     48         return "[DrawerItem VIEW_ACCOUNT, mAccount=" + mAccount + "]";
     49     }
     50 
     51     /**
     52      * Return a view for an account object.
     53      *
     54      * @param convertView a view, possibly null, to be recycled.
     55      * @param parent the parent viewgroup to attach to.
     56      * @return a view to display at this position.
     57      */
     58     @Override
     59     public View getView(View convertView, ViewGroup parent) {
     60         final AccountItemView accountItemView;
     61         if (convertView != null) {
     62             accountItemView = (AccountItemView) convertView;
     63         } else {
     64             accountItemView =
     65                     (AccountItemView) mInflater.inflate(R.layout.account_item, parent, false);
     66         }
     67         accountItemView.bind(mActivity.getActivityContext(), mAccount, mIsSelected,
     68                 mImagesCache, mContactResolver);
     69         return accountItemView;
     70     }
     71 
     72     @Override
     73     public boolean isHighlighted(FolderUri currentFolder, int currentType) {
     74         return false;
     75     }
     76 
     77     @Override
     78     public boolean isItemEnabled() {
     79         return true;
     80     }
     81 
     82     @Override
     83     public @DrawerItemType int getType() {
     84         return VIEW_ACCOUNT;
     85     }
     86 }
     87