FolderDisplayer.java revision b334c9035e9b7a38766bb66c29da2208525d1e11
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.LogTag;
21import com.google.common.collect.Sets;
22
23import android.content.Context;
24import android.text.TextUtils;
25
26import com.android.mail.R;
27import com.android.mail.providers.Conversation;
28import com.android.mail.providers.Folder;
29import com.android.mail.utils.LogUtils;
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#rawFolders}.)
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 parsing the rawFolders string.
55     *
56     * @param foldersString string containing serialized folders to display.
57     * @param ignoreFolder (optional) folder to omit from the displayed set
58     */
59    public void loadConversationFolders(String foldersString, Folder ignoreFolder) {
60        mFoldersSortedSet.clear();
61
62        for (Folder f : Folder.forFoldersString(foldersString)) {
63            // We will sometimes see folders that do not have names yet.
64            if (TextUtils.isEmpty(f.name) || (ignoreFolder != null && ignoreFolder.equals(f))) {
65                continue;
66            }
67
68            // TODO: maybe do additional processing for system folder names here
69
70            mFoldersSortedSet.add(f);
71        }
72    }
73
74}
75