package com.sheep.gamegroup.view.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sheep.gamegroup.model.entity.FaqMsg;
import com.sheep.gamegroup.util.GlideImageLoader;
import com.sheep.gamegroup.util.ListUtil;
import com.sheep.gamegroup.util.TimeUtil;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.jiuyan.samllsheep.R;

import java.util.List;

/**
 * created on：2018/8/28 on 17:26
 * created by: YSL
 * 描述:消息互动中item点击展开后FAQ的形式
 */
public class AdpMsgFaq extends RecyclerView.Adapter<AdpMsgFaq.MyHolder> {
    private Context mContext;
    private List<FaqMsg> list;

    public AdpMsgFaq(Context mContext, List<FaqMsg> list) {
        this.mContext = mContext;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view;
        view = LayoutInflater.from(mContext).inflate(R.layout.adapter_message_interaction, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder viewHolder, int i) {
        FaqMsg item = ListUtil.getItem(list, i);
        if(item != null) {
            if(item.getAvatar() != null)
                GlideImageLoader.setAvatar(viewHolder.ivIcon, item.getAvatar());
            viewHolder.tvPeople.setText(item.getName());
            viewHolder.tvTime.setText(TimeUtil.TimeStamp2Date(item.getTime(), "MM-dd HH:mm"));
            viewHolder.tvContent.setText(item.getContent());
        } else {
            ViewUtil.setDefaultText(viewHolder.tvPeople);
            ViewUtil.setDefaultText(viewHolder.tvTime);
            ViewUtil.setDefaultText(viewHolder.tvContent);
        }


    }

    @Override
    public int getItemCount() {
        return ListUtil.size(list);
    }

    class MyHolder extends RecyclerView.ViewHolder {
        private ImageView ivIcon;//头像
        private TextView tvPeople;//标题
        private TextView tvTime;//谁的消息
        private TextView tvContent;//每条消息的内容，这里最多只显示一行

        public MyHolder(View view) {
            super(view);
            ivIcon = view.findViewById(R.id.iv_icon);
            tvPeople = view.findViewById(R.id.tv_people);
            tvTime = view.findViewById(R.id.tv_time);
            tvContent = view.findViewById(R.id.tv_content);
        }
    }
}
