package com.wassim.androidmvpbase.util;

import android.os.Handler;
import android.os.Looper;

import com.squareup.otto.Bus;

import javax.inject.Inject;
import javax.inject.Singleton;

import rx.Observable;
import rx.functions.Action0;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;
import rx.subjects.SerializedSubject;
import rx.subjects.Subject;

/**
 * Provides helper methods to post event to an Otto event bus
 */
@Singleton
public class RxEventBusHelper {

    private final PublishSubject _bus = PublishSubject.create();

    @Inject
    public RxEventBusHelper() {
    }

    /**
     * Pass any event down to event listeners.
     */
    public void send(final Object object) {
        Schedulers.io().createWorker().schedule(new Action0() {
            @Override
            public void call() {
                _bus. onNext(object);
            }
        });

    }

    /**
     * Subscribe to this Observable. On event, do something
     * e.g. replace a fragment
     */
    public Observable<Object> toObserverable() {
        return _bus;
    }

    public boolean hasObservers(){
        return _bus.hasObservers();
    }
}

@@ -501,30 +501,63 @@
 nal 
-PublishSubject _bus = 
+Subject%3CObject, Object%3E _bus = new SerializedSubject%3C%3E(
 Publ
@@ -575,16 +575,17 @@
 create()
+)
 ;%0A%0A    @
@@ -741,136 +741,8 @@
 ) %7B%0A
-        Schedulers.io().createWorker().schedule(new Action0() %7B%0A            @Override%0A            public void call() %7B%0A         
     
@@ -770,35 +770,8 @@
 t);%0A
-            %7D%0A        %7D);%0A%0A
     

set Rx bus to be thread safe with SerializedSubject