package com.wd.workoffice.ui.adapter;


import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wd.workoffice.R;
import com.wd.workoffice.bean.FinancialTypeBean;
import com.wd.workoffice.bean.event.AddFinancialNumEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by flexible on 2018/8/13.
 */

public class FinancialAddAdapter extends BaseQuickAdapter<FinancialTypeBean, BaseViewHolder> {
    Map<Integer, String> num = new HashMap<>();

    public FinancialAddAdapter(int layoutResId, List data) {
        super(layoutResId, data);
    }

    public Map<Integer, String> getNum() {
        return num;
    }

    public void setNum(Map<Integer, String> num) {
        this.num = num;
    }

    @Override
    protected void convert(BaseViewHolder helper, FinancialTypeBean item) {
        helper.setText(R.id.tv_name, item.getName());
        EditText etNum = helper.getView(R.id.et_num);
        etNum.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                num.put(helper.getAdapterPosition(), s.toString());
                EventBus.getDefault().post(new AddFinancialNumEvent());
            }
        });
    }
}

