Skip to content

Instantly share code, notes, and snippets.

@IlyaEremin
Created April 30, 2015 06:20
Show Gist options
  • Save IlyaEremin/1eaf1679e18ee6b0ce49 to your computer and use it in GitHub Desktop.
Save IlyaEremin/1eaf1679e18ee6b0ce49 to your computer and use it in GitHub Desktop.
RxJava usage samples
public class SignUpScreen extends BaseFragment{
private void signUp(RegistrationInfo regInfo) {
startProgressAnimation();
bind(api.registerWith(regInfo)))
.flatMap(registerResponse -> api.getToken("password", userName, password, Consts.CLIENT_ID, Consts.CLIENT_SECRET))
.flatMap(token -> {
User.saveTokens(token);
return api.getProfileInfo(Consts.SELF);
})
.subscribeOn(Schedulers.io())
.doOnTerminate(() -> stopProgressAnimation())
.subscribe(profile -> {
registerPushNotification();
openStatusScreen();
}, Errors.onError(getActivity()));
}
}
public class App extends Application {
Subject<Void, Void> activityVisibleEvent = PublishSubject.create();
public void activityVisible() {
activityVisibleEvent.onNext(null);
if (serviceNotRunning()) {
startGpsService();
}
}
public void activityGone() {
Observable.timer(10, TimeUnit.SECONDS)
.takeUntil(activityVisibleEvent)
.subscribe(t -> stopGpsService(), Errors.logHandler());
}
}
public SomeClass extends BaseFragment {
public void onCreate(Bundle savedInstanceState) {
Observable.combineLatest(geoServiceConnected, needDataLoading, categoryRetrieved,
(t, t1, t2) -> null)
.takeUntil(viewDestroyed)
.take(1)
.subscribe(t -> fetchStatuses(null, setAdapter()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment