Created
April 30, 2015 06:20
-
-
Save IlyaEremin/1eaf1679e18ee6b0ce49 to your computer and use it in GitHub Desktop.
RxJava usage samples
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 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())); | |
} | |
} |
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 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()); | |
} | |
} |
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 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