Slide 1

Slide 1 text

RxJava ೖ໳ Droid Girls Meetup #6 ࠇ઒ ༸ (@hydrakecat)

Slide 2

Slide 2 text

3Y+BWBהכ ▸ 3Y 3FBDUJWF&YUFOTJPO ך+BWB㹋鄲 ▸ ➭ח׮$װ+4זוד㹋鄲ָ֮׷ ▸ 嚊䙀װ欽铂ָ♧筰זךד鎉铂ָ㢌׻׏ג׮椚鍑׃ װְׅ

Slide 3

Slide 3 text

3Y+BWBהכ ▸ ꬊず劍Ⳣ椚׾䪔ֲ׋׭ךٓ؎ـٓٔ ▸ طحزٙ٦ؙ鸐⥋ծ%#㉏ְさ׻ׇ ▸ 6*؎كٝز

Slide 4

Slide 4 text

3Y+BWB ▸ 3Y+BWBכY禸הY禸ד㣐ֹֻ麩ְתׅ ▸ 欽铂ծⵖꣲծؔلٖ٦ةזו ▸ ➙㔐כ3Y+BWB׾⢪ְתׅ ▸ ָծ׉ֿתד麩ְ׾孡ח׃זֻג㣐♱㣗דׅ

Slide 5

Slide 5 text

3Yך嚊䙀

Slide 6

Slide 6 text

؎كٝزח⿾䘔ׅ׷׌ֽ# service.contributors(new NetworkCall.Listener>() {
 @Override public void success(List data) {
 runOnUiThread(() -> {
 if (!isDestroyed()) {
 adapter.setContributors(data);
 }
 });
 }
 
 @Override public void failure(Throwable t) {}
 }); 3Yך؝خ أٖحس䭷㹀 ٓ؎ؿ؟؎ؙٕثؑحؙ

Slide 7

Slide 7 text

؎كٝزח⿾䘔ׅ׷׌ֽ# 3Yך؝خ service.contributors()
 …
 .subscribe(
 data -> adapter.setContributors(data),
 throwable -> Log.e(TAG, throwable.getMessage())
 ); וֲ⿾䘔ׅ׷ַ׌ֽ剅ֻ

Slide 8

Slide 8 text

؎كٝزח⿾䘔ׅ׷׌ֽ# 3Yך؝خ service.contributors()
 …
 .subscribe(
 data -> adapter.setContributors(data),
 throwable -> Log.e(TAG, throwable.getMessage())
 ); ֿֿחאְגכ䖓鶢

Slide 9

Slide 9 text

