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

public class ListStationDesAdapter extends BaseAdapter {
	private List<StationManagerBean> datas;

	private int NO_DATE_VIEW = 0;
	private int NORMAL_VIEW = 1;
	private boolean isAll = true;
	private boolean isTrain = true;

	public ListStationDesAdapter(List<StationManagerBean> datas,boolean isAll,boolean isTrain) {
		this.datas = datas;
		this.isAll = isAll;
		this.isTrain = isTrain;
	}

	public void refreshData(List<StationManagerBean> objects) {
		this.datas = objects;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {

		return datas.size() == 0 ? 1 : datas.size();
	}

	@Override
	public Object getItem(int position) {
		return datas.size() == 0 ? position : datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public int getItemViewType(int position) {
		return datas.size() == 0 ? NO_DATE_VIEW : NORMAL_VIEW;
	}

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

	@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);
			if (isAll) {
				tv_no_data_tips.setText("没有查询到地址信息，快去设置中更新地址列表，如果您确定地址信息存在，请检测该地址的合法性^_^");
			} else {
				tv_no_data_tips.setText("");
			}
			
		} else {
			if (convertView == null) {
				convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.spiner_item_text_layout, parent,
						false);
				holder = new ViewHolder();
				holder.mTextView = (TextView) convertView.findViewById(R.id.tv_spinner_item);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			if (isTrain) {
				holder.mTextView.setText(datas.get(position).getStationdec() + "");
			} else {
				holder.mTextView.setText(datas.get(position).getStationname() + "   " + datas.get(position).getStationdec());
			}
			
		}
		return convertView;
	}

	public static class ViewHolder {
		public TextView mTextView;
	}

}
