Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RxJava
Search
Douglas Kayama
August 29, 2015
Programming
5
550
RxJava
Palestra apresentada na QCon RJ 2015 e Android Dev Conference iMasters 2015
Douglas Kayama
August 29, 2015
Tweet
Share
More Decks by Douglas Kayama
See All by Douglas Kayama
TensorFlow no Android – v2
douglasdrumond
0
28
BLE
douglasdrumond
0
29
TensorFlow no Android
douglasdrumond
0
19
Firebase or Realm?
douglasdrumond
0
78
Rio Dev Day – Introdução ao Android
douglasdrumond
0
97
Google I/O
douglasdrumond
0
61
Criando apps com alto nível de qualidade (versão longa)
douglasdrumond
0
37
Criando apps com alto nível de qualidade (versão curta)
douglasdrumond
0
25
Primeiros Passos com Google Fit
douglasdrumond
0
190
Other Decks in Programming
See All in Programming
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Go の GC の不得意な部分を克服したい
taiyow
3
850
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
210
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
5
960
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
8
1.9k
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
200
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.5k
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
160
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
570
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
160
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
360
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
244
12k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
A Philosophy of Restraint
colly
203
16k
KATA
mclloyd
29
14k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
BBQ
matthewcrist
85
9.4k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
How to Ace a Technical Interview
jacobian
276
23k
Being A Developer After 40
akosma
87
590k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Transcript
RxJava Douglas Drumond
[email protected]
whoami
None
Por que RxJava? Eventos de UI Eventos do domínio Concorrência
RxJava Observer pattern Iterator pattern Functional programming
Lambda
Retrolambda export JAVA_HOME=/path/java8 export JAVA7_HOME=/path/java7
Retrolambda plugins { id "me.tatarka.retrolambda" version "3.2.2" } android {
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
Retrolambda view.setOnClickListener(new View. OnClickListener() { @Override public void onClick(final View
v) { ... } });
Retrolambda view.setOnClickListener(v -> { });
Básico Observables Subscribers Operadores
Observables Emite itens Chama onNext, onComplete ou onError Hot or
Cold
Subscriber Implementa onNext onComplete onError
Operadores flatMap filter debounce create defer etc
Criando Observable e Subscriber DEMO
Operators Subscribers reagem, não mudam Operadores transformam dados
Operators DEMO
Exemplo com UI DEMO
Mais operadores filter Ex: .filter(query -> !TextUtils.isEmpty(query))
Threads subscribeOn observeOn NewThreadScheduler HandlerThreadScheduler
Rede DEMO
Tratamento de erros Observable.create(...) .map(s -> exception(s)) .map(s -> exception2(s))
.subscribe(new Subscriber<String>() { @Override public void onNext(String s) { Log.d(TAG, s); } @Override public void onCompleted() { Log.d(TAG, "uhu!"); } @Override public void onError(Throwable e) { Log.e(TAG, "ops!"); } });
Ciclo de vida da Activity .cache .unsubscribe ao rodar .subscribe
ao restaurar Use RxLifecycle
Google Play Services https://github.com /mcharmas/Android-ReactiveLocation https://github.com /zmarkan/Reactive-PlayServices
Google Play Services ReactiveLocationProvider locationProvider = new ReactiveLocationProvider(context); locationProvider.getLastKnownLocation() .subscribe(new
Action1<Location>() { @Override public void call(Location location) { doSthImportantWithObtainedLocation(location); } });
Testes @Test public void shouldLoadTwoUsers() throw Exception { TestSubscriber<User> testSubscriber
= new TestSubscriber<>(); databaseHelper.loadUser().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertReceivedOnNext( Arrays.asList(user1, user2)) }
Testes https://github.com/ribot/assertj-rx + BlockingObservable
Testes (exemplo) assertThat(observable.toBlocking()). completes(); assertThat(observable.toBlocking()) .completes() .listOfValuesEmitted() .containsExactly("a", "b", "c");
Referências http://reactivex.io/ https://github.com/ReactiveX/RxJava/wiki /Alphabetical-List-of-Observable-Operators https://speakerdeck.com/benjchristensen https://github.com/mutexkid/rxjava-koans
Referências https://github.com/trello/RxLifecycle https://github.com/JakeWharton/RxBinding https://github.com/ReactiveX/RxAndroid/
Código https://github.com/ douglasdrumond/KnightsOfLambdaCalculus
Obrigado
Contato
[email protected]
@douglasdrumond +DouglasDrumond www.cafelinear.com
[email protected]