Android Open Source - android-ribbit Message Adapter






From Project

Back to project page android-ribbit.

License

The source code is released under:

MIT License

If you think the Android project android-ribbit listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.teamtreehouse.ribbit;
//from   w  ww. j a va  2  s .co m
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.parse.ParseObject;

public class MessageAdapter extends ArrayAdapter<ParseObject> {
  
  protected Context mContext;
  protected List<ParseObject> mMessages;
  
  public MessageAdapter(Context context, List<ParseObject> messages) {
    super(context, R.layout.message_item, messages);
    mContext = context;
    mMessages = messages;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    
    if (convertView == null) {
      convertView = LayoutInflater.from(mContext).inflate(R.layout.message_item, null);
      holder = new ViewHolder();
      holder.iconImageView = (ImageView)convertView.findViewById(R.id.messageIcon);
      holder.nameLabel = (TextView)convertView.findViewById(R.id.senderLabel);
      convertView.setTag(holder);
    }
    else {
      holder = (ViewHolder)convertView.getTag();
    }
    
    ParseObject message = mMessages.get(position);
    
    if (message.getString(ParseConstants.KEY_FILE_TYPE).equals(ParseConstants.TYPE_IMAGE)) {
      holder.iconImageView.setImageResource(R.drawable.ic_action_picture);
    }
    else {
      holder.iconImageView.setImageResource(R.drawable.ic_action_play_over_video);
    }
    holder.nameLabel.setText(message.getString(ParseConstants.KEY_SENDER_NAME));
    
    return convertView;
  }
  
  private static class ViewHolder {
    ImageView iconImageView;
    TextView nameLabel;
  }
  
  public void refill(List<ParseObject> messages) {
    mMessages.clear();
    mMessages.addAll(messages);
    notifyDataSetChanged();
  }
}




Java Source Code List

com.teamtreehouse.ribbit.EditFriendsActivity.java
com.teamtreehouse.ribbit.FileHelper.java
com.teamtreehouse.ribbit.FriendsFragment.java
com.teamtreehouse.ribbit.ImageResizer.java
com.teamtreehouse.ribbit.InboxFragment.java
com.teamtreehouse.ribbit.LoginActivity.java
com.teamtreehouse.ribbit.MainActivity.java
com.teamtreehouse.ribbit.MessageAdapter.java
com.teamtreehouse.ribbit.ParseConstants.java
com.teamtreehouse.ribbit.RecipientsActivity.java
com.teamtreehouse.ribbit.RibbitApplication.java
com.teamtreehouse.ribbit.SectionsPagerAdapter.java
com.teamtreehouse.ribbit.SignUpActivity.java
com.teamtreehouse.ribbit.ViewImageActivity.java