package com.lianxin.pubqq.ulive.adpter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lianxin.pubqq.R;

import com.lianxin.panqq.list.adpter.BaseLiveSearchAdapter;
import com.lianxin.panqq.main.bean.LivePerson;

public class LiveSearchAdapter extends BaseLiveSearchAdapter{

	public LiveSearchAdapter(Context context,List<LivePerson> userList) {
	    super(context,userList);

	}

	@Override
	public void setData(Object object) {
		this.mList = (List<LivePerson>)object; 
	} 		
	
	@Override
	public int getCount() {
		return mList==null?0:mList.size();
	}

	@Override
	public LivePerson getItem(int position) {
		return mList.get(position);
	}

 
	
	 @Override
	public long getItemId(int position) {

		return position;		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
	    final ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.layout_item_live, null);
			holder.imageView = (ImageView)convertView.findViewById(R.id.img_item_gridview);
			holder.roomState = (TextView)convertView.findViewById(R.id.tv_roomname);
			holder.nickName = (TextView)convertView.findViewById(R.id.tv_nickname);			
			holder.onlineNum = (TextView) convertView.findViewById(R.id.tv_onlinenum);
		//	holder.rl_liveicon = (RelativeLayout) convertView.findViewById(R.id.rl_liveicon);		
		//	holder.command = (Button) convertView.findViewById(R.id.command);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
	//	if(position<80){
		final LivePerson person = getItem(position);
	  //  holder.img_gridview.setImageURI(person.getPictureUrl());
	    holder.roomState.setText(person.getRoomName());
	    holder.nickName.setText(person.getNickName());
	    String str = ""+person.getNickName()+",女,18岁,云南大理";
	    holder.nickName.setText(str);	    
	    holder.onlineNum.setText("观看人数:"+person.getOnlineNum());
		//setImageView(imageView, url);	    
	  /*  holder.rl_liveicon.setBackgroundResource(R.drawable.live_header_live_type_pc);
        if (person.getMode() == 201) {
            holder.rl_liveicon.setBackgroundResource(R.drawable.live_header_live_type_mobile);
        }	*/    

		return convertView;
	}

	private static class ViewHolder {

		public ImageView imageView;		
        //        房间名称
        public TextView roomState;
        //        在线人数
        public TextView onlineNum;
        //        昵称
        public TextView nickName;
	}

	private void setImageView(ImageView imageView, String key) {
		Bitmap bitmap = getBitmapFromMemCache(key);		
		if (bitmap != null) {
			imageView.setImageBitmap(bitmap);
		} else {
			imageView.setImageResource(R.drawable.empty_photo);
		}
	}
	
	public int UpdataItem( int userid, Bitmap bitmap ) {
		//String url = ""+userid;	
		//addLruCache(url, bitmap);		
		int position = getItemPosition(userid);		
		//View view = gridView.getChildAt(position);	
		//View view = getChildAt(position);
		View view = getView(position,null,null);		
		ImageView imageView = (ImageView) view.findViewById(R.id.photo);
		imageView.setImageBitmap(bitmap);		
		return 1;
	}
	public int getItemPosition(int userid) {
	    for(int i=0;i<mList.size();i++)
	    {
	    	if(mList.get(i).sendid == userid )
	    	    return i;	        
	    } 		
		return 0;
	}	

}
