1/*
2 * Copyright (C) 2012 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
17package com.android.contacts.list;
18
19import android.content.Context;
20import android.database.Cursor;
21
22import com.android.contacts.GroupMemberLoader;
23import com.android.contacts.common.list.ContactEntry;
24import com.android.contacts.common.list.ContactTileAdapter;
25import com.android.contacts.common.list.ContactTileView;
26import com.google.common.collect.Lists;
27
28import java.util.ArrayList;
29
30/**
31 * Tile adapter for groups.
32 */
33public class GroupMemberTileAdapter extends ContactTileAdapter {
34
35    public GroupMemberTileAdapter(Context context, ContactTileView.Listener listener, int numCols) {
36        super(context, listener, numCols, DisplayType.GROUP_MEMBERS);
37    }
38
39    @Override
40    protected void bindColumnIndices() {
41        mIdIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_ID;
42        mLookupIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_LOOKUP_KEY;
43        mPhotoUriIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_PHOTO_URI;
44        mNameIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_DISPLAY_NAME_PRIMARY;
45        mPresenceIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_PRESENCE_STATUS;
46        mStatusIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_STATUS;
47    }
48
49    @Override
50    protected void saveNumFrequentsFromCursor(Cursor cursor) {
51        mNumFrequents = 0;
52    }
53
54    @Override
55    public int getItemViewType(int position) {
56        return ViewTypes.STARRED;
57    }
58
59    @Override
60    protected int getDividerPosition(Cursor cursor) {
61        // No divider
62        return -1;
63    }
64
65    @Override
66    public int getCount() {
67        if (mContactCursor == null || mContactCursor.isClosed()) {
68            return 0;
69        }
70
71        return getRowCount(mContactCursor.getCount());
72    }
73
74    @Override
75    public ArrayList<ContactEntry> getItem(int position) {
76        final ArrayList<ContactEntry> resultList = Lists.newArrayListWithCapacity(mColumnCount);
77        int contactIndex = position * mColumnCount;
78
79        for (int columnCounter = 0; columnCounter < mColumnCount; columnCounter++) {
80            resultList.add(createContactEntryFromCursor(mContactCursor, contactIndex));
81            contactIndex++;
82        }
83        return resultList;
84    }
85}
86