alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 32 | package org.sflphone.adapters; |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.concurrent.ExecutorService; |
| 36 | import java.util.concurrent.Executors; |
| 37 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 38 | import org.sflphone.R; |
| 39 | import org.sflphone.model.CallContact; |
| 40 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 41 | import android.content.Context; |
| 42 | import android.view.LayoutInflater; |
| 43 | import android.view.View; |
| 44 | import android.view.ViewGroup; |
| 45 | import android.widget.BaseAdapter; |
| 46 | import android.widget.ImageView; |
| 47 | import android.widget.TextView; |
| 48 | |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 49 | public class StarredContactsAdapter extends BaseAdapter { |
| 50 | |
| 51 | private ExecutorService infos_fetcher = Executors.newCachedThreadPool(); |
| 52 | private ArrayList<CallContact> dataset; |
| 53 | Context mContext; |
| 54 | |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 55 | // private static final String TAG = ContactsAdapter.class.getSimpleName(); |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 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 |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 79 | public CallContact getItem(int index) { |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 80 | 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 | |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 103 | infos_fetcher.execute(new ContactPictureTask(mContext, photo_view, item.getId())); |
alision | d295ec2 | 2013-05-17 10:12:13 -0400 | [diff] [blame] | 104 | |
| 105 | return v; |
| 106 | } |
| 107 | } |