ListItemAdapter.java

 1package eu.siacs.conversations.ui.adapter;
 2
 3import java.util.List;
 4
 5import eu.siacs.conversations.R;
 6import eu.siacs.conversations.entities.ListItem;
 7import eu.siacs.conversations.ui.XmppActivity;
 8import android.content.Context;
 9import android.content.SharedPreferences;
10import android.preference.PreferenceManager;
11import android.view.LayoutInflater;
12import android.view.View;
13import android.view.ViewGroup;
14import android.widget.ArrayAdapter;
15import android.widget.ImageView;
16import android.widget.LinearLayout;
17import android.widget.TextView;
18
19public class ListItemAdapter extends ArrayAdapter<ListItem> {
20
21	protected XmppActivity activity;
22	protected boolean showDynamicTags = false;
23
24	public ListItemAdapter(XmppActivity activity, List<ListItem> objects) {
25		super(activity, 0, objects);
26		this.activity = activity;
27		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
28		this.showDynamicTags = preferences.getBoolean("show_dynamic_tags",false);
29	}
30
31	@Override
32	public View getView(int position, View view, ViewGroup parent) {
33		LayoutInflater inflater = (LayoutInflater) getContext()
34				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
35		ListItem item = getItem(position);
36		if (view == null) {
37			view = inflater.inflate(R.layout.contact, parent, false);
38		}
39		TextView name = (TextView) view.findViewById(R.id.contact_display_name);
40		TextView jid = (TextView) view.findViewById(R.id.contact_jid);
41		ImageView picture = (ImageView) view.findViewById(R.id.contact_photo);
42		LinearLayout tagLayout = (LinearLayout) view.findViewById(R.id.tags);
43
44		List<ListItem.Tag> tags = item.getTags();
45		if (tags.size() == 0 || !this.showDynamicTags) {
46			tagLayout.setVisibility(View.GONE);
47		} else {
48			tagLayout.setVisibility(View.VISIBLE);
49			tagLayout.removeAllViewsInLayout();
50			for(ListItem.Tag tag : tags) {
51				TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag,tagLayout,false);
52				tv.setText(tag.getName());
53				tv.setBackgroundColor(tag.getColor());
54				tagLayout.addView(tv);
55			}
56		}
57
58		jid.setText(item.getJid().toString());
59		name.setText(item.getDisplayName());
60		picture.setImageBitmap(activity.avatarService().get(item,
61				activity.getPixel(48)));
62		return view;
63	}
64
65}