This file contains hidden or 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
| import rx.Observable | |
| interface RxPermission { | |
| val isGranted: Boolean | |
| fun request(): Observable<Boolean> | |
| } |
This file contains hidden or 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
| // sample 3 UI event | |
| mButton = (Button) findViewById(R.id.button); | |
| Observable<View> clickEventObservable = Observable.create(new Observable.OnSubscribe<View>() { | |
| @Override | |
| public void call(final Subscriber<? super View> subscriber) { | |
| mButton.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| subscriber.onNext(v); | |
| } |
This file contains hidden or 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
| package com.company; | |
| import retrofit.RestAdapter; | |
| import retrofit.http.GET; | |
| import retrofit.http.Path; | |
| import rx.Observable; | |
| import rx.Subscriber; | |
| import rx.functions.Action1; | |
| import rx.functions.Func1; | |
| import rx.functions.Func2; |
This file contains hidden or 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 abstract class CachedRefreshable<P, T> extends Refreshable<P, T> { | |
| protected abstract Observable<T> getSourceObservable(P parameters); | |
| /** | |
| * Return the Observable that gets data from a cached source. | |
| * | |
| * @return Observable from cache item, or null if the cache misses. | |
| */ | |
| protected abstract Observable<T> getCachedObservable(P parameters); |
This file contains hidden or 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
| package rx.concurrency; | |
| import android.os.Handler; | |
| import android.os.Looper; | |
| import rx.Scheduler; | |
| import rx.Subscription; | |
| import rx.concurrency.ExecutorScheduler; | |
| import rx.util.AtomicObservableSubscription; | |
| import rx.util.functions.Func2; |
This file contains hidden or 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
| function rxfetch(url) { | |
| return rxfetch(url).flatMap(function (response) { | |
| var next = response.headers.get('Link').replace(/<([^<]*)>; rel="next".*/, '$1'); | |
| return Rx.Observable.concat(Rx.Observable.just(response), next ? rxfetch3(next) : Rx.Observable.empty()); | |
| }); | |
| } | |
| rxfetch('https://api.github.com/users/yongjhih/repos') | |
| .map(function (response) { return response.json(); }) | |
| .flatMap(function (json) { return Rx.Observable.from(json); }) |
This file contains hidden or 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 void login(final String mac, final String devicesOs, final String appVersion, String userAcct, String userPwd, String memType) { | |
| getSubscription().add(ApiClient.getInstance().personLogin(mac, devicesOs, appVersion, userAcct, userPwd, memType) | |
| .subscribeOn(Schedulers.newThread()) // (1) | |
| .observeOn(AndroidSchedulers.mainThread()) // (2) | |
| .flatMap(new Func1<PersonLogin, Observable<PersonData>>() { | |
| @Override | |
| public Observable<PersonData> call(PersonLogin personLogin) { | |
| // main thread | |
| return ApiClient.getInstance().queryPersonData(mac, devicesOs, appVersion, personLogin.getUId(), personLogin.getSessionId()).subscribeOn(Schedulers.newThread()); | |
| } |
This file contains hidden or 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 void login(final String mac, final String devicesOs, final String appVersion, String userAcct, String userPwd, String memType) { | |
| getSubscription().add(ApiClient.getInstance().personLogin(mac, devicesOs, appVersion, userAcct, userPwd, memType) | |
| .doOnSubscribe(new Action0() { | |
| @Override | |
| public void call() { | |
| getView().showLoading(); | |
| } | |
| }) | |
| .subscribeOn(Schedulers.newThread()) | |
| .observeOn(AndroidSchedulers.mainThread()) // (a) |
This file contains hidden or 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
| return RxFb.api(FB_APP_ID, FB_CLIENT_ID, "/me?fields=email", { access_token: fbToken; }).flatMap(fbUser -> { | |
| var userQuery = new Parse.Query(Parse.User); | |
| userQuery.equalTo("email", fbUser.email); | |
| return Observable.unzip(fbToken, ParseObservable.find(userQuery)); // magic | |
| }).switchIfEmpty(fbToken -> { | |
| var newUser = new Parse.User(); | |
| newUser.setUsername(fbUser.email); | |
| newUser.setEmail(fbUser.email) | |
| newUser.setPassword(fbToken); | |
| return ParseObservable.signUp(newUser); |
This file contains hidden or 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
| // Say you have two observables (Bar and Baz) you want to combine into a single output (Foo) | |
| public Observable<Foo> combineObservables(Observable<Bar> barObservable, Observable<Baz> bazObservable) { | |
| return Observable.zip( | |
| barObservable, | |
| bazObservable, | |
| new Func2<Bar, Baz, Foo>() { | |
| @Override |