package com.dniemcu.gui;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.dniemcu.R;
import com.dniemcu.PDFSigned.PDFItem;

public class CustomPdfAdapter extends ArrayAdapter<PDFItem> {
 	    
		Context context;
 	    String 	filename;
 	   
 	    public CustomPdfAdapter(Context context, String fileName, int textViewResourceId, List<PDFItem> objects) {
 	        super(context, textViewResourceId, objects);
 	        // TODO Auto-generated constructor stub
 	        this.context = context;
 	        this.filename = fileName;
 	    }

 	    /*private view holder class*/
 	    private class ViewHolder {
 	        private TextView txtFileName;
 	        private TextView txtFileDesc1;
 	        private TextView txtFileDesc2;
 	    }
 	    
 	    public View getView(int position, View convertView, ViewGroup parent) {
 	        ViewHolder holder;
 	        PDFItem rowItem = getItem(position);

 	        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
 	        if (convertView == null) {
 	            convertView = mInflater.inflate(R.layout.rowsignedoperation, parent, false);
 	            holder = new ViewHolder();
 	            holder.txtFileName 	= (TextView) convertView.findViewById(R.id.txtFile);
 	            holder.txtFileDesc1 = (TextView) convertView.findViewById(R.id.txtDescr1);
 	            holder.txtFileDesc2 = (TextView) convertView.findViewById(R.id.txtDescr2);
 	           convertView.findViewById(R.id.Btn_DESTROYENTRY).setVisibility(Button.INVISIBLE);
 	             
 	            convertView.setTag(holder);
 	        } else
 	            holder = (ViewHolder) convertView.getTag();

            // Ajustamos los textos y el tipo de letra
            Typeface type = Typeface.createFromAsset(context.getAssets(),"fonts/NeutraText-LightAlt.otf");
            holder.txtFileName.setText(rowItem.getFileName());
            holder.txtFileName.setTypeface(type);
            holder.txtFileDesc1.setText(rowItem.getDescription(1));
            holder.txtFileDesc1.setTypeface(type);
            holder.txtFileDesc2.setText(rowItem.getDescription(2));
            holder.txtFileDesc2.setTypeface(type);
            
            if(rowItem.isSelected) {
            	convertView.setBackgroundColor(Color.rgb(192, 199, 78));
            	holder.txtFileName.setTextColor(Color.WHITE);
            	holder.txtFileDesc1.setTextColor(Color.WHITE);
            	holder.txtFileDesc2.setTextColor(Color.WHITE);
            }
            else {
            	convertView.setBackgroundColor(Color.TRANSPARENT);
            	holder.txtFileName.setTextColor(Color.BLACK);
            	holder.txtFileDesc1.setTextColor(Color.GRAY);
            	holder.txtFileDesc2.setTextColor(Color.GRAY);
            }
 	        
 	        return convertView;
 	    }
}