package com.wisewoods.eduandroid.ui.adapter.provider;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.wisewoods.base.bean.TreePeopleBean;
import com.wisewoods.eduandroid.R;

import org.jetbrains.annotations.NotNull;

public class ThirdProvider extends BaseNodeProvider {

    @Override
    public int getItemViewType() {
        return 1;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_recycler_people;
    }

    @Override
    public void convert(@NotNull BaseViewHolder helper, @NotNull BaseNode data) {
        TreePeopleBean.DataBean dataBean = (TreePeopleBean.DataBean) data;
        helper.setText(R.id.tv_name, dataBean.deptName);

        TextView view = helper.getView(R.id.tv_name);
        Drawable drawable = view.getResources().getDrawable(dataBean.isCheck ?
                R.drawable.ic_metting_people_check : R.drawable.ic_metting_people_default);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(drawable, null, null, null);
    }

    @Override
    public void onClick(@NonNull BaseViewHolder helper, @NonNull View view, BaseNode data, int position) {
        TreePeopleBean.DataBean dataBean = (TreePeopleBean.DataBean) data;
        dataBean.isCheck = !dataBean.isCheck;
        getAdapter().notifyItemChanged(position);
    }
}
