package com.phlx.wool.ui.inventory;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;


import com.phlx.wool.entity.Label;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

/**
 * <pre>
 *     author : lei
 *     e-mail : 18600395998@163.com
 *     time   : 2020/04/26
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class InventoryItem extends ItemViewModel<InventoryVM> {

    public ObservableField<Label> entity = new ObservableField<>();

    public InventoryItem(@NonNull InventoryVM viewModel, Label entity) {
        super(viewModel);
        this.entity.set(entity);
    }

    /**
     * 获取position的方式有很多种,indexOf是其中一种，常见的还有在Adapter中、ItemBinding.of回调里
     *
     * @return
     */
    public int getPosition() {
        return viewModel.getItemPosition(this);
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            //这里可以通过一个标识,做出判断，已达到跳入不同界面的逻辑
            if (entity.get().getId() == -1) {
                viewModel.deleteItemLiveData.setValue(InventoryItem.this);
            }
        }
    });
    //条目的长按事件
    public BindingCommand itemLongClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
           // ToastUtils.showShort(entity.get().getName());
        }
    });
}
