package com.phlx.wool.ui.adapter;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;

import com.phlx.wool.databinding.ItemUnitRvBinding;
import com.phlx.wool.ui.work.unit.UnitItem;

import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter;

/**
 * <pre>
 *     author : lei
 *     e-mail : 18600395998@163.com
 *     time   : 2019/12/26
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class UnitAdapter extends BindingRecyclerViewAdapter<UnitItem> {

    private int selPosition = -1;
    private Context mContext;

    public UnitAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void onBindBinding(@NonNull ViewDataBinding binding, int variableId, int layoutRes,
                              int position, UnitItem item) {
        super.onBindBinding(binding, variableId, layoutRes, position, item);

        ItemUnitRvBinding itemRvBinding = (ItemUnitRvBinding) binding;

        if (selPosition == position) {
            itemRvBinding.selectStatus.setChecked(true);
        } else {
            itemRvBinding.selectStatus.setChecked(false);
        }
    }
    public void setItemSel(int selPosition) {
        this.selPosition = selPosition;
        notifyDataSetChanged();
    }
}
