package com.android.chmo.ui.adpater;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.chmo.R;
import com.android.chmo.base.BaseActivity;
import com.android.chmo.http.HttpApi;
import com.android.chmo.model.CommentInfo;
import com.android.chmo.utils.DateUtils;
import com.android.chmo.utils.XUtilsImage;
import com.netease.nim.avchatkit.common.util.TimeUtil;

import java.util.Date;


public class CommentAdapter extends CommonAdapter<CommentInfo> {
    private BaseActivity baseActivity;


    public CommentAdapter(BaseActivity activity) {
        super(activity);
        baseActivity = activity;
    }
    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(null != convertView) {
            holder = (ViewHolder) convertView.getTag();
        }
        if(null == holder) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.list_comment_item,null);
            holder.headView = (ImageView) convertView.findViewById(R.id.head);
            holder.nameView = (TextView) convertView.findViewById(R.id.name);
            holder.contentView = (TextView) convertView.findViewById(R.id.content);
            holder.timeView = (TextView) convertView.findViewById(R.id.time);
            convertView.setTag(holder);
        }

        final CommentInfo info = mList.get(position);
        XUtilsImage.displayCircluar(holder.headView, HttpApi.getImgUrl(info.hphoto),R.mipmap.def_head);
        holder.nameView.setText(info.pet);
        holder.contentView.setText(info.intro);
        holder.timeView.setText(getTimeStr(info.idate));
        return convertView;
    }

    private String getTimeStr(String date) {
       Date d = DateUtils.parseDateTime(date);
       return TimeUtil.getTimeShowString(d.getTime(),false);
    }


    class ViewHolder {
        ImageView headView;
        TextView nameView;
        TextView contentView;
        TextView timeView;
    }
}
