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.LinearLayout;
import android.widget.TextView;

import com.sheep.gamegroup.util.GlideImageLoader;
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 MessageInteractionAdapter extends RecyclerView.Adapter<MessageInteractionAdapter.MyHolder> {
    private Context mContext;
    private List<?> mList;

    public MessageInteractionAdapter(Context mContext, List<?> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

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

    @Override
    public void onBindViewHolder(@NonNull MyHolder viewHolder, int i) {
        if (mList == null || mList.isEmpty()) {
            return;
        } else {
            if (i == mList.size() - 1) {
                viewHolder.viewLine.setVisibility(View.GONE);//最后一条数据隐藏线条
            }
            GlideImageLoader.centerImage(viewHolder.ivIcon, "");
            viewHolder.tvPeople.setText("");
            viewHolder.tvTime.setText("");
            viewHolder.tvContent.setText("");
        }
    }

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

    class MyHolder extends RecyclerView.ViewHolder {
        private ImageView ivIcon;//头像
        private TextView tvPeople;//标题
        private TextView tvTime;//谁的消息
        private TextView tvContent;//每条消息的内容，这里最多只显示一行
        private View viewLine;//item之间的线条
        private LinearLayout itemLayout;//整个item布局

        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);
            viewLine = view.findViewById(R.id.view_line);
            itemLayout = view.findViewById(R.id.item_layout);
        }
    }
}
