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.ListView;
import android.widget.TextView;
import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.bean.ShipmentUploadRecordBean;
import cn.net.caoyao.cpzshandset.service.bll.ShipmentUploadStatusBll;

public class ShipmentUploadStatusAdapter extends BaseAdapter{
	private List<String> dates;
	private ShipmentUploadStatusBll uploadStatusBll;
	private int NO_DATE_VIEW = 0;
	private int NORMAL_VIEW = 1;
	
	public ShipmentUploadStatusAdapter(List<String> dates,ShipmentUploadStatusBll uploadStatusBll) {
		this.dates = dates;
		this.uploadStatusBll = uploadStatusBll;
	}
	
	@Override
	public int getCount() {
		return dates.size() == 0? 1: dates.size();
	}
	@Override
	public Object getItem(int position) {
		return dates.size() == 0? position:dates.get(dates.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_shipment_upload_status_item, parent, false);
				holder = new ViewHolder();
				holder.tv_date_str = (TextView) convertView.findViewById(R.id.tv_date_str);
				holder.lv_shipment_upload_status = (ListView) convertView.findViewById(R.id.lv_shipment_upload_status);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.tv_date_str.setText("时间："+dates.get(position));
			List<ShipmentUploadRecordBean> uploads = uploadStatusBll.queryAllUploadStatus(dates.get(position));
			ShipmentUploadStatusItemAdapter adapter = new ShipmentUploadStatusItemAdapter(uploads);
			holder.lv_shipment_upload_status.setAdapter(adapter);
		}
		
		
		return convertView;
	}
	
	@Override
	public int getItemViewType(int position) {
		return dates.size() == 0?NO_DATE_VIEW : NORMAL_VIEW;
	}
	
	

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



	private class ViewHolder{
		private TextView tv_date_str;
		private ListView lv_shipment_upload_status;
	}
	

}
