@Override public View getView(int position, View convertView, ViewGroup parent) { ConversationView view = null; if (convertView == null) { view = new ConversationView(MessageListActivity.this); } else { view = (ConversationView)convertView; } Conversation c = conversations.get(position); view.setConversation(c);; return view; } }
@Override public void propertyChange(PropertyChangeEvent event){ if (event.getPropertyName().equals("detail")) { TextView tv = (TextView)this.findViewById(R.id.content); tv.setText(this.conversation.getDetail()); } else if (event.getPropertyName().equals("name")) { TextView tv = (TextView) this.findViewById(R.id.name); tv.setText(this.conversation.getName()); } else if (event.getPropertyName().equals("avatar")) { ImageView imageView = (ImageView) this.findViewById(R.id.header); Picasso.with(context) .load(avatar) .into(imageView); } else if (event.getPropertyName().equals("unreadCount")) { setUnreadCount();
private void setUnreadCount() { TextView tv = (TextView) this.findViewById(R.id.unReadCount); if (conversation.getUnreadCount() > 0) { tv.setVisibility(VISIBLE); tv.setText(String.valueOf(conversation.getUnreadCount())); } else { tv.setVisibility(GONE); } }
public void setConversation(Conversation c) { if (this.conversation != null) { this.conversation.removePropertyChangeListener(this); } this.conversation = c; this.conversation.addPropertyChangeListener(this); TextView tv = (TextView) this.findViewById(R.id.name); tv.setText(c.getName()); tv = (TextView)this.findViewById(R.id.content); tv.setText(c.getDetail()); int placeholder; if (c.type == Conversation.CONVERSATION_PEER) { placeholder = R.drawable.avatar_contact; } else { placeholder = R.drawable.avatar_group; } String avatar = null; if (!TextUtils.isEmpty(c.getAvatar())) { avatar = c.getAvatar(); } ImageView imageView = (ImageView) this.findViewById(R.id.header); Picasso.with(context) .load(avatar) .placeholder(placeholder) .into(imageView); setUnreadCount(); }