package com.lianxin.pubqq.ulive.adpter;

import java.util.List;



import com.lianxin.panqq.list.bean.Member;
import com.lianxin.panqq.utils.ImagesUtils;
//import com.item.jiejie.ProdctBean;
import com.lianxin.pubqq.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
 
/**
 * GridView加载数据的适配器
 * @author Administrator
 *
 */
public class MeetHeadGridAdapter extends BaseAdapter{
   
  private Context context;
  private List<Member> lists;//数据源
  private int mIndex; // 页数下标，标示第几页，从0开始
  private int mPargerSize;// 每页显示的最大的数量
     
  public MeetHeadGridAdapter(Context context, List<Member> lists,
      int mIndex, int mPargerSize) {
    this.context = context;
    this.lists = lists;
    this.mIndex = mIndex;
    this.mPargerSize = mPargerSize;
  }
 
  /**
   * 先判断数据及的大小是否显示满本页lists.size() > (mIndex + 1)*mPagerSize
   * 如果满足，则此页就显示最大数量lists的个数
   * 如果不够显示每页的最大数量，那么剩下几个就显示几个
   */
  @Override
  public int getCount() {
    // TODO Auto-generated method stub
    return lists.size() > (mIndex + 1) * mPargerSize ? 
        mPargerSize : (lists.size() - mIndex*mPargerSize);
  }
 
  @Override
  public Member getItem(int arg0) {
    // TODO Auto-generated method stub
    return lists.get(arg0 + mIndex * mPargerSize);
  }
 
  @Override
  public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return arg0 + mIndex * mPargerSize;
  }
 
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    
	if (convertView == null) {
		convertView = LayoutInflater.from(context).inflate(
				R.layout.item_meetaudio_gridview, null);
	}
	ImageView iv_avatar = (ImageView) convertView
			.findViewById(R.id.iv_avatar);
	TextView tv_username = (TextView) convertView
			.findViewById(R.id.tv_username);

		final Member user = lists.get(position);
		final String usernick = user.getName();
		final int userid = user.getUserId();
		int imageid = user.getHeadImg();
	if(userid<=1000){
		iv_avatar.setImageResource(R.drawable.empty_photo);	
		tv_username.setText("");				
	}else{
		if(imageid<0||imageid>80)
			imageid = imageid%80;
		//final String useravatar = user.getHeadUrl();
		tv_username.setText(usernick);

		iv_avatar.setImageResource(ImagesUtils.images[imageid]);							
//		iv_avatar.setImageResource(R.drawable.empty_photo);	
		iv_avatar.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {


			}
		});
	}
	return convertView;    
  }
  
	private static class ViewHolder {
		public ImageView imageView;	//缩略图	     
        public TextView nickName; //昵称
	}  
  
}