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.PackSubLabelInfoBean;

public class PackBoxSubLabelAdapter extends BaseAdapter{
	private List<PackSubLabelInfoBean> labels;
	public PackBoxSubLabelAdapter(List<PackSubLabelInfoBean> labels) {
		this.labels = labels;
	}
	
	public void refreshData(List<PackSubLabelInfoBean> labels){
		this.labels = labels;
//		LogUtil.i(TConfig.Echo, "labels:" + labels.toString());
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return labels.size();
	}

	@Override
	public Object getItem(int position) {
//		return labels.get(labels.size() - position -1);
		return labels.get(position);
	}

	@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 (convertView == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_single_label_item, parent, false);
			holder = new ViewHolder();
			holder.lin_single_label_root = convertView.findViewById(R.id.lin_single_label_root);
			holder.tv_single_label_serial = (TextView) convertView.findViewById(R.id.tv_single_label_serial);
			holder.tv_single_label_item_content = (TextView) convertView.findViewById(R.id.tv_single_label_item_content);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
//		SingleLabelOptionBean b = labels.get(labels.size() - position - 1);
		PackSubLabelInfoBean b = labels.get(position);
		holder.tv_single_label_serial.setText(labels.size() - position +"");
		String labelId = b.getSub_label_str();
		holder.tv_single_label_item_content.setText(labelId.replaceAll("\\d{4}(?!$)", "$0  "));
		
		return convertView;
	}

	private class ViewHolder{
		private TextView tv_single_label_serial;
		private TextView tv_single_label_item_content;
		private View lin_single_label_root;
	}
}
