package com.tencent.liteav.live.ui.widget;

import android.graphics.Color;

import com.tencent.liteav.live.R;
import com.tencent.liteav.live.ui.MemberEntity;
import com.wisewoods.base.base.BaseVH;
import com.wisewoods.base.bean.RedisList;
import com.wisewoods.base.page.BasePageAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 直播间列表适配器
 */
public class RoomListAdapter extends BasePageAdapter<RedisList.RedisData.DataBean> {
    ArrayList<RedisList.RedisData.DataBean> mInviteList;
    List<MemberEntity> mMemberEntityList;
    String key;

    public RoomListAdapter(ArrayList<RedisList.RedisData.DataBean> mInviteList, String key, List<MemberEntity> mMemberEntityList) {
        super(R.layout.item_recycler_live_user_list);
        addChildClickViewIds(R.id.tv_invite, R.id.tv_mute, R.id.tv_close);
        this.mInviteList = mInviteList;
        this.mMemberEntityList = mMemberEntityList;
        this.key = key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    @Override
    protected void convert(@NotNull BaseVH baseVH, RedisList.RedisData.DataBean dataBean) {
        boolean flag = false;
        boolean hasMe = false;
        for (RedisList.RedisData.DataBean bean : this.mInviteList) {
            if (bean.id.equals(dataBean.id)) {
                flag = true;
            }
        }
        for (MemberEntity memberEntity : mMemberEntityList) {
            if (memberEntity.getUserId().equals(dataBean.id)) {
                flag = true;
                hasMe = true;
            }
        }
        baseVH.setText(R.id.tv_name, dataBean.name)
                .setTextColor(R.id.tv_name, dataBean.state == 0 ? Color.parseColor("#cccccc") :
                        Color.parseColor("#313131"))
                .setGone(R.id.tv_invite, "teacherMap".equals(key) || dataBean.state == 0 || flag)
                .setGone(R.id.tv_mute, "teacherMap".equals(key) || dataBean.state == 0)
                .setGone(R.id.tv_close, !(hasMe && (dataBean.id.startsWith("work_") || dataBean.id.startsWith("student_"))))
                .setNetUrl(R.id.iv_avatar, dataBean.picUrl, R.drawable.trtcmeeting_meeting_head)
                .setImageResource(R.id.iv_status, dataBean.state == 0 ? R.drawable.shape_point_live_off :
                        R.drawable.shape_point_live_on)
                .setTextTop(R.id.tv_mute, dataBean.talkStatus == 0 ? R.drawable.ic_mute :
                        R.drawable.ic_mute_no)
                .setText(R.id.tv_mute, dataBean.talkStatus == 0 ? "禁言" : "取消")
        ;
    }
}
