Skip to content

Instantly share code, notes, and snippets.

@WarrenFaith
Created March 14, 2017 11:58
Show Gist options
  • Save WarrenFaith/39730bf8e8855c1d8bd4246db8e6dc0d to your computer and use it in GitHub Desktop.
Save WarrenFaith/39730bf8e8855c1d8bd4246db8e6dc0d to your computer and use it in GitHub Desktop.
public class RxAccountBus {
private final static RxAccountBus INSTANCE = new RxAccountBus();
public final static int ACCOUNT_LOGGED_IN = 0;
public final static int ACCOUNT_LOGGED_OUT = 1;
public final static int ACCOUNT_DATA_UPDATED = 2;
@Retention(SOURCE)
@IntDef({ACCOUNT_LOGGED_IN, ACCOUNT_LOGGED_OUT, ACCOUNT_DATA_UPDATED})
public @interface Account {
}
private PublishSubject<Integer> subject = PublishSubject.create();
private RxAccountBus() {
// nothing to do here
}
public static RxAccountBus getInstance() {
return INSTANCE;
}
/**
* Pass any event down to event listeners.
*/
public void sendEvent(@Account int account) {
subject.onNext(account);
}
/**
* Subscribe to this Observable.
*/
public Observable<Integer> getEvents() {
return subject;
}
}
@bblackbelt
Copy link

you might want to use return subject.asObservable(); instead than just return subject;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment