package io.rong.contactcard.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.bc_chat.bc_base.adapter.ModeListAdapter;
import com.bc_chat.bc_base.entity.ListModel;
import com.bc_chat.bc_base.entity.UserInfo;
import com.zhaohaoting.framework.abs.adapter.AbsRecyclerAdapter;
import com.zhaohaoting.framework.utils.glid.GlideUtils;

import io.rong.contactcard.R;
import io.rong.contactcard.databinding.ItemLayoutSelectContactBinding;


/**
 * author：Created by zhaohaoting on 2019/2/27
 * email：526309416@qq.com
 * desc：可选择
 */
public class SelectContactListAdapter extends ModeListAdapter<UserInfo, ListModel<UserInfo>> {

    public SelectContactListAdapter(Context context) {
        super(context, new ListModel());
    }

    private boolean isShowTitle = true;

    public void setShowTitle(boolean showTitle) {
        isShowTitle = showTitle;
    }

    @Override
    public int getItemLayoutId(int type) {
        return R.layout.item_layout_select_contact;
    }

    @Override
    public void onBindViewHolderHF(AbsRecyclerAdapter.BaseViewHolder baseViewHolder, int realPosition, UserInfo contacts) {
        ItemLayoutSelectContactBinding dataBinding = (ItemLayoutSelectContactBinding) baseViewHolder.getDataBinding();
        if (isShowTitle && contacts.isTop()) {
            dataBinding.tvLettersTitle.setVisibility(View.VISIBLE);
        } else {
            dataBinding.tvLettersTitle.setVisibility(View.GONE);
        }
        dataBinding.tvLettersTitle.setText(contacts.getFirstLetter());
        dataBinding.tvName.setText(TextUtils.isEmpty(contacts.getRemark())?contacts.getNickname():contacts.getRemark());
        GlideUtils.loadCircleImage(context, contacts.getPhoto(), dataBinding.ivHeader);
        //如果是多选则重写点击方法
//        if (!singSelect!!) {
//            baseViewHolder.itemView.setOnClickListener {
//                if (onItemClickListener != null) {
//                    contacts.isSelect = !contacts.isSelect
//                    dataBinding.tvState.isSelected = contacts.isSelect
//                    onItemClickListener.onItemClick(baseViewHolder, realPosition)
//                }
//            }
//        }
    }
}
