package com.itant.joycity.adapter;

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 com.itant.joycity.R;
import com.itant.joycity.bean.Kefu;
import com.itant.joycity.bean.WechatKefu;

import java.util.List;

/**
 * Created by Jason on 2016/10/6.
 * 图片列表适配器
 */
public class WechatKefuAdapter extends BaseAdapter {

    private List<WechatKefu> kefus;
    private Context context;


    public WechatKefuAdapter() {

    }

    public WechatKefuAdapter(Context context, List<WechatKefu> kefus) {
        this.kefus = kefus;
        this.context = context;
    }

    @Override
    public int getCount() {
        return kefus == null ? 0 : kefus.size();
    }

    @Override
    public Object getItem(int position) {
        return kefus == null ? null : kefus.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        WechatKefu kefu = kefus.get(position);

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_kefu_wechat, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_kefu_wechat_name = (TextView) convertView.findViewById(R.id.tv_kefu_wechat_name);
            viewHolder.tv_kefu_wechat_number = (TextView) convertView.findViewById(R.id.tv_kefu_wechat_number);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_kefu_wechat_name.setText(kefu.getName());
        viewHolder.tv_kefu_wechat_number.setText(kefu.getNumber());

        return convertView;
    }


    private ViewHolder viewHolder;
    private static class ViewHolder {
        TextView tv_kefu_wechat_name;
        TextView tv_kefu_wechat_number;
    }
}
