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 android.content.Context;
21
22import com.android.mail.R;
23import com.android.mail.providers.Conversation;
24import com.android.mail.providers.Folder;
25import com.android.mail.providers.UIProvider.FolderType;
26import com.android.mail.utils.FolderUri;
27import com.android.mail.utils.LogTag;
28import com.google.common.collect.Sets;
29
30import java.util.NavigableSet;
31
32/**
33 * Used to generate folder display information given a raw folders string.
34 * (The raw folders string can be obtained from {@link Conversation#getRawFolders()}.)
35 */
36public class FolderDisplayer {
37    public static final String LOG_TAG = LogTag.getLogTag();
38    protected Context mContext;
39    protected final NavigableSet<Folder> mFoldersSortedSet = Sets.newTreeSet();
40
41    protected final int mDefaultBgColor;
42    protected final int mDefaultFgColor;
43
44    public FolderDisplayer(Context context) {
45        mContext = context;
46
47        mDefaultFgColor = context.getResources().getColor(R.color.default_folder_foreground_color);
48        mDefaultBgColor = context.getResources().getColor(R.color.default_folder_background_color);
49    }
50
51    /**
52     * Configure the FolderDisplayer object by filtering and copying from the list of raw folders.
53     *
54     * @param conv {@link Conversation} containing the folders to display.
55     * @param ignoreFolderUri (optional) folder to omit from the displayed set
56     * @param ignoreFolderType -1, or the {@link FolderType} to omit from the displayed set
57     */
58    public void loadConversationFolders(Conversation conv, final FolderUri ignoreFolderUri,
59            final int ignoreFolderType) {
60        mFoldersSortedSet.clear();
61        for (Folder folder : conv.getRawFolders()) {
62            // Skip the ignoreFolderType
63            if (ignoreFolderType >= 0 && folder.isType(ignoreFolderType)) {
64                continue;
65            }
66            // skip the ignoreFolder
67            if (ignoreFolderUri != null && ignoreFolderUri.equals(folder.folderUri)) {
68                continue;
69            }
70            mFoldersSortedSet.add(folder);
71        }
72    }
73
74    /**
75     * Reset this FolderDisplayer so that it can be reused.
76     */
77    public void reset() {
78        mFoldersSortedSet.clear();
79    }
80}
81