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.common.config.HandsetOperation;
import cn.net.caoyao.cpzshandset.service.bll.UploadStatusBll;

public class UploadStatusAdapter extends BaseAdapter{/*
	private List<String> dates;
//	private List<HomeBean> homeBeans;
	private List<HandsetOperation> homeBeans;
	private UploadStatusBll uploadStatusBll;
	private int NO_DATE_VIEW = 0;
	private int NORMAL_VIEW = 1;
	
	public UploadStatusAdapter(List<String> dates,List<HandsetOperation> homeBeans,UploadStatusBll uploadStatusBll) {
		this.dates = dates;
		this.homeBeans = homeBeans;
		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){
			//显示无数据界面   
			
		} else {
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(R.layout.adapter_upload_status_item, parent, false);
				holder = new ViewHolder();
				holder.tv_date_str = (TextView) convertView.findViewById(R.id.tv_date_str);
				holder.tv_content_str = (TextView) convertView.findViewById(R.id.tv_content_str);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.tv_date_str.setText("时间："+dates.get(position));
			
			StringBuilder sb = new StringBuilder();
			for (HandsetOperation b : homeBeans) {
				sb.append(b.getOptionName() +"：");
				sb.append(uploadStatusBll.queryLabelCountByOptionAndDate(b.getOption(), dates.get(position))+" 个");
				sb.append("\n");
			}
			holder.tv_content_str.setText(sb.toString());
//			ActivateBean aBean = dates.get(dates.size()- position-1);
			
		}
		
		
		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,tv_content_str;
	}
	

*/

	private List<String> dates;
//	private List<HomeBean> homeBeans;
	private List<HandsetOperation> homeBeans;
	private UploadStatusBll uploadStatusBll;
	private int NO_DATE_VIEW = 0;
	private int NORMAL_VIEW = 1;
	
	public UploadStatusAdapter(List<String> dates,List<HandsetOperation> homeBeans,UploadStatusBll uploadStatusBll) {
		this.dates = dates;
		this.homeBeans = homeBeans;
		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_upload_status_item, parent, false);
				holder = new ViewHolder();
				holder.tv_date_str = (TextView) convertView.findViewById(R.id.tv_date_str);
				holder.tv_content_str = (TextView) convertView.findViewById(R.id.tv_content_str);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.tv_date_str.setText("时间："+dates.get(position));
			
			StringBuilder sb = new StringBuilder();
			for (HandsetOperation b : homeBeans) {
				sb.append(b.getOptionName() +"：");
				sb.append(uploadStatusBll.queryLabelCountByOptionAndDate(b.getOption(), dates.get(position))+" 个");
				sb.append("\n");
			}
			holder.tv_content_str.setText(sb.toString());
//			ActivateBean aBean = dates.get(dates.size()- position-1);
			
		}
		
		
		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,tv_content_str;
	}
		
}
