Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.


















public interface Callback {
void onSuccess(List<Recipe> recipes);
void onError(Throwable t);
}
public void searchRecipe(St...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...
searchRecipe(“ステーキ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

addToList(recipes);
}
@Over...


# app/build.gradle

dependencies {

compile 'io.reactivex:rxjava:1.1.1'
compile 'io.reactivex:rxandroid:1.1.0'

}
public void searchRecipe(String keyword, Callback callback) {

recipeApiClient.search(keyword, callback);

}
public void searchRecipe(String keyword, Callback callback) {

recipeApiClient.search(keyword, callback);

}
public void searchRecipe(String keyword, Callback callback) {

recipeApiClient.search(keyword, callback);

}


public void searchRecipe(String keyword) {

recipeApiClient.search(keyword, new Callback() {
@Override
public void onSuc...


public void searchRecipe(String keyword) {

recipeApiClient.search(keyword, new Callback() {
@Override
public void onSuc...


public Observable<List<Recipe>> searchRecipe(String keyword) {

recipeApiClient.search(keyword, new Callback() {
@Overri...


public Observable<List<Recipe>> searchRecipe(String keyword) {

recipeApiClient.search(keyword, new Callback() {
@Overri...
public Observable<List<Recipe>> searchRecipe(String keyword) {
return Observable.create(subscriber -> {


















...
public Observable<List<Recipe>> searchRecipe(String keyword) {
return Observable.create(subscriber -> {

recipeApiClient.s...
public Observable<List<Recipe>> searchRecipe(String keyword) {
return Observable.create(subscriber -> {

recipeApiClient.s...
public Observable<List<Recipe>> searchRecipe(String keyword) {
return Observable.create(subscriber -> {

recipeApiClient.s...
public Observable<List<Recipe>> searchRecipe(String keyword) {
return Observable.create(subscriber -> {

recipeApiClient.s...
public List<Recipe> searchRecipe(String keyword) throws HttpException {
// okhttpとかHttpClientで同期通信

}


public Observable<...
searchRecipe(“ステーキ”)
.subscribe(new Subscriber<List<Recipe>>() {

@Override

public void onNext(List<Recipe> recipe) {

ad...
searchRecipe(“ステーキ”)
.subscribe(new Subscriber<List<Recipe>>() {

@Override

public void onNext(List<Recipe> recipe) {

ad...
searchRecipe(“ステーキ”)
.subscribe(new Subscriber<List<Recipe>>() {

@Override

public void onNext(List<Recipe> recipe) {

ad...
searchRecipe(“ステーキ”)
.subscribe(new Subscriber<List<Recipe>>() {

@Override

public void onNext(List<Recipe> recipe) {

ad...
searchRecipe(“ステーキ”)
.subscribe(new Subscriber<List<Recipe>>() {

@Override

public void onNext(List<Recipe> recipe) {

ad...
searchRecipe(“ステーキ”)
.subscribe(new Subscriber<List<Recipe>>() {

@Override

public void onNext(List<Recipe> recipe) {

ad...
searchRecipe(“ステーキ”)
.subscribe(new Subscriber<List<Recipe>>() {

@Override

public void onNext(List<Recipe> recipe) {

ad...
searchRecipe(“ステーキ”)
.subscribe(new Subscriber<List<Recipe>>() {

@Override

public void onNext(List<Recipe> recipe) {

ad...
searchRecipe(“ステーキ”)
.subscribe(recipes -> {
addToList(recipes);
},
throwable -> {
showErrorMessage(t);
},
() -> {

// 省略可...
searchRecipe(“ステーキ”)
.subscribe(recipes -> {
addToList(recipes);
},
throwable -> {
showErrorMessage(t);
},
() -> {

// 省略可...
searchRecipe(“ステーキ”)
.subscribe(recipes -> {
addToList(recipes);
},
throwable -> {
showErrorMessage(t);
},
() -> {

// 省略可...
searchRecipe(“ステーキ”)
.subscribe(recipes -> {
addToList(recipes);
},
throwable -> {
showErrorMessage(t);
},
() -> {

// 省略可...
🙇
searchRecipeBy(“ステーキ”)

.map(recipes -> { /* todo something */ })

.subscribeOn(Schedulers.io())

.map(recipes -> { /* tod...
searchRecipeBy(“ステーキ”)

.map(recipes -> { /* todo something */ })

.subscribeOn(Schedulers.io())

.map(recipes -> { /* tod...
searchRecipeBy(“ステーキ”)

.map(recipes -> { /* todo something */ })

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedu...
searchRecipeBy(“ステーキ”)

.map(recipes -> { /* todo something */ })

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedu...
searchRecipeBy(“ステーキ”)

.map(recipes -> { /* todo something */ })

.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedul...
searchRecipe(“ステーキ”)

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThread())
.subscribe(recipes -> {
ad...
searchRecipe(“ステーキ”)

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThread())
.subscribe(recipes -> {
ad...
searchRecipe(“ステーキ”)

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThread())
.subscribe(recipes -> {
ad...
searchRecipe(“ステーキ”)

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThread())
.subscribe(recipes -> {
ad...


searchRecipeBy(“ハンバーグ”, new Callback() {
@Override
public void onSuccess(List<Recipe> recipes) {

if(getActivity() == null...


# app/build.gradle

dependencies {

compile 'com.trello:rxlifecycle:0.4.0'
compile 'com.trello:rxlifecycle-components:0....
searchRecipeBy(“ハンバーグ”)
.compose(bindToLifecycle())

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThrea...
searchRecipeBy(“ハンバーグ”)
.compose(bindToLifecycle())

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThrea...
searchRecipeBy(“ハンバーグ”)
.compose(bindToLifecycle())

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThrea...
searchRecipeBy(“ハンバーグ”)
.compose(bindToLifecycle())

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThrea...
searchRecipeBy(“ハンバーグ”)
.compose(bindToLifecycle())

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThrea...
searchRecipeBy(“ハンバーグ”)
.compose(bindToLifecycle())

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThrea...
searchRecipeBy(“ハンバーグ”)
.compose(bindToLifecycle())

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThrea...
searchRecipeBy(“ハンバーグ”)
.compose(bindToLifecycle())

.subscribeOn(schedulers.io())

.observeOn(AndroidSchedulers.mainThrea...




#
#
#
#
!
!
!
#
#
#
#
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
Observable.combineLatest(

Observable.just(1),

Observable.just(2),

(i1,i2) -> i1 + i2 // この場合、3が次のオペレーターに渡る

);
Observable.combineLatest(

Observable.just(1),

Observable.just(2),

(i1,i2) -> Pair.create(i1, i2)

);
Observable.combine...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい
Pair::create
)

.subscribeOn(sc...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい
Pair::create
)

.subscribeOn(sc...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい
Pair::create
)

.subscribeOn(sc...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい
Pair::create
)

.subscribeOn(sc...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい
Pair::create
)

.subscribeOn(sc...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい
Pair::create
)

.subscribeOn(sc...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい
Pair::create
)

.subscribeOn(sc...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい
Pair::create
)

.subscribeOn(sc...
😱
😱
😱
AdObservable(“タマゴ”)
.onErrorReturn(throwable -> AdModel.EmptyData());
public Observable<AdModel> searchAd(String keyword) {
return Observable.create(subscriber -> {
try{

AdModel adModel = adC...
public Observable<AdModel> searchAd(String keyword) {
return Observable.create(subscriber -> {
try{

AdModel adModel = adC...
public Observable<AdModel> searchAd(String keyword) {
return Observable.create(subscriber -> {
try{

AdModel adModel = adC...
public Observable<AdModel> searchAd(String keyword) {
return Observable.create(subscriber -> {
try{

AdModel adModel = adC...
public Observable<AdModel> searchAd(String keyword) {
return Observable.create(subscriber -> {
try{

AdModel adModel = adC...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”),
Pair::create
)

.subscribeOn(schedulers.io())

.observeO...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”),
Pair::create
)

.subscribeOn(schedulers.io())

.observeO...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”),
Pair::create
)

.subscribeOn(schedulers.io())

.observeO...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”),
Pair::create
)

.subscribeOn(schedulers.io())

.observeO...
Observable.combineLatest(
searchRecipe(“ステーキ”),
searchAd(“ステーキ”),
Pair::create
)

.subscribeOn(schedulers.io())

.observeO...
Observable.combineLatest(
searchRecipe(“ステーキ”).subscribeOn(schedulers.io()),
searchAd(“ステーキ”).subscribeOn(schedulers.io())...


AdObservable(“タマゴ”)
.retry(1); // 例外が発生した場合1回だけリトライする
AdObservable(“タマゴ”)
.retry((count, throwable) -> count > 2)


public Observable<AdModel> searchAd(String keyword) {
return Observable.create(subscriber -> {
try{

AdModel ad = AdClie...
!
!
!


!
!
!
♥
♥
♥


!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
searchRecipe(“ステーキ”)
.flatMap(recipes -> fetchLikedRecipeIds(recipes))
.subscribe(recipeIds -> {})
searchRecipe(“ステーキ”)
.flatMap(recipes -> fetchLikedRecipeIds(recipes))
.subscribe(recipeIds -> {})
searchRecipe(“ステーキ”)
.flatMap(recipes -> fetchLikedRecipeIds(recipes))
.subscribe(recipeIds -> {})
searchRecipe(“ステーキ”)
.flatMap(recipes -> fetchLikedRecipeIds(recipes))
.subscribe(recipeIds -> {})
searchRecipe(“ステーキ”)

.flatMap(recipes -> 

Observable.combineLatest(
Observable.just(recipes), // レシピリストをそのまま渡す

fetchLik...
searchRecipe(“ステーキ”)

.flatMap(recipes -> 

Observable.combineLatest(
Observable.just(recipes), // レシピリストをそのまま渡す

fetchLik...
searchRecipe(“ステーキ”)

.flatMap(recipes -> 

Observable.combineLatest(
Observable.just(recipes), // レシピリストをそのまま渡す

fetchLik...
searchRecipe(“ステーキ”)

.flatMap(recipes -> {

fetchLikedRecipe(recipes)

.map(likeIds -> {

mergeLikeState(recipes, likeIds...
public Observable<List<Recipe>> searchRecipeWithLikeState(String keyword) {
searchRecipe(keyword)
.flatMap(recipes ->
Obse...
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
!
!
!
♥
♥
♥
Observable.combineLatest(
searchRecipeWithLikeState(“ステーキ”)
.subscribeOn(schedulers.io()),
searchAd(“ステーキ”)
.subscribeOn(s...
Observable.combineLatest(

Observable.just(1),

Observable.just(2),

(i1,i2) -> i1 + i2

);


searchRecipe(“ステーキ”)
.flatMap(recipes -> recipeClient.fetchLikedRecipeIds(recipes))
.subscribe(recipeIds -> {})


public class Tuple3<T1, T2, T3> {

public T1 first; public T2 second; public T3 third;

public Tuple3(T1 first, T2 secon...
// in your CustomApplication
public void onCreate(Bundle saveInstanceState){

super.onCreate();
System.setProperty("rx.rin...
Single.create(subscriber -> {

subscriber.onSuccess("Hello world");

}).subscribe(text -> {

System.out.println(text);

},...


Completable.create(subscriber -> { 

subscriber.onCompleted()

}).subscribe(throwable -> {

Crashlytics.logException(e);...


明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
明日から使えるRxjava頻出パターン (Droid kaigi 2016)
Upcoming SlideShare
Loading in …5
×

明日から使えるRxjava頻出パターン (Droid kaigi 2016)

23,056 views

Published on

Droidkaigiで紹介した資料です。

Published in: Technology
  • Hi there! I just wanted to share a list of sites that helped me a lot during my studies: .................................................................................................................................... www.EssayWrite.best - Write an essay .................................................................................................................................... www.LitReview.xyz - Summary of books .................................................................................................................................... www.Coursework.best - Online coursework .................................................................................................................................... www.Dissertations.me - proquest dissertations .................................................................................................................................... www.ReMovie.club - Movies reviews .................................................................................................................................... www.WebSlides.vip - Best powerpoint presentations .................................................................................................................................... www.WritePaper.info - Write a research paper .................................................................................................................................... www.EddyHelp.com - Homework help online .................................................................................................................................... www.MyResumeHelp.net - Professional resume writing service .................................................................................................................................. www.HelpWriting.net - Help with writing any papers ......................................................................................................................................... Save so as not to lose
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ♥♥♥ http://bit.ly/39mQKz3 ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Sex in your area is here: ❤❤❤ http://bit.ly/39mQKz3 ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy &amp; Proven Way to Build Good Habits &amp; Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS/FILE INTO AVAILABLE FORMAT - (Unlimited) ......................................................................................................................... ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes Christian, Classics, Comics, Contemporary, Cookbooks, Art, Biography, Business, Chick Lit, Children's, Manga, Memoir, Music, Science, Science Fiction, Self Help, History, Horror, Humor And Comedy, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

明日から使えるRxjava頻出パターン (Droid kaigi 2016)

  1. 1. 

  2. 2.
  3. 3. 
 

  4. 4.
  5. 5.
  6. 6. 
 

  7. 7.
  8. 8. public interface Callback { void onSuccess(List<Recipe> recipes); void onError(Throwable t); } public void searchRecipe(String keyword, Callback callback) {
 recipeApiClient.search(keyword, callback);
 }
  9. 9. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 }
  10. 10. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 }
  11. 11. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 }
  12. 12. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 }
  13. 13. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 } !
  14. 14. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 } ! !
  15. 15. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 } ! ! !
  16. 16. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 } ! ! ! !
  17. 17. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 }
  18. 18. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 }
  19. 19. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 }
  20. 20. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 }
  21. 21. searchRecipe(“ステーキ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 addToList(recipes); } @Override public void onError(Throwable t) { showErrorView(t); } });
 } "
  22. 22. 
 # app/build.gradle
 dependencies {
 compile 'io.reactivex:rxjava:1.1.1' compile 'io.reactivex:rxandroid:1.1.0'
 }
  23. 23. public void searchRecipe(String keyword, Callback callback) {
 recipeApiClient.search(keyword, callback);
 }
  24. 24. public void searchRecipe(String keyword, Callback callback) {
 recipeApiClient.search(keyword, callback);
 }
  25. 25. public void searchRecipe(String keyword, Callback callback) {
 recipeApiClient.search(keyword, callback);
 }
  26. 26. 
 public void searchRecipe(String keyword) {
 recipeApiClient.search(keyword, new Callback() { @Override public void onSuccess(List<Recipe> recipes) { } @Override public void onError(Throwable t) { } });
 }
  27. 27. 
 public void searchRecipe(String keyword) {
 recipeApiClient.search(keyword, new Callback() { @Override public void onSuccess(List<Recipe> recipes) { } @Override public void onError(Throwable t) { } });
 }
  28. 28. 
 public Observable<List<Recipe>> searchRecipe(String keyword) {
 recipeApiClient.search(keyword, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 } @Override public void onError(Throwable t) {
 } });
 }
  29. 29. 
 public Observable<List<Recipe>> searchRecipe(String keyword) {
 recipeApiClient.search(keyword, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 } @Override public void onError(Throwable t) {
 } });
 }
  30. 30. public Observable<List<Recipe>> searchRecipe(String keyword) { return Observable.create(subscriber -> {
 
 
 
 
 
 
 
 
 
 
 
 }); } void 
 recipeApiClient.search(keyword, new Callback() {
 @Override
 public void onSuccess(List<Recipe> recipes) {
 
 
 } @Override public void onError(Throwable t) {
 }
 });
  31. 31. public Observable<List<Recipe>> searchRecipe(String keyword) { return Observable.create(subscriber -> {
 recipeApiClient.search(keyword, new Callback() {
 @Override
 public void onSuccess(List<Recipe> recipes) {
 
 
 } @Override public void onError(Throwable t) { 
 } }); }); } void
  32. 32. public Observable<List<Recipe>> searchRecipe(String keyword) { return Observable.create(subscriber -> {
 recipeApiClient.search(keyword, new Callback() {
 @Override
 public void onSuccess(List<Recipe> recipes) {
 subscriber.onNext(recipes);// イベントの通知 subscriber.onCompleted(); // 全イベントが終了した通知
 } @Override public void onError(Throwable t) { subscriber.onError(t); // 処理内で失敗した通知 } }); }); } void
  33. 33. public Observable<List<Recipe>> searchRecipe(String keyword) { return Observable.create(subscriber -> {
 recipeApiClient.search(keyword, new Callback() {
 @Override
 public void onSuccess(List<Recipe> recipes) {
 subscriber.onNext(recipes);// イベントの通知 subscriber.onCompleted(); // 全イベントが終了した通知
 } @Override public void onError(Throwable t) { subscriber.onError(t); // 処理内で失敗した通知 } }); }); } void
  34. 34. public Observable<List<Recipe>> searchRecipe(String keyword) { return Observable.create(subscriber -> {
 recipeApiClient.search(keyword, new Callback() {
 @Override
 public void onSuccess(List<Recipe> recipes) {
 subscriber.onNext(recipes);// イベントの通知 subscriber.onCompleted(); // 全イベントが終了した通知
 } @Override public void onError(Throwable t) { subscriber.onError(t); // 処理内で失敗した通知 } }); }); } void
  35. 35. public List<Recipe> searchRecipe(String keyword) throws HttpException { // okhttpとかHttpClientで同期通信
 } 
 public Observable<List<Recipe>> searchRecipe(String keyword) { return Observable.create(subscriber -> { try{
 List<Recipe> recipes = ApiClient.search(keyword); subscriber.onNext(recipes); subscriber.onFinished(); } catch(HttpException e) {
 subscriber.onError(e);
 } }
  36. 36. searchRecipe(“ステーキ”) .subscribe(new Subscriber<List<Recipe>>() {
 @Override
 public void onNext(List<Recipe> recipe) {
 addToList(recipes);
 }
 @Override
 public void onError(Throwable e) {
 showErrorMessage(t);
 }
 
 @Override
 public void onCompleted() { 
 }); );
  37. 37. searchRecipe(“ステーキ”) .subscribe(new Subscriber<List<Recipe>>() {
 @Override
 public void onNext(List<Recipe> recipe) {
 addToList(recipes);
 }
 @Override
 public void onError(Throwable e) {
 showErrorMessage(t);
 }
 
 @Override
 public void onCompleted() { 
 }); );
  38. 38. searchRecipe(“ステーキ”) .subscribe(new Subscriber<List<Recipe>>() {
 @Override
 public void onNext(List<Recipe> recipe) {
 addToList(recipes);
 }
 @Override
 public void onError(Throwable e) {
 showErrorMessage(t);
 }
 
 @Override
 public void onCompleted() { 
 }); );
  39. 39. searchRecipe(“ステーキ”) .subscribe(new Subscriber<List<Recipe>>() {
 @Override
 public void onNext(List<Recipe> recipe) {
 addToList(recipes);
 }
 @Override
 public void onError(Throwable e) {
 showErrorMessage(t);
 }
 
 @Override
 public void onCompleted() { 
 }); );
  40. 40. searchRecipe(“ステーキ”) .subscribe(new Subscriber<List<Recipe>>() {
 @Override
 public void onNext(List<Recipe> recipe) {
 addToList(recipes);
 }
 @Override
 public void onError(Throwable e) {
 showErrorMessage(t);
 }
 
 @Override
 public void onCompleted() { 
 }); ); !
  41. 41. searchRecipe(“ステーキ”) .subscribe(new Subscriber<List<Recipe>>() {
 @Override
 public void onNext(List<Recipe> recipe) {
 addToList(recipes);
 }
 @Override
 public void onError(Throwable e) {
 showErrorMessage(t);
 }
 
 @Override
 public void onCompleted() { 
 }); ); ! !
  42. 42. searchRecipe(“ステーキ”) .subscribe(new Subscriber<List<Recipe>>() {
 @Override
 public void onNext(List<Recipe> recipe) {
 addToList(recipes);
 }
 @Override
 public void onError(Throwable e) {
 showErrorMessage(t);
 }
 
 @Override
 public void onCompleted() { 
 }); ); ! ! !
  43. 43. searchRecipe(“ステーキ”) .subscribe(new Subscriber<List<Recipe>>() {
 @Override
 public void onNext(List<Recipe> recipe) {
 addToList(recipes);
 }
 @Override
 public void onError(Throwable e) {
 showErrorMessage(t);
 }
 
 @Override
 public void onCompleted() { 
 }); ); ! ! ! !
  44. 44. searchRecipe(“ステーキ”) .subscribe(recipes -> { addToList(recipes); }, throwable -> { showErrorMessage(t); }, () -> {
 // 省略可能
 } );
  45. 45. searchRecipe(“ステーキ”) .subscribe(recipes -> { addToList(recipes); }, throwable -> { showErrorMessage(t); }, () -> {
 // 省略可能
 } );
  46. 46. searchRecipe(“ステーキ”) .subscribe(recipes -> { addToList(recipes); }, throwable -> { showErrorMessage(t); }, () -> {
 // 省略可能
 } );
  47. 47. searchRecipe(“ステーキ”) .subscribe(recipes -> { addToList(recipes); }, throwable -> { showErrorMessage(t); }, () -> {
 // 省略可能
 } ); ! ! ! !
  48. 48. 🙇
  49. 49. searchRecipeBy(“ステーキ”)
 .map(recipes -> { /* todo something */ })
 .subscribeOn(Schedulers.io())
 .map(recipes -> { /* todo something */ }) .subscribe(recipes -> {});
  50. 50. searchRecipeBy(“ステーキ”)
 .map(recipes -> { /* todo something */ })
 .subscribeOn(Schedulers.io())
 .map(recipes -> { /* todo something */ }) .subscribe(recipes -> {}); 

  51. 51. searchRecipeBy(“ステーキ”)
 .map(recipes -> { /* todo something */ })
 .subscribeOn(Schedulers.io())
 .observeOn(AndroidSchedulers.mainThread())
 .map(recipes -> { /* todo something */ }) .observeOn(Schedulers.io()) .subscribe(recipes -> {});
  52. 52. searchRecipeBy(“ステーキ”)
 .map(recipes -> { /* todo something */ })
 .subscribeOn(Schedulers.io())
 .observeOn(AndroidSchedulers.mainThread())
 .map(recipes -> { /* todo something */ }) .observeOn(Schedulers.io()) .subscribe(recipes -> {});
  53. 53. searchRecipeBy(“ステーキ”)
 .map(recipes -> { /* todo something */ })
 .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> {}); 

  54. 54. searchRecipe(“ステーキ”)
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addToList(recipes); }, throwable -> { showErrorMessage(t); } );
  55. 55. searchRecipe(“ステーキ”)
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addToList(recipes); }, throwable -> { showErrorMessage(t); } );
  56. 56. searchRecipe(“ステーキ”)
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addToList(recipes); }, throwable -> { showErrorMessage(t); } );
  57. 57. searchRecipe(“ステーキ”)
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addToList(recipes); }, throwable -> { showErrorMessage(t); } ); ! ! ! !
  58. 58.
  59. 59. searchRecipeBy(“ハンバーグ”, new Callback() { @Override public void onSuccess(List<Recipe> recipes) {
 if(getActivity() == null) { return; }
 addToList(recipes); } @Override public void onError(Throwable t) {
 if(getActivity() == null) { return; } showErrorMessage(t); } });
 }
  60. 60. 
 # app/build.gradle
 dependencies {
 compile 'com.trello:rxlifecycle:0.4.0' compile 'com.trello:rxlifecycle-components:0.4.0'
 }
  61. 61. searchRecipeBy(“ハンバーグ”) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addList(recipes); }, throwable -> { showErrorMessage(t); } );
  62. 62. searchRecipeBy(“ハンバーグ”) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addList(recipes); }, throwable -> { showErrorMessage(t); } );
  63. 63. searchRecipeBy(“ハンバーグ”) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addList(recipes); }, throwable -> { showErrorMessage(t); } );
  64. 64. searchRecipeBy(“ハンバーグ”) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addList(recipes); }, throwable -> { showErrorMessage(t); } ); ! ! ! !
  65. 65. searchRecipeBy(“ハンバーグ”) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addList(recipes); }, throwable -> { showErrorMessage(t); } );
  66. 66. searchRecipeBy(“ハンバーグ”) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addList(recipes); }, throwable -> { showErrorMessage(t); } );
  67. 67. searchRecipeBy(“ハンバーグ”) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addList(recipes); }, throwable -> { showErrorMessage(t); } ); 

  68. 68. searchRecipeBy(“ハンバーグ”) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(recipes -> { addList(recipes); }, throwable -> { showErrorMessage(t); } ); 

  69. 69.
  70. 70.
  71. 71. # # # # ! ! !
  72. 72. # # # # ! ! !
  73. 73. ! ! !
  74. 74. ! ! !
  75. 75. ! ! !
  76. 76. ! ! !
  77. 77. ! ! !
  78. 78. ! ! !
  79. 79. ! ! !
  80. 80. ! ! !
  81. 81. ! ! !
  82. 82. !
  83. 83. !
  84. 84. ! !
  85. 85. ! ! !
  86. 86. ! ! !
  87. 87. Observable.combineLatest(
 Observable.just(1),
 Observable.just(2),
 (i1,i2) -> i1 + i2 // この場合、3が次のオペレーターに渡る
 );
  88. 88. Observable.combineLatest(
 Observable.just(1),
 Observable.just(2),
 (i1,i2) -> Pair.create(i1, i2)
 ); Observable.combineLatest(
 Observable.just(1),
 Observable.just(2),
 Pair::create
 );
  89. 89. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToListWithBannerIfExist(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } );
  90. 90. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToListWithBannerIfExist(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } );
  91. 91. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToListWithBannerIfExist(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } );
  92. 92. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToListWithBannerIfExist(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } );
  93. 93. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToListWithBannerIfExist(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } );
  94. 94. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToListWithBannerIfExist(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } );
  95. 95. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToListWithBannerIfExist(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } );
  96. 96. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), // 広告情報を取得するメソッドだと思って下さい Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToListWithBannerIfExist(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } );
  97. 97. 😱
  98. 98. 😱
  99. 99. 😱
  100. 100. AdObservable(“タマゴ”) .onErrorReturn(throwable -> AdModel.EmptyData());
  101. 101. public Observable<AdModel> searchAd(String keyword) { return Observable.create(subscriber -> { try{
 AdModel adModel = adClient.search(keyword); subscriber.onNext(adModel); } catch(HttpException e) {
 subscriber.onError(e);
 }) .onErrorReturn(e -> { return AdModel.createEmptyData();
 }); }
  102. 102. public Observable<AdModel> searchAd(String keyword) { return Observable.create(subscriber -> { try{
 AdModel adModel = adClient.search(keyword); subscriber.onNext(adModel); } catch(HttpException e) {
 subscriber.onError(e);
 }) .onErrorReturn(e -> { return AdModel.createEmptyData();
 }); }
  103. 103. public Observable<AdModel> searchAd(String keyword) { return Observable.create(subscriber -> { try{
 AdModel adModel = adClient.search(keyword); subscriber.onNext(adModel); } catch(HttpException e) {
 subscriber.onError(e);
 }) .onErrorReturn(e -> { return AdModel.createEmptyData();
 }); }
  104. 104. public Observable<AdModel> searchAd(String keyword) { return Observable.create(subscriber -> { try{
 AdModel adModel = adClient.search(keyword); subscriber.onNext(adModel); } catch(HttpException e) {
 subscriber.onError(e);
 }) .onErrorReturn(e -> { return AdModel.createEmptyData();
 }); }
  105. 105. public Observable<AdModel> searchAd(String keyword) { return Observable.create(subscriber -> { try{
 AdModel adModel = adClient.search(keyword); subscriber.onNext(adModel); } catch(HttpException e) {
 subscriber.onError(e);
 }) .onErrorReturn(e -> { return AdModel.createEmptyData();
 }); }
  106. 106. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe( /* 省略 */ );
  107. 107. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe( /* 省略 */ );
  108. 108. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe( /* 省略 */ );
  109. 109. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe( /* 省略 */ );
  110. 110. Observable.combineLatest( searchRecipe(“ステーキ”), searchAd(“ステーキ”), Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe( /* 省略 */ );
  111. 111. Observable.combineLatest( searchRecipe(“ステーキ”).subscribeOn(schedulers.io()), searchAd(“ステーキ”).subscribeOn(schedulers.io()), Pair::create )
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe( /* 省略 */ );
  112. 112.
  113. 113. AdObservable(“タマゴ”) .retry(1); // 例外が発生した場合1回だけリトライする AdObservable(“タマゴ”) .retry((count, throwable) -> count > 2)
  114. 114. 
 public Observable<AdModel> searchAd(String keyword) { return Observable.create(subscriber -> { try{
 AdModel ad = AdClient.search(keyword); subscriber.onNext(ad); } catch(HttpException e) {
 subscriber.onError(e);
 }) .retry(1) .onErrorReturn(e -> { return AdModel.createEmptyData();
 }); }
  115. 115. ! ! ! 

  116. 116. ! ! ! ♥ ♥ ♥ 

  117. 117. ! ! ! ♥ ♥ ♥
  118. 118. ! ! ! ♥ ♥ ♥
  119. 119. searchRecipe(“ステーキ”) .flatMap(recipes -> fetchLikedRecipeIds(recipes)) .subscribe(recipeIds -> {})
  120. 120. searchRecipe(“ステーキ”) .flatMap(recipes -> fetchLikedRecipeIds(recipes)) .subscribe(recipeIds -> {})
  121. 121. searchRecipe(“ステーキ”) .flatMap(recipes -> fetchLikedRecipeIds(recipes)) .subscribe(recipeIds -> {})
  122. 122. searchRecipe(“ステーキ”) .flatMap(recipes -> fetchLikedRecipeIds(recipes)) .subscribe(recipeIds -> {})
  123. 123. searchRecipe(“ステーキ”)
 .flatMap(recipes -> 
 Observable.combineLatest( Observable.just(recipes), // レシピリストをそのまま渡す
 fetchLikedRecipe(recipes)), //レシピリストからLikeしたレシピIdを取得 Pair::create
 )
 )
 .map(this::mergeLikeState) // mapでLike状態をレシピインスタンスに反映させる(省略) .subscribe(recipes -> {})
  124. 124. searchRecipe(“ステーキ”)
 .flatMap(recipes -> 
 Observable.combineLatest( Observable.just(recipes), // レシピリストをそのまま渡す
 fetchLikedRecipe(recipes)), //レシピリストからLikeしたレシピIdを取得 Pair::create
 )
 )
 .map(this::mergeLikeState) // mapでLike状態をレシピインスタンスに反映させる(省略) .subscribe(recipes -> {})
  125. 125. searchRecipe(“ステーキ”)
 .flatMap(recipes -> 
 Observable.combineLatest( Observable.just(recipes), // レシピリストをそのまま渡す
 fetchLikedRecipe(recipes)), //レシピリストからLikeしたレシピIdを取得 Pair::create
 )
 )
 .map(this::mergeLikeState) // mapでLike状態をレシピインスタンスに反映させる(省略) .subscribe(recipes -> {})
  126. 126. searchRecipe(“ステーキ”)
 .flatMap(recipes -> {
 fetchLikedRecipe(recipes)
 .map(likeIds -> {
 mergeLikeState(recipes, likeIds);
 });
 }
 ) .subscribe(recipes -> {})
  127. 127. public Observable<List<Recipe>> searchRecipeWithLikeState(String keyword) { searchRecipe(keyword) .flatMap(recipes -> Observable.combineLatest( Observable.just(recipes), fetchLikedRecipeIds(recipes)), Pair::create ) ) .map(this::mergeLikeState) }
 public Func1<List<Recipe>> mergeLikeState(Pair<List<Recipe>, Integer> pair) {
 // Like状態をレシピインスタンスに反映させる(省略)
 }
  128. 128. ! ! ! ♥ ♥ ♥
  129. 129. ! ! ! ♥ ♥ ♥
  130. 130. ! ! ! ♥ ♥ ♥
  131. 131. ! ! ! ♥ ♥ ♥
  132. 132. ! ! ! ♥ ♥ ♥
  133. 133. ! ! ! ♥ ♥ ♥
  134. 134. ! ! ! ♥ ♥ ♥
  135. 135. ! ! ! ♥ ♥ ♥
  136. 136. ! ! ! ♥ ♥ ♥
  137. 137. ! ! ! ♥ ♥ ♥
  138. 138. ! ! ! ♥ ♥ ♥
  139. 139. ! ! ! ♥ ♥ ♥
  140. 140. ! ! ! ♥ ♥ ♥
  141. 141. Observable.combineLatest( searchRecipeWithLikeState(“ステーキ”) .subscribeOn(schedulers.io()), searchAd(“ステーキ”) .subscribeOn(schedulers.io()), Pair::create ) .compose(bindToLifecycle())
 .subscribeOn(schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(pair -> { addToList(pair.first, pair.second); }, throwable -> { showErrorMessage(t); } ); ! ! ! ♥ ♥ ♥
  142. 142. Observable.combineLatest(
 Observable.just(1),
 Observable.just(2),
 (i1,i2) -> i1 + i2
 ); 

  143. 143. searchRecipe(“ステーキ”) .flatMap(recipes -> recipeClient.fetchLikedRecipeIds(recipes)) .subscribe(recipeIds -> {})
  144. 144. 
 public class Tuple3<T1, T2, T3> {
 public T1 first; public T2 second; public T3 third;
 public Tuple3(T1 first, T2 second, T3 third) {
 this.first = first;
 this.second = second;
 this.third = third;
 }
 public static <T1, T2, T3> Tuple3<T1, T2, T3> create(T1 t1, T2 t2, T3 t3) {
 return new Tuple3<>(t1, t2, t3);
 }
 }
  145. 145. // in your CustomApplication public void onCreate(Bundle saveInstanceState){
 super.onCreate(); System.setProperty("rx.ring-buffer.size", "32"); }
  146. 146. Single.create(subscriber -> {
 subscriber.onSuccess("Hello world");
 }).subscribe(text -> {
 System.out.println(text);
 }, throwable -> {
 Crashlytics.logException(e);
 });
  147. 147. 
 Completable.create(subscriber -> { 
 subscriber.onCompleted()
 }).subscribe(throwable -> {
 Crashlytics.logException(e);
 }, () -> {
 
 });
  148. 148.

×