package com.common.im.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.common.im.bean.GroupMemberBean;
import com.common.im_ui.R;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.usercenter.helper.UserHelper;

import java.util.List;

/**
 * 创建日期：2022/6/13 15:54
 *
 * @author Ryan
 * 类说明：
 */
public class GroupMemberAdapter extends BaseQuickAdapter<GroupMemberBean, BaseViewHolder> {
    private String currentId;

    public GroupMemberAdapter(List<GroupMemberBean> data) {
        super(R.layout.group_member_list_item, data);
        currentId = UserHelper.getUserId();
    }


    @Override
    protected void convert(BaseViewHolder helper, GroupMemberBean bean) {

        ImageView ivIcon = helper.getView(R.id.iv_icon);
        TextView tvTitle = helper.getView(R.id.tv_title);
        TextView tvType = helper.getView(R.id.tv_type);
        View viewLine = helper.getView(R.id.view_line);
        ImageView imageView2 = helper.getView(R.id.imageView2);
        int position = getItemPosition(bean);
        if (position == getItemCount() - 1 || !bean.getSuspensionTag().equals(getData().get(position + 1).getSuspensionTag())) {
            viewLine.setVisibility(View.INVISIBLE);
        } else {
            viewLine.setVisibility(View.VISIBLE);
        }

        if (null != bean) {
            String roleType = bean.getRoleType();
            GlideUtils.INSTANCE.loadImage(getContext(), bean.getAvatar(), ivIcon);
            tvTitle.setText(bean.getNickname());
            if (TextUtils.equals(currentId, bean.getUserId())) {
                imageView2.setVisibility(View.GONE);
            } else {
                imageView2.setVisibility(View.VISIBLE);
            }
        }


    }

}
