Upgrade to Pro — share decks privately, control downloads, hide ads and more …

droidkaigi-2017

 droidkaigi-2017

Yuya Kaido

March 10, 2017
Tweet

More Decks by Yuya Kaido

Other Decks in Programming

Transcript

  1. ໨࣍ɿԠ༻ฤ • جຊฤͰొ৔ͨ͠ΤϥʔϋϯυϦϯάΛ૊Έ߹ΘͤΔ • Ϣʔεέʔε1 • ϦτϥΠΛ3ճߦ͏ • μϝͳΒΩϟογϡΛදࣔ͢Δ •

    Ϣʔεέʔε2 • ϦτϥΠΛ3ճߦ͏ • μϝͳΒΩϟογϡΛදࣔ͢Δ • Ωϟογϡ͕ͳ͍৔߹͸τʔετΛදࣔ͢Δ
  2. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 });
  3. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 });
  4. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 });
  5. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 });
  6. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 });
  7. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 }); D/ErrorHandlingInRxJava: onNext
  8. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 }); D/ErrorHandlingInRxJava: onNext
  9. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 }); D/ErrorHandlingInRxJava: onNext
  10. onError Observable.create(new Action1<Emitter<String>>() {
 @Override
 public void call(Emitter<String> emitter) {


    emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 }, Emitter.BackpressureMode.NONE)
 .subscribe(new Subscriber<String>() {
 @Override
 public void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 }); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: Something went wrong
  11. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber());
  12. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber());
  13. NextThenError public class NextThenError implements Action1<Emitter<String>> {
 
 @Override
 public

    void call(Emitter<String> emitter) {
 emitter.onNext("onNext");
 emitter.onError(new RuntimeException("Something went wrong"));
 }
 
 } 1ͭ໨ͷΞΠςϜͱͯ͠ʮonNextʯΛΤϛοτ͢Δ 2ͭ໨ͷΞΠςϜͱͯ͠ʮRuntimeExceptionʯΛΤϛοτ͢Δ
  14. LoggingSubscriber public class LoggingSubscriber extends Subscriber<String> {
 
 @Override
 public

    void onCompleted() {
 Log.d("ErrorHandlingInRxJava", "onCompleted");
 }
 
 @Override
 public void onError(Throwable e) {
 Log.d("ErrorHandlingInRxJava", e.getMessage());
 }
 
 @Override
 public void onNext(String s) {
 Log.d("ErrorHandlingInRxJava", s);
 }
 
 } Observable͔ΒྲྀΕ͖ͯͨΠϕϯτΛϩάʹදࣔ͢Δ
  15. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber());
  16. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber());
  17. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber()); onErrorReturn( )
  18. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber()); onErrorReturn( )
  19. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext onErrorReturn( )
  20. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext onErrorReturn( )
  21. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext onErrorReturn( )
  22. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext onErrorReturn( )
  23. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onErrorReturn onErrorReturn( )
  24. onErrorReturn Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorReturn(new Func1<Throwable, String>() {
 @Override
 public

    String call(Throwable throwable) {
 return "onErrorReturn";
 }
 })
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onErrorReturn D/ErrorHandlingInRxJava: onCompleted onErrorReturn( )
  25. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber());
  26. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber());
  27. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber()); onErrorResumeNext( )
  28. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber()); onErrorResumeNext( )
  29. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext onErrorResumeNext( )
  30. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext onErrorResumeNext( )
  31. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext onErrorResumeNext( )
  32. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext onErrorResumeNext( )
  33. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onErrorResumeNext onErrorResumeNext( )
  34. onErrorResumeNext Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends String>>()

    {
 @Override
 public Observable<? extends String> call(
 Throwable throwable) {
 return Observable.just("onErrorResumeNext");
 }
 }
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onErrorResumeNext D/ErrorHandlingInRxJava: onCompleted onErrorResumeNext( )
  35. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext retryWhen ( )
  36. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext retryWhen ( )
  37. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext retryWhen ( )
  38. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext retryWhen ( )
  39. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext retryWhen ( ) subscribe
  40. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext retryWhen ( ) subscribe
  41. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onNext retryWhen ( ) subscribe
  42. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onNext retryWhen ( ) subscribe
  43. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onNext retryWhen ( ) subscribe
  44. ࣌ؒΛ͓͍ͯϦτϥΠ͢Δ Observable.create(new NextThenError(), Emitter.BackpressureMode.NONE)
 .retryWhen(observable -> 
 observable.first().flatMap(throwable -> 


    Observable.timer(3, TimeUnit.SECONDS)
 )
 )
 .subscribe(new LoggingSubscriber()); D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onNext D/ErrorHandlingInRxJava: onCompleted retryWhen ( ) subscribe
  45. ΤϥʔΛτʔετͰදࣔ͢Δ githubRepository.getDroidKaigiContributors()
 .subscribeOn(Schedulers.io())
 .observeOn(AndroidSchedulers.mainThread())
 .subscribe(new Subscriber<List<GithubContributor>>() {
 @Override
 public void

    onCompleted() {}
 
 @Override
 public void onError(Throwable e) {
 Toast.makeText(MainActivity.this, e.getMessage(),
 Toast.LENGTH_SHORT).show();
 }
 
 @Override
 public void onNext(List<GithubContributor> githubContributors) {
 // Write your awesome logic
 }
 });
  46. ΤϥʔΛτʔετͰදࣔ͢Δ githubRepository.getDroidKaigiContributors()
 .subscribeOn(Schedulers.io())
 .observeOn(AndroidSchedulers.mainThread())
 .subscribe(new Subscriber<List<GithubContributor>>() {
 @Override
 public void

    onCompleted() {}
 
 @Override
 public void onError(Throwable e) {
 Toast.makeText(MainActivity.this, e.getMessage(),
 Toast.LENGTH_SHORT).show();
 }
 
 @Override
 public void onNext(List<GithubContributor> githubContributors) {
 // Write your awesome logic
 }
 });
  47. ΤϥʔΛτʔετͰදࣔ͢Δ githubRepository.getDroidKaigiContributors()
 .subscribeOn(Schedulers.io())
 .observeOn(AndroidSchedulers.mainThread())
 .subscribe(new Subscriber<List<GithubContributor>>() {
 @Override
 public void

    onCompleted() {}
 
 @Override
 public void onError(Throwable e) {
 Toast.makeText(MainActivity.this, e.getMessage(),
 Toast.LENGTH_SHORT).show();
 }
 
 @Override
 public void onNext(List<GithubContributor> githubContributors) {
 // Write your awesome logic
 }
 });
  48. ΤϥʔΛτʔετͰදࣔ͢Δ githubRepository.getDroidKaigiContributors()
 .subscribeOn(Schedulers.io())
 .observeOn(AndroidSchedulers.mainThread())
 .subscribe(new Subscriber<List<GithubContributor>>() {
 @Override
 public void

    onCompleted() {}
 
 @Override
 public void onError(Throwable e) {
 Toast.makeText(MainActivity.this, e.getMessage(),
 Toast.LENGTH_SHORT).show();
 }
 
 @Override
 public void onNext(List<GithubContributor> githubContributors) {
 // Write your awesome logic
 }
 });
  49. ΤϥʔΛτʔετͰදࣔ͢Δ githubRepository.getDroidKaigiContributors()
 .subscribeOn(Schedulers.io())
 .observeOn(AndroidSchedulers.mainThread())
 .subscribe(new Subscriber<List<GithubContributor>>() {
 @Override
 public void

    onCompleted() {}
 
 @Override
 public void onError(Throwable e) {
 Toast.makeText(MainActivity.this, e.getMessage(),
 Toast.LENGTH_SHORT).show();
 }
 
 @Override
 public void onNext(List<GithubContributor> githubContributors) {
 // Write your awesome logic
 }
 });
  50. ୅ΘΓͷσʔλΛදࣔ͢Δ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public void

    call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  51. ୅ΘΓͷσʔλΛදࣔ͢Δ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public void

    call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  52. ୅ΘΓͷσʔλΛදࣔ͢Δ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public void

    call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  53. ୅ΘΓͷσʔλΛදࣔ͢Δ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public void

    call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  54. ΤϥʔͷछྨͰॲཧΛ෼ذ͢Δ client.getDroidKaigiContributors()
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override


    public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (throwable instanceof AccessTokenExpiredException) {
 // ϩάΞ΢τ
 }
 
 if (throwable instanceof MaintenanceModeException) {
 // ϝϯςφϯεϞʔυ
 }
 
 return Observable.error(throwable);
 }
 }
 );
  55. ΤϥʔͷछྨͰॲཧΛ෼ذ͢Δ client.getDroidKaigiContributors()
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override


    public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (throwable instanceof AccessTokenExpiredException) {
 // ϩάΞ΢τ
 }
 
 if (throwable instanceof MaintenanceModeException) {
 // ϝϯςφϯεϞʔυ
 }
 
 return Observable.error(throwable);
 }
 }
 );
  56. ΤϥʔͷछྨͰॲཧΛ෼ذ͢Δ client.getDroidKaigiContributors()
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override


    public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (throwable instanceof AccessTokenExpiredException) {
 // ϩάΞ΢τ
 }
 
 if (throwable instanceof MaintenanceModeException) {
 // ϝϯςφϯεϞʔυ
 }
 
 return Observable.error(throwable);
 }
 }
 );
  57. ΤϥʔͷछྨͰॲཧΛ෼ذ͢Δ client.getDroidKaigiContributors()
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override


    public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (throwable instanceof AccessTokenExpiredException) {
 // ϩάΞ΢τ
 }
 
 if (throwable instanceof MaintenanceModeException) {
 // ϝϯςφϯεϞʔυ
 }
 
 return Observable.error(throwable);
 }
 }
 );
  58. ΤϥʔͷछྨͰॲཧΛ෼ذ͢Δ client.getDroidKaigiContributors()
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override


    public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (throwable instanceof AccessTokenExpiredException) {
 // ϩάΞ΢τ
 }
 
 if (throwable instanceof MaintenanceModeException) {
 // ϝϯςφϯεϞʔυ
 }
 
 return Observable.error(throwable);
 }
 }
 );
  59. ΤϥʔͷछྨͰॲཧΛ෼ذ͢Δ client.getDroidKaigiContributors()
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override


    public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (throwable instanceof AccessTokenExpiredException) {
 // ϩάΞ΢τ
 }
 
 if (throwable instanceof MaintenanceModeException) {
 // ϝϯςφϯεϞʔυ
 }
 
 return Observable.error(throwable);
 }
 }
 );
  60. ϦτϥΠ͢Δ͔ΛϢʔβʔʹਘͶΔ .retryWhen(observable -> observable.flatMap(throwable ->
 Observable.create(emitter -> {
 Snackbar snackbar

    = Snackbar.make(
 getView(), "Retry?", Snackbar.LENGTH_INDEFINITE);
 snackbar.setAction("Yes", view -> emitter.onNext(null));
 snackbar.show();
 }, Emitter.BackpressureMode.NONE))
 )
  61. ϦτϥΠ͢Δ͔ΛϢʔβʔʹਘͶΔ .retryWhen(observable -> observable.flatMap(throwable ->
 Observable.create(emitter -> {
 Snackbar snackbar

    = Snackbar.make(
 getView(), "Retry?", Snackbar.LENGTH_INDEFINITE);
 snackbar.setAction("Yes", view -> emitter.onNext(null));
 snackbar.show();
 }, Emitter.BackpressureMode.NONE))
 )
  62. ϦτϥΠ͢Δ͔ΛϢʔβʔʹਘͶΔ .retryWhen(observable -> observable.flatMap(throwable ->
 Observable.create(emitter -> {
 Snackbar snackbar

    = Snackbar.make(
 getView(), "Retry?", Snackbar.LENGTH_INDEFINITE);
 snackbar.setAction("Yes", view -> emitter.onNext(null));
 snackbar.show();
 }, Emitter.BackpressureMode.NONE))
 )
  63. ϦτϥΠ͢Δ͔ΛϢʔβʔʹਘͶΔ .retryWhen(observable -> observable.flatMap(throwable ->
 Observable.create(emitter -> {
 Snackbar snackbar

    = Snackbar.make(
 getView(), "Retry?", Snackbar.LENGTH_INDEFINITE);
 snackbar.setAction("Yes", view -> emitter.onNext(null));
 snackbar.show();
 }, Emitter.BackpressureMode.NONE))
 )
  64. Ԡ༻ฤ • جຊฤͰొ৔ͨ͠ΤϥʔϋϯυϦϯάΛ૊Έ߹ΘͤΔ • Ϣʔεέʔε1 • ϦτϥΠΛ3ճߦ͏ • μϝͳΒΩϟογϡΛදࣔ͢Δ •

    Ϣʔεέʔε2 • ϦτϥΠΛ3ճߦ͏ • μϝͳΒΩϟογϡΛදࣔ͢Δ • Ωϟογϡ͕ͳ͍৔߹͸τʔετΛදࣔ͢Δ
  65. Ϣʔεέʔε1ɿϦτϥΠˍΩϟογϡ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  66. Ϣʔεέʔε1ɿϦτϥΠˍΩϟογϡ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  67. Ϣʔεέʔε1ɿϦτϥΠˍΩϟογϡ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  68. Ϣʔεέʔε1ɿϦτϥΠˍΩϟογϡ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  69. Ϣʔεέʔε1ɿϦτϥΠˍΩϟογϡ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorReturn(new Func1<Throwable, List<GithubContributor>>() {
 @Override
 public List<GithubContributor> call(Throwable throwable) {
 return dao.findAll(); // DB͔Βऔಘ
 }
 });
  70. Ϣʔεέʔε2ɿϦτϥΠˍΩϟογϡˍτʔετ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override
 public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (dao.exists()) {
 return Observable.just(dao.findAll());
 }
 return Observable.error(throwable);
 }
 }
 );
  71. Ϣʔεέʔε2ɿϦτϥΠˍΩϟογϡˍτʔετ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override
 public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (dao.exists()) {
 return Observable.just(dao.findAll());
 }
 return Observable.error(throwable);
 }
 }
 );
  72. Ϣʔεέʔε2ɿϦτϥΠˍΩϟογϡˍτʔετ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override
 public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (dao.exists()) {
 return Observable.just(dao.findAll());
 }
 return Observable.error(throwable);
 }
 }
 );
  73. Ϣʔεέʔε2ɿϦτϥΠˍΩϟογϡˍτʔετ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override
 public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (dao.exists()) {
 return Observable.just(dao.findAll());
 }
 return Observable.error(throwable);
 }
 }
 );
  74. Ϣʔεέʔε2ɿϦτϥΠˍΩϟογϡˍτʔετ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override
 public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (dao.exists()) {
 return Observable.just(dao.findAll());
 }
 return Observable.error(throwable);
 }
 }
 );
  75. Ϣʔεέʔε2ɿϦτϥΠˍΩϟογϡˍτʔετ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override
 public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (dao.exists()) {
 return Observable.just(dao.findAll());
 }
 return Observable.error(throwable);
 }
 }
 );
  76. Ϣʔεέʔε2ɿϦτϥΠˍΩϟογϡˍτʔετ client.getDroidKaigiContributors() // αʔόʔ͔Βऔಘ
 .retry(3)
 .doOnNext(new Action1<List<GithubContributor>>() {
 @Override
 public

    void call(List<GithubContributor> githubContributors) {
 dao.insertAll(githubContributors); // DBʹอଘ
 }
 })
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends List<GithubContributor>>>() {
 @Override
 public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (dao.exists()) {
 return Observable.just(dao.findAll());
 }
 return Observable.error(throwable);
 }
 }
 );
  77. RetrofitͷΤϥʔϋϯυϦϯά • جຊฤͰ঺հͨ͠ʮΤϥʔͷछྨͰॲཧΛ෼ذ͢ΔʯΛ શAPIʹ࢓ࠐΈ͍ͨ client.getDroidKaigiContributors()
 .onErrorResumeNext(
 new Func1<Throwable, Observable<? extends

    List<GithubContributor>>>() {
 @Override
 public Observable<? extends List<GithubContributor>> call(
 Throwable throwable) {
 if (throwable instanceof AccessTokenExpiredException) {
 // ϩάΞ΢τ
 }
 
 if (throwable instanceof MaintenanceModeException) {
 // ϝϯςφϯεϞʔυ
 }
 
 return Observable.error(throwable);
 }
 }
 );
  78. RetrofitͷΤϥʔϋϯυϦϯά public class RxJavaErrorHandlingCallAdapterFactory extends CallAdapter.Factory {
 
 public static

    RxJavaErrorHandlingCallAdapterFactory create() {
 return new RxJavaErrorHandlingCallAdapterFactory();
 }
 
 private final CallAdapter.Factory original = RxJavaCallAdapterFactory.create();
 
 @Override
 public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
 return new RxJavaCallAdapterWrapper(original.get(returnType, annotations, retrofit));
 }
 
 private static class RxJavaCallAdapterWrapper<R>
 implements CallAdapter<R, Observable<?>> {
 private final CallAdapter<R, ?> original;
 
 public RxJavaCallAdapterWrapper(CallAdapter<R, ?> original) {
 this.original = original;
 }
 
 @Override
 public Type responseType() {
 return original.responseType();
 }
 
 @Override
 public Observable<?> adapt(Call<R> call) {
 return ((Observable<?>) original.adapt(call))
 .onErrorResumeNext(new ErrorHandler<>());
 }
 }
 }
  79. RetrofitͷΤϥʔϋϯυϦϯά public class RxJavaErrorHandlingCallAdapterFactory extends CallAdapter.Factory {
 
 public static

    RxJavaErrorHandlingCallAdapterFactory create() {
 return new RxJavaErrorHandlingCallAdapterFactory();
 }
 
 private final CallAdapter.Factory original = RxJavaCallAdapterFactory.create();
 
 @Override
 public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
 return new RxJavaCallAdapterWrapper(original.get(returnType, annotations, retrofit));
 }
 
 private static class RxJavaCallAdapterWrapper<R>
 implements CallAdapter<R, Observable<?>> {
 private final CallAdapter<R, ?> original;
 
 public RxJavaCallAdapterWrapper(CallAdapter<R, ?> original) {
 this.original = original;
 }
 
 @Override
 public Type responseType() {
 return original.responseType();
 }
 
 @Override
 public Observable<?> adapt(Call<R> call) {
 return ((Observable<?>) original.adapt(call))
 .onErrorResumeNext(new ErrorHandler<>());
 }
 }
 }
  80. RetrofitͷΤϥʔϋϯυϦϯά private static class RxJavaCallAdapterWrapper<R>
 implements CallAdapter<R, Observable<?>> {
 private

    final CallAdapter<R, ?> original;
 
 public RxJavaCallAdapterWrapper(CallAdapter<R, ?> original) {
 this.original = original;
 }
 
 @Override
 public Type responseType() {
 return original.responseType();
 }
 
 @Override
 public Observable<?> adapt(Call<R> call) {
 return ((Observable<?>) original.adapt(call))
 .onErrorResumeNext(new ErrorHandler<>());
 }
 }
  81. RetrofitͷΤϥʔϋϯυϦϯά private static class RxJavaCallAdapterWrapper<R>
 implements CallAdapter<R, Observable<?>> {
 private

    final CallAdapter<R, ?> original;
 
 public RxJavaCallAdapterWrapper(CallAdapter<R, ?> original) {
 this.original = original;
 }
 
 @Override
 public Type responseType() {
 return original.responseType();
 }
 
 @Override
 public Observable<?> adapt(Call<R> call) {
 return ((Observable<?>) original.adapt(call))
 .onErrorResumeNext(new ErrorHandler<>());
 }
 }