package com.philisense.rdgo.util;

import com.philisense.rdgo.ui.putIn.PutInOrderActivity;
import com.philisense.rdgo.ui.putOut.PutOutOrderActivity;

import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;

/**
 * Created by chenxiaopeng on 2017/12/28.
 */

public class TreeNodeInsertSubscribe implements ObservableOnSubscribe{

    private PutOutOrderActivity putOutOrderActivity;
    private PutInOrderActivity putInOrderActivity;

    public TreeNodeInsertSubscribe(PutOutOrderActivity activity) {
        this.putOutOrderActivity = activity;
    }

    public TreeNodeInsertSubscribe(PutInOrderActivity activity) {
        this.putInOrderActivity = activity;
    }

    @Override
    public void subscribe(ObservableEmitter e) throws Exception {
        if (putInOrderActivity != null) {
            putInOrderActivity.setInsertListener(new TreeNodeInsertListener() {
                @Override
                public void onInsert() {
                    e.onNext(1);
                }
            });
        }else if (putOutOrderActivity != null) {
            putOutOrderActivity.setInsertListener(new TreeNodeInsertListener() {
                @Override
                public void onInsert() {
                    e.onNext(1);
                }
            });
        }

    }
}
