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 |
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.mdaisuke.sample; | |
| import android.app.Activity; | |
| import android.os.Bundle; | |
| import android.text.Editable; | |
| import android.text.TextWatcher; | |
| import android.view.Menu; | |
| import android.view.MenuItem; | |
| import android.view.View; | |
| import android.widget.Button; |
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 static Observable<List<String>> paginatedThings(final Observable<Void> onNextObservable) { | |
| return Observable.create(new Observable.OnSubscribe<List<String>>() { | |
| @Override | |
| public void call(final Subscriber<? super List<String>> subscriber) { | |
| onNextObservable.subscribe(new Observer<Void>() { | |
| int latestPage = -1; | |
| @Override | |
| public void onCompleted() { | |
| subscriber.onCompleted(); |
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 android.content.Context; | |
| import android.location.Criteria; | |
| import android.location.Location; | |
| import android.location.LocationListener; | |
| import android.location.LocationManager; | |
| import android.os.Bundle; | |
| import android.os.Looper; | |
| import rx.Observable; | |
| import rx.Subscriber; |
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 org.ymkm.utils; | |
| import rx.Observable; | |
| import rx.Subscriber; | |
| import rx.Subscription; | |
| import rx.android.schedulers.AndroidSchedulers; | |
| import rx.schedulers.Schedulers; | |
| public final class RxAsyncUtils { |
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 interface API { | |
| @GET("/user/{username}/dogs") | |
| Observable<Dog> getAllDogsOf(@Path("username") String username); | |
| @GET("/dog/{id}") | |
| Observable<Dog> getDogInfoById(@Path("id") int dogId); | |
| } |