package com.bc_chat.contacts.adapter

import android.content.Context
import com.bc_chat.bc_base.adapter.ModeListAdapter
import com.bc_chat.bc_base.entity.ListModel
import com.bc_chat.bc_base.entity.group.MemberBean
import com.bc_chat.bc_base.utils.gone
import com.bc_chat.bc_base.utils.visible
import com.bc_chat.contacts.R
import com.bc_chat.contacts.databinding.ItemLayoutContactBinding
import com.zhaohaoting.framework.abs.adapter.AbsRecyclerAdapter
import com.zhaohaoting.framework.utils.glid.GlideUtils


/**
 * author：Created by zhaohaoting on 2019/2/27
 * email：526309416@qq.com
 * desc：可选择
 */
class SelectMemberListAdapter constructor(var mContext: Context, var singSelect: Boolean? = false) : ModeListAdapter<MemberBean, ListModel<MemberBean>>(mContext, ListModel<MemberBean>()) {

    private var isShowTitle: Boolean? = true

    override fun getItemLayoutId(type: Int): Int = R.layout.item_layout_contact

    override fun onBindViewHolderHF(baseViewHolder: AbsRecyclerAdapter.BaseViewHolder<*>, realPosition: Int, contacts: MemberBean) {
        val dataBinding = baseViewHolder.dataBinding as ItemLayoutContactBinding
        //是否是单选
        if (singSelect!!) {
            dataBinding.tvState.gone()
        } else {
            dataBinding.tvState.visible()
            dataBinding.tvState.isSelected = contacts.isSelect
        }
        if (isShowTitle!! && contacts.isTop) {
            dataBinding.tvLettersTitle.visible()
        } else {
            dataBinding.tvLettersTitle.gone()
        }
        dataBinding.tvLettersTitle.text = contacts.firstLetter
        dataBinding.tvName.text = contacts.remark ?: contacts.nickname
        GlideUtils.loadCircleImage(mContext, contacts.photo, dataBinding.ivHeader)
        //如果是多选则重写点击方法
        if (!singSelect!!) {
            baseViewHolder.itemView.setOnClickListener {
                if (onItemClickListener != null) {
                    contacts.isSelect = !contacts.isSelect
                    dataBinding.tvState.isSelected = contacts.isSelect
                    onItemClickListener.onItemClick(baseViewHolder, realPosition)
                }
            }
        }
    }
}
