package com.cwbuyer.adapter;

import java.util.HashMap;
import java.util.List;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cwbuyer.lib.Utilis;
import com.pwbuyer.main.R;

@SuppressLint("InflateParams")
public class MyAdapter1 extends BaseAdapter {
	private Context context = null;
    private LayoutInflater inflater = null;
    private List<HashMap<String, Object>> list = null;
    private String keyString[] = null;
    private String itemString = null; 
   
    private int idValue[] = null;

    public MyAdapter1(Context context, List<HashMap<String, Object>> list,
             String[] from, int[] to) {
        this.context = context;
        this.list = list;
        keyString = new String[from.length];
        idValue = new int[to.length];
        System.arraycopy(from, 0, keyString, 0, from.length);
        System.arraycopy(to, 0, idValue, 0, to.length);
        inflater = LayoutInflater.from(context);
        
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        return list.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

	@SuppressWarnings("unused")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
           ViewHolder1 holder = null;
            if (holder == null) {
                holder = new ViewHolder1();
                if (convertView == null) {
                	convertView = inflater.inflate(R.layout.cust_adapter, null);
                }
                holder.tv = (TextView) convertView.findViewById(idValue[0]);
                holder.tv2 = (TextView) convertView.findViewById(idValue[1]);
                holder.tv5 = (TextView) convertView.findViewById(idValue[2]);
                holder.tv6 = (TextView) convertView.findViewById(idValue[3]);
                holder.tv7 = (TextView) convertView.findViewById(idValue[4]);
                holder.tv1 = (TextView) convertView.findViewById(idValue[5]);	                
                holder.iv1=(ImageView)convertView.findViewById(idValue[6]);
                holder.iv2 =(ImageView)convertView.findViewById(idValue[7]);
            
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder1) convertView.getTag();
            }	                
                
            HashMap<String, Object> map = list.get(position);
            if (map != null) {
                itemString = (String) map.get(keyString[0]);
                holder.tv.setText(itemString);
                itemString = (String) map.get(keyString[1]);
                holder.tv2.setText(itemString);
                itemString = (String) map.get(keyString[2]);
                holder.tv5.setText(itemString);
                itemString = (String) map.get(keyString[3]);
                holder.tv6.setText(itemString);
                itemString = (String) map.get(keyString[4]);
                holder.tv7.setText(itemString);
                itemString = (String) map.get(keyString[5]);
                holder.tv1.setText(itemString);
                
                itemString = (String) map.get(keyString[8]);
                if(itemString != null && itemString.length() > 0){	                
                	if( itemString.indexOf("drawable/") < 0) { 
        			Bitmap bmp=Utilis.getLimitBitmap( itemString,80,80);
        			if (bmp!=null)holder.iv1.setImageBitmap(bmp);
    				} else{ 
        				holder.iv1.setImageDrawable(Utilis.getResourceImage(context, itemString));
    				}	                
					} else {
    	    			holder.iv1.setImageResource(R.drawable.m053);    				
    			}
                
                itemString = (String) map.get(keyString[7]);
                if(itemString != null && itemString.length() > 0){	                
                	if( itemString.indexOf("drawable/") < 0) { 
        			Bitmap bmp=Utilis.getLimitBitmap( itemString,30,30);
        			if (bmp!=null)holder.iv2.setImageBitmap(bmp);
    				} else{ 
        				holder.iv2.setImageDrawable(Utilis.getResourceImage(context, itemString));
    				}	                
					} else {
    	    			holder.iv2.setImageResource(R.drawable.m053);    				
    			}

                
            }    
		
//        count++;
		return convertView;

	}
	
	public class ViewHolder1 {
        public TextView tv = null;
        public TextView tv2 = null;
        public TextView tv5 = null;
        public TextView tv6 = null;
        public TextView tv7 = null;
        public TextView tv1 = null;
        public ImageView iv1 = null;
        public ImageView iv2 =null;
    } 				

	

}
