package com.wassim.androidmvpbase.util;

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

import com.squareup.otto.Bus;

import javax.inject.Inject;

import rx.Observable;
import rx.subjects.PublishSubject;

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

    private static RxEventBusHelper instance;

    private PublishSubject<Object> subject = PublishSubject.create();

    @Inject
    public RxEventBusHelper() {
    }

    /**
     * Pass any event down to event listeners.
     */
    public void post(Object object) {
        subject.onNext(object);
    }

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

@@ -146,16 +146,47 @@
 .Inject;
+%0Aimport javax.inject.Singleton;
 %0A%0Aimport
@@ -211,16 +211,151 @@
 port rx.
+functions.Action0;%0Aimport rx.schedulers.Schedulers;%0Aimport rx.subjects.PublishSubject;%0Aimport rx.subjects.SerializedSubject;%0Aimport rx.
 subjects
@@ -347,39 +347,32 @@
 ort rx.subjects.
-Publish
 Subject;%0A%0A/**%0A *
@@ -435,16 +435,27 @@
 bus%0A */%0A
+@Singleton%0A
 public c
@@ -495,85 +495,33 @@
 ate 
-static RxEventBusHelper instance;%0A%0A    private PublishSubject%3CObject%3E subject
+final PublishSubject _bus
  = P
@@ -679,13 +679,19 @@
 oid 
-post(
+send(final 
 Obje
@@ -715,31 +715,183 @@
     
-subject.onNext(object);
+Schedulers.io().createWorker().schedule(new Action0() %7B%0A            @Override%0A            public void call() %7B%0A                _bus. onNext(object);%0A            %7D%0A        %7D);%0A
 %0A   
@@ -1035,11 +1035,22 @@
 ct%3E 
-get
+toObserverable
 () %7B
@@ -1065,23 +1065,98 @@
  return 
-subject
+_bus;%0A    %7D%0A%0A    public boolean hasObservers()%7B%0A        return _bus.hasObservers()
 ;%0A    %7D%0A

add PublishSubject with Scheduler.io() worker as poster on io() Scheduler (Temporary until future refactor for memory considerations )