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.mail.R;
23 import com.android.mail.providers.Folder;
24 import com.android.mail.ui.ControllableActivity;
25 import com.android.mail.ui.FolderItemView;
26 import com.android.mail.utils.FolderUri;
27 
28 class FolderDrawerItem extends DrawerItem {
FolderDrawerItem(ControllableActivity activity, Folder folder, @DrawerItemCategory int folderCategory)29     FolderDrawerItem(ControllableActivity activity, Folder folder,
30             @DrawerItemCategory int folderCategory) {
31         super(activity, folder,  folderCategory, null);
32     }
33 
34     @Override
toString()35     public String toString() {
36         return "[DrawerItem VIEW_FOLDER, mFolder=" + mFolder + ", mItemCategory=" +
37                 mItemCategory + "]";
38     }
39 
40     /**
41      * Return a folder: either a parent folder or a normal (child or flat)
42      * folder.
43      *
44      * @param convertView a view, possibly null, to be recycled.
45      * @return a view showing a folder at the given position.
46      */
47     @Override
getView(View convertView, ViewGroup parent)48     public View getView(View convertView, ViewGroup parent) {
49         final FolderItemView folderItemView;
50         if (convertView != null) {
51             folderItemView = (FolderItemView) convertView;
52         } else {
53             folderItemView =
54                     (FolderItemView) mInflater.inflate(R.layout.folder_item, parent, false);
55         }
56         folderItemView.bind(mFolder, null /* parentUri */);
57         folderItemView.setIcon(mFolder);
58         return folderItemView;
59     }
60 
61     @Override
isHighlighted(FolderUri currentFolder, int currentType)62     public boolean isHighlighted(FolderUri currentFolder, int currentType) {
63         // True if folder types and URIs are the same
64         if (currentFolder != null && mFolder != null && mFolder.folderUri != null) {
65             return (mItemCategory == currentType) && mFolder.folderUri.equals(currentFolder);
66         }
67         return false;
68     }
69 
70     @Override
isItemEnabled()71     public boolean isItemEnabled() {
72         return true;
73     }
74 
75     @Override
getType()76     public @DrawerItemType int getType() {
77         return VIEW_FOLDER;
78     }
79 }
80