Created
March 14, 2017 11:58
-
-
Save WarrenFaith/39730bf8e8855c1d8bd4246db8e6dc0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you might want to use
return subject.asObservable();
instead than justreturn subject;