package com.quansu.heifengwuliu.adapter;

import android.graphics.Paint;
import android.widget.TextView;

import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.quansu.heifengwuliu.R;
import com.quansu.heifengwuliu.databinding.ItemTodoBinding;
import com.quansu.heifengwuliu.model.Todo;
import com.quansu.heifengwuliu.vmodel.TodoListVModel;
import com.ysnows.base.base.BAdapter;

import org.jetbrains.annotations.NotNull;

public class TodosAdapter extends BAdapter<Todo, BaseDataBindingHolder<ItemTodoBinding>> {

    private TodoListVModel vm;

    public TodosAdapter(TodoListVModel vm) {
        super(R.layout.item_todo, null);
        this.vm = vm;
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<ItemTodoBinding> helper, Todo todo) {
        ItemTodoBinding binding = helper.getDataBinding();
        binding.setItem(todo);
        binding.setPosition(helper.getAdapterPosition());
        binding.setVm(vm);

        TextView tvName = helper.getView(R.id.tv_name);
        if (todo.checked == 1) {
            tvName.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        } else {
            tvName.getPaint().setFlags(0);  // 取消设置的的划线
        }

    }
}
