Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RxJava
Search
Douglas Kayama
August 29, 2015
Programming
580
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxJava
Palestra apresentada na QCon RJ 2015 e Android Dev Conference iMasters 2015
Douglas Kayama
August 29, 2015
More Decks by Douglas Kayama
See All by Douglas Kayama
TensorFlow no Android – v2
douglasdrumond
0
57
BLE
douglasdrumond
0
38
TensorFlow no Android
douglasdrumond
0
40
Firebase or Realm?
douglasdrumond
0
87
Rio Dev Day – Introdução ao Android
douglasdrumond
0
110
Google I/O
douglasdrumond
0
75
Criando apps com alto nível de qualidade (versão longa)
douglasdrumond
0
53
Criando apps com alto nível de qualidade (versão curta)
douglasdrumond
0
38
Primeiros Passos com Google Fit
douglasdrumond
0
210
Other Decks in Programming
See All in Programming
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
880
AmebaブログはKMPから卒業します
kmars0605
0
180
気持ちぃ〜角丸 Squircle
ryu1013
0
310
すこし踏み込む CancellationToken
htkym
2
1.7k
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
170
contenteditable と日本語入力に向き合う
colorful12
0
200
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
Featured
See All Featured
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
410
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
750
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
How to Ace a Technical Interview
jacobian
280
24k
How GitHub (no longer) Works
holman
316
150k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
Optimizing for Happiness
mojombo
378
71k
Everyday Curiosity
cassininazir
0
350
Building the Perfect Custom Keyboard
takai
2
910
Google's AI Overviews - The New Search
badams
0
1.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
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]