blob: c09dfe7bbf279a01c71d3186b57a56cfa10b607d [file] [log] [blame]
alision11e8e162013-05-28 10:33:14 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
alisiond295ec22013-05-17 10:12:13 -040032package com.savoirfairelinux.sflphone.adapters;
33
34import java.util.ArrayList;
35import java.util.concurrent.ExecutorService;
36import java.util.concurrent.Executors;
37
38import android.content.Context;
39import android.view.LayoutInflater;
40import android.view.View;
41import android.view.ViewGroup;
42import android.widget.BaseAdapter;
43import android.widget.ImageView;
44import android.widget.TextView;
45
46import com.savoirfairelinux.sflphone.R;
47import com.savoirfairelinux.sflphone.model.CallContact;
48
49public class StarredContactsAdapter extends BaseAdapter {
50
51 private ExecutorService infos_fetcher = Executors.newCachedThreadPool();
52 private ArrayList<CallContact> dataset;
53 Context mContext;
54
55 private static final String TAG = ContactsAdapter.class.getSimpleName();
56
57 public StarredContactsAdapter(Context context) {
58 super();
59 mContext = context;
60 dataset = new ArrayList<CallContact>();
61 }
62
63 public void removeAll() {
64 dataset.clear();
65 notifyDataSetChanged();
66 }
67
68 public void addAll(ArrayList<CallContact> arrayList) {
69 dataset.addAll(arrayList);
70 notifyDataSetChanged();
71 }
72
73 @Override
74 public int getCount() {
75 return dataset.size();
76 }
77
78 @Override
alisiond8c83882013-05-17 17:00:42 -040079 public CallContact getItem(int index) {
alisiond295ec22013-05-17 10:12:13 -040080 return dataset.get(index);
81 }
82
83 @Override
84 public long getItemId(int index) {
85 return dataset.get(index).getId();
86 }
87
88 @Override
89 public View getView(int pos, View convView, ViewGroup parent) {
90
91 View v = convView;
92 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
93
94 if (v == null) {
95 v = inflater.inflate(R.layout.item_contact_starred, null);
96 }
97
98 CallContact item = dataset.get(pos);
99
100 ((TextView) v.findViewById(R.id.display_name)).setText(item.getmDisplayName());
101 ImageView photo_view = (ImageView) v.findViewById(R.id.photo);
102
103 infos_fetcher.execute(new ContactPictureLoader(mContext, photo_view, item.getId()));
104
105 return v;
106 }
107}