package com.example.waoperations.Transference;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;

import com.example.waoperations.Transference.TransferenceItemSummary;
import java.util.Locale;
import android.content.Intent;
import android.widget.BaseAdapter;
import com.example.waoperations.R;

public class TransferenceAdapterZ extends CursorAdapter {
	
	  public TransferenceAdapterZ(Context context, Cursor cursor) {
          super(context, cursor);
          }
	
	   @Override
	      public void bindView(View view, Context context, Cursor cursor) {
	  		if (view == null) {
	              LayoutInflater mInflater = (LayoutInflater)
	                      context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
	              view = mInflater.inflate(R.layout.drawer_list_item, null);
	          }
	          Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/opensans-light.ttf");  
	          Typeface fontbold = Typeface.createFromAsset(context.getAssets(), "fonts/opensans-semibold.ttf");  
	          
	                    
	          TextView TransferTextView = (TextView) view.findViewById(R.id.PedidoCompraZ);
	          TransferTextView.setText(cursor.getString(2));
	          TransferTextView.setTextColor(Color.BLACK);
	          TransferTextView.setTypeface(fontbold); 
	          TransferTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
	          
	          TextView HastaTextView = (TextView) view.findViewById(R.id.inventlocationidtoZ);
	          HastaTextView.setText(cursor.getString(8)+"  ("+cursor.getString(7)+")");
	          HastaTextView.setTextColor(Color.BLACK);
	          HastaTextView.setTypeface(fontbold); 
	          HastaTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
	          
	          TextView FechaEnvioTextView = (TextView) view.findViewById(R.id.shipIdZ);
	          FechaEnvioTextView.setText(cursor.getString(3));
	          FechaEnvioTextView.setTextColor(Color.BLACK);
	          FechaEnvioTextView.setTypeface(fontbold); 
	          FechaEnvioTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
	          
	  
	          TextView QtyReservadaView = (TextView) view.findViewById(R.id.qtyreservaZ);
	          QtyReservadaView.setText(cursor.getString(11)+"  ("+cursor.getString(15)+")");
	          QtyReservadaView.setTextColor(Color.BLACK);
	          QtyReservadaView.setTypeface(fontbold); 
	          QtyReservadaView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
	          
	          
	          TextView QtyDespachadatView = (TextView) view.findViewById(R.id.qtydespZ);
	          QtyDespachadatView.setText(cursor.getString(6)+"  ("+cursor.getString(15)+")");
	          QtyDespachadatView.setTextColor(Color.BLACK);
	          QtyDespachadatView.setTypeface(fontbold); 
	          QtyDespachadatView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
	          
	          Double contado;
	          Double reservada;
	      
				contado =  Double.parseDouble(cursor.getString(6));//6 QTYCOUNTED
				reservada= Double.parseDouble(cursor.getString(11));//15 RESERVPHYSICAL

		          try{
				          if(reservada>0.0 && contado==0.0){
				        	  view.setBackgroundResource(R.color.LightBlue);	
					            ImageView imageViewStatus = (ImageView) view.findViewById(R.id.imageViewStatus);
					            imageViewStatus.setImageResource(R.drawable.empty);
				           	}else if(reservada==0.0 && contado>0.0){
				           		view.setBackgroundResource(R.color.GreenYellow);
				        	    ImageView imageViewStatus = (ImageView) view.findViewById(R.id.imageViewStatus);
				        	    imageViewStatus.setImageResource(R.drawable.up);
				        	}else if(reservada>0.0 && contado>0.0){
				        		view.setBackgroundResource(R.color.IndianRed);	
					            ImageView imageViewStatus = (ImageView) view.findViewById(R.id.imageViewStatus);
					            imageViewStatus.setImageResource(R.drawable.down);
				        	}else{
				        		view.setBackgroundResource(R.color.White);
				             	ImageView imageViewStatus = (ImageView) view.findViewById(R.id.imageViewStatus);
				             	imageViewStatus.setImageResource(R.drawable.empty);
				        	}
		          }catch(Exception exc){} 
	  
	         }

	      @Override
	      public View newView(Context context, Cursor cursor, ViewGroup parent) {
	              LayoutInflater inflater = LayoutInflater.from(parent.getContext());
	              View view = inflater.inflate(R.layout.transference_all_list_z, parent, false);
	              return view;
	      }

}