3Yך嚊䙀 { Observable # Observer subscribe emit emit emit Event subscribeঢ়گΛ؅ཧ͢Δ΋ͷ = Disposable

Slide 10

Slide 10 text

0CTFSWBCMF ‣ &WFOU׾וֲFNJUׅ׷ַ׾㹀׭׷ ‣ 荈ⴓד⡲׷ֿהכ֮ת׶זְ ‣ طحزٙ٦ؙ鸐⥋̔3FUSPU ‣ 6*؎كٝز̔3Y#JOEJOH // 1ඵ͝ͱʹLongܕͷΠϕϯτ͕emit͞ΕΔʢ1, 2, 3, …ʣ Observable.interval(1, TimeUnit.SECONDS); 
 // Ϧετͷཁૉ͕1ͭͣͭemit͞ΕΔ Observable.fromIterable(list);

Slide 11

Slide 11 text

0CTFSWFS ‣ ؎كٝز׾「ֽ《׏גוֲ⿾䘔ׅ׷ַ׾㹀׭׷ ‣ 0CTFSWBCMFTVCTDSJCF ך䒷侧ח♷ִ׷ ‣ ؎كٝز׀הח؝٦ٕغحًؙاحسָㄎל׸׷

Slide 12

Slide 12 text

0CTFSWFS service.contributors(owner, repository)
 .subscribe(new Observer>() {
 @Override public void onSubscribe(Disposable d) {
 }
 
 @Override public void onNext(List contributors) {
 }
 
 @Override public void onError(Throwable e) {
 }
 
 @Override public void onComplete() {
 }
 });
 TVCTDSJCFׁ׸׋ FWFOU׾「ֽ《׏׋ ؒٓ٦ָ饯ֹ׋ ֿ׸⟃♳FWFOUָזְ

Slide 13

Slide 13 text

service.contributors(owner, repository)
 .subscribe(new DefaultObserver>() {
 @Override public void onNext(List contributors) {
 ‌}
 
 @Override public void onError(Throwable e) {
 ‌}
 
 @Override public void onComplete() {
 ‌}
 });
 0CTFSWFS

Slide 14

Slide 14 text

service.contributors(owner, repository)
 .subscribe( contributors -> {},
 throwable -> {},
 () -> {} );
 
 0CTFSWFS

Slide 15

Slide 15 text

圫ղז0CTFSWBCMF ‣ PO/FYU ָ⡦㔐׮ㄎל׸גPO$PNQMFUFE כ宕黅 חㄎל׸זְ ‣ PO/FYU ָ㔐׌ֽㄎל׸ג湫䖓חPO$PNQMFUFE DPNQMFUFE

Slide 16

Slide 16 text

圫ղז0CTFSWBCMF ‣ PO/FYU ָ㔐׮ㄎל׸׆חPO&SSPS ָㄎל׸׷ FSSPS

Slide 17

Slide 17 text

%JTQPTBCMF ‣ TVCTDSJCFך朐䡾׾盖椚 ‣ 0CTFSWBCMFTVCTDSJCF ך䨱׶⦼ ‣ %JTQPTBCMFEJTQPTF ׾ㄎעהծ
 ׉׸⟃꣬כ0CTFSWFSכ؎كٝز׾「ֽ《׵זְ

Slide 18

Slide 18 text

%JTQPTBCMF @Override protected void onCreate(Bundle savedInstanceState) {
 …
 disposable = service.contributors(owner, repository)
 .subscribe(
 contributors -> {},
 throwable -> {},
 () -> {}
 ); }
 
 @Override protected void onDestroy() {
 super.onDestroy();
 if (disposable != null) {
 disposable.dispose();
 }
 } ֿ׸⟃꣬כ؎كٝز׾「ֽ《׵זְ

Slide 19

Slide 19 text

%JTQPTBCMF ‣ "OESPJEדכTVCTDSJCFהEJTQPTFך㜥䨽ָٓ؎ ؿ؟؎ؙٕ♳ד㼎獥חז׷״ֲחׅ׷ ‣ TVCTDSJCFPO$SFBUF EJTQPTFPO%FTUSPZ ‣ TVCTDSJCFPO4UBSU EJTQPTFPO4UPQ ‣ TVCTDSJCFPO"UUBDIFE5P8JOEPX 
 EJTQPTFPO%FUBDIFE'SPN8JOEPX

Slide 20

Slide 20 text

3Yך؝خ 0CTFSWBCMF׾㢌䳔׃גְֻؔلٖ٦ة׾黝欽ׅ׷ ֿהדծ実׭׷0CTFSWBCMFחׅ׷

Slide 21

Slide 21 text

تـٕةحف׾嗚⳿׃׋ְ = Operator 0QFSBUPS ྡΓ߹͏Πϕϯτ͕Ұఆ࣌ؒҎ಺
 ͩͬͨΒΠϕϯτΛemit͢ΔΑ͏ͳObservable
 ʹม׵͢Δ

Slide 22

Slide 22 text

圫ղז0QFSBUPS ▸ MUFS ▸ 勴⟝ח֮׏׋؎كٝز׌ֽ鸐ׅ

Slide 23

Slide 23 text

圫ղז0QFSBUPS ▸ UBLF ▸ ؎كٝز׾⯓걧ַ׵䭷㹀ׁ׸׋侧׌ֽ鸐ׅ

Slide 24

Slide 24 text

圫ղז0QFSBUPS ▸ NBQ ▸ ؎كٝز׾㢌䳔ׅ׷

Slide 25

Slide 25 text

圫ղז0QFSBUPS ▸ BU.BQ ▸ ؎كٝزאאַ׵倜׋ח0CTFSWBCMF׾⡲ ׶ծ׉ַֿ׵FNJUׁ׸׷؎كٝز׾תה׭׷

Slide 26

Slide 26 text

NBQהBU.BQך⢪ְⴓֽ ‣ ♧菙涸ח㢌䳔䖓ך؎كٝزָ0CTFSWBCMFחז׷ז ׵BU.BQ׾⢪ֲ ‣ ⢽Ⰵ׸㶨ךطحزٙ٦ؙ鸐⥋ ‣ ⢽ٔأز׾㾜Ꟛׅ׷ service.items()
 .flatMap(item -> service.user(item.getUser())) service.usersList()
 .flatMap(users -> Observable.fromIterable(users))

Slide 27

Slide 27 text

NBQהBU.BQך⢪ְⴓֽ ‣ ׉ֲדזְז׵NBQ׾⢪ֲ ‣ ⢽ٔأزך"EBQUFS欽חؔـآؙؑز׾㢌䳔 service.users()
 .map(user -> new Contributor(user.getLogin(), user.getName()))

Slide 28

Slide 28 text

圫ղז0QFSBUPS ▸ DPNCJOF-BUFTU ▸ 醱侧ך0CTFSWBCMFךֲ׍ծוַָֿ؎كٝز׾ FNJU׃׋׵ծ➭ך0CTFSWBCMFך剑倜ך؎كٝ زהさ׻ׇ׋؎كٝز׾FNJUׅ׷

Slide 29

Slide 29 text

圫ղז0QFSBUPS ▸ DPNCJOF-BUFTU

Slide 30

Slide 30 text

圫ղז0QFSBUPS ▸ TVCTDSJCF0O ▸ ؎كٝز׾FNJUׅ׷הֹךأٖحس׾㢌刿ׅ׷ service.contributors(owner, repository)
 .subscribeOn(Schedulers.io())
 طحزٙ٦ؙ鸐⥋׾ً؎ٝأٖحسהⴽךأٖحسד遤ֲ

Slide 31

Slide 31 text

圫ղז0QFSBUPS ▸ TVCTDSJCF0O ▸ ؎كٝز׾FNJUׅ׷הֹךأٖحس׾㢌刿ׅ׷ ▸ 姻然חכ׍׳׏ה麩ְתָׅծה׶ִ֮׆כֿ ְֲֲ椚鍑ד$

Slide 32

Slide 32 text

圫ղז0QFSBUPS ▸ PCTFSWF0O ▸ ؎كٝز׾「ֽ《׷הֹךأٖحس׾㢌刿ׅ׷ service.contributors(owner, repository)
 .subscribeOn(Schedulers.io())
 .observeOn(AndroidSchedulers.mainThread()) .subscribe(contributors -> { … }) TVCTDSJCF ⰻד遤ֲⳢ椚׾ً؎ٝأٖحسד遤ֲ

Slide 33

Slide 33 text

圫ղז0QFSBUPS ▸ GSPN*UFSBCMF ▸ ٔأز*UFSBCMFַ׵0CTFSWBCMF׾⡲׷ FromIterable

Slide 34

Slide 34 text

圫ղז0QFSBUPS ▸ UP-JTU ▸ ؎كٝز׾Ⰻ鿇תה׭ג-JTUחׅ׷ toList

Slide 35

Slide 35 text

3Yך؝خ ▸ ؿؑ٦أחⴓֽג罋ִ׷ ▸ ر٦ةך崧׸׾ת׆㹀纏 ▸ 0CTFSWBCMF׾欽䠐׃׋׶ծPQFSBUPS׾籬ְד וֲ㢌䳔ׅ׷ַ䭷爙ׅ׷ ▸ ر٦ة׾崧ׅ ▸ TVCTDSJCFׅ׷

Slide 36

Slide 36 text

Pipes by Domiriel CC BY-NC 2.0

Slide 37

Slide 37 text

״ֻ֮׷⹞麩ְ ‣ 0CTFSWBCMF׾⡲׏׋׵ծּׅחFWFOUָFNJUׁ׸׷ Observable> o = service.contributors(); ת׌طحزٙ٦ؙ鸐⥋כ
 饯ֹזְ

Slide 38

Slide 38 text

״ֻ֮׷⹞麩ְ ‣ 0CTFSWBCMF׾⡲׏׋׵ծּׅחFWFOUָFNJUׁ׸׷ Observable> o = service.contributors(); o.subscribe(contributors -> {}, throwable -> {}, () -> {}); طحزٙ٦ؙ鸐⥋ָ饯ֹ׷

Slide 39

Slide 39 text

״ֻ֮׷⹞麩ְ ‣ 0CTFSWBCMF׾⡲׏׋׵ծּׅחFWFOUָFNJUׁ׸׷ ‣ 0CTFSWBCMFָⰟ剣ׁ׸׷ Observable> o = service.contributors(); o.subscribe(contributors -> {}, throwable -> {}, () -> {}); o.subscribe(contributors -> {}, throwable -> {}, () -> {}); طحزٙ٦ؙ鸐⥋ָ饯ֹ׷さ鎘㔐

Slide 40

Slide 40 text

رغحؚך؝خ ▸ EP0O&BDIؔلٖ٦ة׾ⵃ欽ׅ׷ service.contributors(owner, repository)
 .doOnEach(event -> Log.d(TAG, "event: " + event))
 .flatMap(…) .map(…)
 … MainActivity D notification: OnNextNotification[[…]] MainActivity D notification: OnCompleteNotification

Slide 41

Slide 41 text

➙傈鑧ׁזַ׏׋ֿה ▸ 4JOHMF .BZCF $PNQMFUBCMF ▸ )PU0CTFSWBCMFה$PME0CTFSWBCMF ▸ 4VCKFDU ▸ 'MPXBCMFה0CTFSWBCMFך麩ְ ▸ #BDLQSFTTVSFהכ ▸ ذأز

Slide 42

Slide 42 text

⿫罋俑柃 ‣ IUUQSFBDUJWFYJP ‣ IUUQSYXJLJXJLJEPUDPNTBNQMFT ‣ ˑ3FBDUJWF1SPHSBNNJOHXJUI3Y+BWB$SFBUJOH "TZODISPOPVT &WFOU#BTFE"QQMJDBUJPOT˒ 5PNBT[/VSLJFXJD[ #FO$ISJTUFOTFO