Android Open Source - ChitChat Friend Grid Adapter






From Project

Back to project page ChitChat.

License

The source code is released under:

MIT License

If you think the Android project ChitChat 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.shivamb7.chitchat.adapters;
//  ww  w  .ja  v a 2 s . c o  m
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.parse.ParseObject;
import com.parse.ParseUser;
import com.shivamb7.chitchat.R;
import com.shivamb7.chitchat.workers.Constants;

public class FriendGridAdapter extends ArrayAdapter<ParseUser> {
  
  Context mContext;
  List<ParseUser> mFriends;
  
  public FriendGridAdapter(Context c,List<ParseUser> messages)
  {
    super(c,R.layout.message_list_item,messages);
    mContext = c;
    mFriends = messages;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if(convertView == null)
    {
    convertView = LayoutInflater.from(mContext).inflate(R.layout.friend_grid_item, null);
    holder = new ViewHolder();
    holder.iconCheck = (ImageView)convertView.findViewById(R.id.user_image_check);
    holder.nameLabel = (TextView)convertView.findViewById(R.id.friend_name);
    //holder.timeLabel = (TextView)convertView.findViewById(R.id.message_time);
    convertView.setTag(holder); //VERY IMPORTANT LINE !!!
    }
    else
    {
      holder = (ViewHolder)convertView.getTag();
    }
    ParseUser friend = mFriends.get(position);
    /*Date createdDate = message.getCreatedAt();
    long currentTime = new Date().getTime();
    String convertedTime = DateUtils.getRelativeTimeSpanString(createdDate.getTime(), currentTime, DateUtils.SECOND_IN_MILLIS).toString();
    holder.timeLabel.setText(convertedTime);
    if(message.getString(Constants.FILE_TYPE).equals(Constants.TYPE_PICTURE))
    {
      holder.iconImage.setImageResource(R.drawable.ic_action_picture_orange);
    }
    else if(message.getString(Constants.FILE_TYPE).equals(Constants.TYPE_VIDEO))
    {
      holder.iconImage.setImageResource(R.drawable.ic_action_video_orange);
    }
    else
    {
      holder.iconImage.setImageResource(R.drawable.ic_action_chat_orange);
    }*/
    holder.nameLabel.setText(friend.getUsername());
    GridView gv = (GridView)parent;
    if(gv.isItemChecked(position))
    {
      holder.iconCheck.setVisibility(View.VISIBLE);
    }
    else
    {
      holder.iconCheck.setVisibility(View.INVISIBLE);
    }
    return convertView;
  }
  
  public static class ViewHolder
  {
    ImageView iconCheck;
    TextView nameLabel;
    //TextView timeLabel;
  }
  
  public void refreshAdapter(List<ParseUser> users)
  {
    mFriends.clear();
    mFriends.addAll(users);
    notifyDataSetChanged();
  }

}




Java Source Code List

com.pkmmte.circularimageview.CircularImageView.java
com.shivamb7.chitchat.AddFriendsActivity.java
com.shivamb7.chitchat.ChatsActivity.java
com.shivamb7.chitchat.ComposeTextActivity.java
com.shivamb7.chitchat.ImageMessageActivity.java
com.shivamb7.chitchat.MainActivity.java
com.shivamb7.chitchat.ProfileActivity.java
com.shivamb7.chitchat.RecipientsActivity.java
com.shivamb7.chitchat.RegisterActivity2.java
com.shivamb7.chitchat.RegisterActivity.java
com.shivamb7.chitchat.adapters.ChatsAdapter.java
com.shivamb7.chitchat.adapters.FriendGridAdapter.java
com.shivamb7.chitchat.adapters.LevelAdapter.java
com.shivamb7.chitchat.fragments.ChatsFragment.java
com.shivamb7.chitchat.fragments.ContactsFragment.java
com.shivamb7.chitchat.fragments.ProfileFragment.java
com.shivamb7.chitchat.workers.ChitChatApplication.java
com.shivamb7.chitchat.workers.CircularImageView.java
com.shivamb7.chitchat.workers.Constants.java
com.shivamb7.chitchat.workers.Fab.java
com.shivamb7.chitchat.workers.FileHelper.java
com.shivamb7.chitchat.workers.ImageResizer.java
com.shivamb7.chitchat.workers.Level.java
com.shivamb7.chitchat.workers.RippleView.java
com.shivamb7.chitchat.workers.TypefaceSpan.java