FolderDisplayer.java revision 259df5b9e11908c8ef7c91483924891dd96b3c27
1/*
2 * Copyright (C) 2012 Google Inc.
3 * Licensed to The Android Open Source Project.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.mail.ui;
19
20import com.android.mail.utils.FolderUri;
21import com.android.mail.utils.LogTag;
22import com.google.common.collect.Sets;
23
24import android.content.Context;
25
26import com.android.mail.R;
27import com.android.mail.providers.Conversation;
28import com.android.mail.providers.Folder;
29import com.android.mail.providers.UIProvider.FolderType;
30
31import java.util.SortedSet;
32
33/**
34 * Used to generate folder display information given a raw folders string.
35 * (The raw folders string can be obtained from {@link Conversation#getRawFolders()}.)
36 *
37 */
38public class FolderDisplayer {
39    public static final String LOG_TAG = LogTag.getLogTag();
40    protected Context mContext;
41    protected final SortedSet<Folder> mFoldersSortedSet = Sets.newTreeSet();
42
43    protected final int mDefaultBgColor;
44    protected final int mDefaultFgColor;
45
46    public FolderDisplayer(Context context) {
47        mContext = context;
48
49        mDefaultFgColor = context.getResources().getColor(R.color.default_folder_foreground_color);
50        mDefaultBgColor = context.getResources().getColor(R.color.default_folder_background_color);
51    }
52
53    /**
54     * Configure the FolderDisplayer object by filtering and copying from the list of raw folders.
55     *
56     * @param conv {@link Conversation} containing the folders to display.
57     * @param ignoreFolderUri (optional) folder to omit from the displayed set
58     * @param ignoreFolderType -1, or the {@link FolderType} to omit from the displayed set
59     */
60    public void loadConversationFolders(Conversation conv, final FolderUri ignoreFolderUri,
61            final int ignoreFolderType) {
62        mFoldersSortedSet.clear();
63        for (Folder folder : conv.getRawFolders()) {
64            // Skip the ignoreFolderType
65            if (ignoreFolderType >= 0 && folder.isType(ignoreFolderType)) {
66                continue;
67            }
68            // skip the ignoreFolder
69            if (ignoreFolderUri != null && ignoreFolderUri.equals(folder.folderUri)) {
70                continue;
71            }
72            mFoldersSortedSet.add(folder);
73        }
74    }
75
76    /**
77     * Reset this FolderDisplayer so that it can be reused.
78     */
79    public void reset() {
80        mFoldersSortedSet.clear();
81    }
82}
83