package cn.net.caoyao.cpzshandset.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.bean.JinLiquorUploadBean;

public class JinLiquorUploadStatusAdapter extends BaseAdapter{
	private List<JinLiquorUploadBean> uploads;
	private int NO_DATE_VIEW = 0;
	private int NORMAL_VIEW = 1;
	
	public JinLiquorUploadStatusAdapter(List<JinLiquorUploadBean> uploads) {
		this.uploads = uploads;
	}
	
	public void refreshData(List<JinLiquorUploadBean> uploads){
		this.uploads = uploads;
	}
	@Override
	public int getCount() {
		return uploads.size() == 0? 1: uploads.size();
	}
	@Override
	public Object getItem(int position) {
		return uploads.size() == 0? position:uploads.get(uploads.size());
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		Context context = parent.getContext();
		
		if (getItemViewType(position) == NO_DATE_VIEW) {
			//显示无数据界面
			convertView = LayoutInflater.from(context).inflate(R.layout.adapter_no_data_view, parent,false);
			TextView tv_no_data_tips = (TextView) convertView.findViewById(R.id.tv_no_data_tips);
			tv_no_data_tips.setText("当天没有上传任何数据^_^");
		} else {
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(R.layout.adapter_item_shipment_upload_status_item, parent, false);
				holder = new ViewHolder();
				holder.tv_item_upload_status_serial = (TextView) convertView.findViewById(R.id.tv_item_upload_status_serial);
				holder.tv_item_upload_status_1 = (TextView) convertView.findViewById(R.id.tv_item_upload_status_1);
				holder.tv_item_upload_status_2 = (TextView) convertView.findViewById(R.id.tv_item_upload_status_2);
				holder.tv_item_upload_status_3 = (TextView) convertView.findViewById(R.id.tv_item_upload_status_3);
				holder.tv_item_upload_status_4 = (TextView) convertView.findViewById(R.id.tv_item_upload_status_4);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.tv_item_upload_status_serial.setText((uploads.size() -  position)+"");
			JinLiquorUploadBean b = uploads.get(position);
			
			holder.tv_item_upload_status_1.setText("单    号：" + b.getOutWarehouseNo().replaceAll("\\d{4}(?!$)", "$0  "));
			holder.tv_item_upload_status_2.setText("日    期：" + b.getUpload_date());
			holder.tv_item_upload_status_3.setText("数    量：" + b.getTray_count() +" 袋");
			holder.tv_item_upload_status_4.setText("经销商："+b.getDealer_name());
			
		}
		
		
		return convertView;
	}
	
	@Override
	public int getItemViewType(int position) {
		return uploads.size() == 0?NO_DATE_VIEW : NORMAL_VIEW;
	}
	
	

	@Override
	public int getViewTypeCount() {
		return 2;
	}



	private class ViewHolder{
		private TextView tv_item_upload_status_serial,tv_item_upload_status_1,tv_item_upload_status_2,tv_item_upload_status_3,tv_item_upload_status_4;
	}
	

}
