• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 package com.android.mail.ui;
19 
20 import android.content.Context;
21 import android.database.Cursor;
22 import android.database.MatrixCursor;
23 
24 import com.android.mail.providers.Folder;
25 import com.android.mail.providers.UIProvider;
26 import com.android.mail.utils.MatrixCursorWithCachedColumns;
27 
28 import java.util.Set;
29 
30 public class AddableFolderSelectorAdapter extends FolderSelectorAdapter {
31 
AddableFolderSelectorAdapter(Context context, Cursor folders, Set<String> initiallySelected, int layout, String header)32     public AddableFolderSelectorAdapter(Context context, Cursor folders,
33             Set<String> initiallySelected, int layout, String header) {
34         super(context, folders, initiallySelected, layout, header);
35     }
36 
filterFolders(final Cursor folderCursor, final Set<Integer> excludedTypes)37     public static Cursor filterFolders(final Cursor folderCursor,
38             final Set<Integer> excludedTypes) {
39         final int projectionSize = UIProvider.FOLDERS_PROJECTION.length;
40         final MatrixCursor cursor =
41                 new MatrixCursorWithCachedColumns(UIProvider.FOLDERS_PROJECTION);
42         final Object[] folder = new Object[projectionSize];
43         if (folderCursor.moveToFirst()) {
44             do {
45                 final int type = folderCursor.getInt(UIProvider.FOLDER_TYPE_COLUMN);
46 
47                 if (excludedTypes != null) {
48                     boolean exclude = false;
49 
50                     for (final int excludedType : excludedTypes) {
51                         if (Folder.isType(type, excludedType)) {
52                             exclude = true;
53                             break;
54                         }
55                     }
56 
57                     if (exclude) {
58                         continue;
59                     }
60                 }
61 
62                 if (Folder.isType(type, UIProvider.FolderType.INBOX)
63                         || Folder.isType(type, UIProvider.FolderType.DEFAULT)) {
64                     folder[UIProvider.FOLDER_ID_COLUMN] = folderCursor
65                             .getLong(UIProvider.FOLDER_ID_COLUMN);
66                     folder[UIProvider.FOLDER_PERSISTENT_ID_COLUMN] = folderCursor
67                             .getString(UIProvider.FOLDER_PERSISTENT_ID_COLUMN);
68                     folder[UIProvider.FOLDER_URI_COLUMN] = folderCursor
69                             .getString(UIProvider.FOLDER_URI_COLUMN);
70                     folder[UIProvider.FOLDER_NAME_COLUMN] = folderCursor
71                             .getString(UIProvider.FOLDER_NAME_COLUMN);
72                     folder[UIProvider.FOLDER_HAS_CHILDREN_COLUMN] = folderCursor
73                             .getInt(UIProvider.FOLDER_HAS_CHILDREN_COLUMN);
74                     folder[UIProvider.FOLDER_CAPABILITIES_COLUMN] = folderCursor
75                             .getInt(UIProvider.FOLDER_CAPABILITIES_COLUMN);
76                     folder[UIProvider.FOLDER_SYNC_WINDOW_COLUMN] = folderCursor
77                             .getInt(UIProvider.FOLDER_SYNC_WINDOW_COLUMN);
78                     folder[UIProvider.FOLDER_CONVERSATION_LIST_URI_COLUMN] = folderCursor
79                             .getString(UIProvider.FOLDER_CONVERSATION_LIST_URI_COLUMN);
80                     folder[UIProvider.FOLDER_CHILD_FOLDERS_LIST_COLUMN] = folderCursor
81                             .getString(UIProvider.FOLDER_CHILD_FOLDERS_LIST_COLUMN);
82                     folder[UIProvider.FOLDER_UNSEEN_COUNT_COLUMN] = folderCursor
83                             .getInt(UIProvider.FOLDER_UNSEEN_COUNT_COLUMN);
84                     folder[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = folderCursor
85                             .getInt(UIProvider.FOLDER_UNREAD_COUNT_COLUMN);
86                     folder[UIProvider.FOLDER_TOTAL_COUNT_COLUMN] = folderCursor
87                             .getInt(UIProvider.FOLDER_TOTAL_COUNT_COLUMN);
88                     folder[UIProvider.FOLDER_REFRESH_URI_COLUMN] = folderCursor
89                             .getString(UIProvider.FOLDER_REFRESH_URI_COLUMN);
90                     folder[UIProvider.FOLDER_SYNC_STATUS_COLUMN] = folderCursor
91                             .getInt(UIProvider.FOLDER_SYNC_STATUS_COLUMN);
92                     folder[UIProvider.FOLDER_LAST_SYNC_RESULT_COLUMN] = folderCursor
93                             .getInt(UIProvider.FOLDER_LAST_SYNC_RESULT_COLUMN);
94                     folder[UIProvider.FOLDER_TYPE_COLUMN] = type;
95                     folder[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = folderCursor
96                             .getInt(UIProvider.FOLDER_ICON_RES_ID_COLUMN);
97                     folder[UIProvider.FOLDER_NOTIFICATION_ICON_RES_ID_COLUMN] = folderCursor
98                             .getInt(UIProvider.FOLDER_NOTIFICATION_ICON_RES_ID_COLUMN);
99                     folder[UIProvider.FOLDER_BG_COLOR_COLUMN] = folderCursor
100                             .getString(UIProvider.FOLDER_BG_COLOR_COLUMN);
101                     folder[UIProvider.FOLDER_FG_COLOR_COLUMN] = folderCursor
102                             .getString(UIProvider.FOLDER_FG_COLOR_COLUMN);
103                     folder[UIProvider.FOLDER_LOAD_MORE_URI_COLUMN] = folderCursor
104                             .getString(UIProvider.FOLDER_LOAD_MORE_URI_COLUMN);
105                     folder[UIProvider.FOLDER_HIERARCHICAL_DESC_COLUMN] = folderCursor
106                             .getString(UIProvider.FOLDER_HIERARCHICAL_DESC_COLUMN);
107                     folder[UIProvider.FOLDER_LAST_MESSAGE_TIMESTAMP_COLUMN] = folderCursor
108                             .getLong(UIProvider.FOLDER_LAST_MESSAGE_TIMESTAMP_COLUMN);
109                     folder[UIProvider.FOLDER_PARENT_URI_COLUMN] = folderCursor
110                             .getString(UIProvider.FOLDER_PARENT_URI_COLUMN);
111                     cursor.addRow(folder);
112                 }
113             } while (folderCursor.moveToNext());
114         }
115         return cursor;
116     }
117 }
118