SlideShare a Scribd company logo
Dagger & RxJava & 
Retrofit 
Ted
what is Dagger 
Dagger is a Dependency Injector
example1 
public class School { 
public Teacher teacher = new Teacher(); 
}
Cons? 
● school 裡會有很多teacher,但是如果沒有 
setter 代表school必須跟teacher綁定 
● how to test?
example2 
public class School { 
public Teacher teacher ; 
public void setTeacher(Teacher t){ 
teacher = t; 
} 
}
Pros 
● now we can set whoever we want. 
● and easy to test
TestSample 
s = new Schoole(); 
s.setTeacher(new MockTeacher()); 
assert.equals(s.getTeacherName(),”balabala”);
so...how to use dagger 
● source (Module) 
● target (class)
Source (Module) 
create a @Module 
tell the module you are going to @Inject to 
which class 
@Provides a type to that class
Target(class) 
@Inject the Modules to class 
auto @Inject to field or get type by code
example1 
demo and explain 
https://github. 
com/nightbear1009/Dagger_StepByStep 
repository = feature/simpleDagger
example2 
demo and explain 
https://github. 
com/nightbear1009/Dagger_StepByStep 
repository = feature/plusIfNecessary
what’s the meaning of plus? 
AppGraph 
NetworkModules 
AccountModules
what’s the meaning of plus? 
AppGraph 
NetworkModules 
AccountModules 
LoginGraph 
LoginHelperModules 
UserLogin App + Login Graph
what’s the meaning of plus? 
UserLogout 
AppGraph 
NetworkModules 
AccountModules
what about test 
override
example3 
https://github. 
com/nightbear1009/Dagger_StepByStep 
repository = feature/testTeacher
Rxjava 
Funtional Programing
forEach 
rx.Observable.from("1","2","3").forEach(new Action1<String>() { 
@Override 
public void call(String s) { 
Log.d("Ted","s "+s); 
} 
}); 
s 1 
s 2 
s 3
map 
rx.Observable.from("1","2","3").map(new Func1<String, Boolean>() { 
@Override 
public Boolean call(String s) { 
return s.equals("1"); 
} 
}).subscribe(new Action1<Object>() { 
@Override 
public void call(Object o) { 
Log.d("Ted","o "+o); 
} 
}); 
o true 
o false 
o false
flapMap 
rx.Observable.from("1","2","3").flatMap(new Func1<String, rx.Observable<?>>() { 
@Override 
public rx.Observable<?> call(String s) { 
Log.d("Ted","num "+s); 
return rx.Observable.from(s); 
} 
}).subscribe(new Action1<Object>() { 
@Override 
public void call(Object o) { 
} 
}); 
num 1 
num 2 
num 3
filter 
rx.Observable.from("1","2","3").filter(new Func1<String, Boolean>() { 
@Override 
public Boolean call(String s) { 
return s.equals("1"); 
} 
}).subscribe(new Action1<String>() { 
@Override 
public void call(String s) { 
Log.d("Ted","s "+s); 
} 
}); 
s 1
toSortedList 
rx.Observable.from("1","3","2").toSortedList(new Func2<String, String, Integer>() { 
@Override 
public Integer call(String s, String s2) { 
return Integer.valueOf(s2) - Integer.valueOf(s); 
} 
}).subscribe(new Action1<List<String>>() { 
@Override 
public void call(List<String> strings) { 
for(String s :strings){ 
Log.d("Ted","s "+s); 
} 
} 
}); 
s 3 
s 2 
s 1
groupby 
false integer 1 false integer 3 
true integer 2 true integer 2 false integer 3 
false integer 5 true integer 6 false integer 7 
true integer 8 false integer 9
Observable.just vs Observable.from 
一次丟全部資料和一次丟一筆資料的差別?
without publish + connect 
D s url1 
D s url2 
D s url3 
D s2 url1 
D s2 url2 
D s2 url3
publish + connect 
D s url1 
D s2 url1 
D s url2 
D s2 url2 
D s url3 
D s2 url3
refcount 
還沒時間看XD
Pros & Cons 
Pros 
logic will be clear 
Cons 
high leaning curve 
lots of callback(with retrolamda maybe better)
Ingram 說 
http://ingramchen. 
io/blog/2014/10/retromlambda.html
華生大大 說 
https://twitter. 
com/jakewharton/status/3858989968 
84971520
過了幾個月後 華生大大又說..
華生大大 again
都是別人說,現在換我說XD 
rxjava的確算是較大型的lib,learning curve比較 
高,有很多東西需要花時間學習&了解. 
but如果我們只是用來處理 api + data handle 而 
不用來處理複雜的邏輯 or data combining... 
(https://github.com/nightbear1009/RxAndroid- 
Login-Sample ), 
我相信會是個不錯的選擇
Retrofit 
three steps 
1. create interface 
2. create api 
3. handleData
Dagger & rxjava & retrofit
Dagger & rxjava & retrofit
Dagger & rxjava & retrofit
retrofit 
1. build in gson 
2. no need to implement parcelable 
3. easy to test
test
test more with gradle + dagger 
前情提要: 
randy: 有沒有可能寫出 
XXXListView.get(url) ; 然後就可以畫出layout的 
辦法? 
https://github. 
com/nightbear1009/SmallDaggerRetr 
ofitRxjavaSample
當然,目前的版本還有很多高耦合的問題必須解 
決,ex : adapter 但或許是個將view 封裝的一個 
方向?
so… what can we do with these lib 
Demo Time again
Conclusion 
● use Retrofit to handle Network api 
● use dagger to injection every retrofit’s 
adapter 
(so we can mock the api data) 
● use rxjava to handle every event including 
api call back 
(so our logic will be clearly)

More Related Content

What's hot (19)

PDF
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
NAVER / MusicPlatform
 
PDF
The Ring programming language version 1.6 book - Part 184 of 189
Mahmoud Samir Fayed
 
PPTX
Reactive Programming no Android
Guilherme Branco
 
PDF
JVM Mechanics
Doug Hawkins
 
PDF
JVM Mechanics: Understanding the JIT's Tricks
Doug Hawkins
 
PPTX
Reactive Programming on Android
Guilherme Branco
 
PDF
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
PPTX
Apache Flink Training: DataSet API Basics
Flink Forward
 
PDF
Virtual machine and javascript engine
Duoyi Wu
 
PDF
The Ring programming language version 1.5.4 book - Part 26 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 25 of 181
Mahmoud Samir Fayed
 
PDF
Use C++ to Manipulate mozSettings in Gecko
Chih-Hsuan Kuo
 
PDF
Java_practical_handbook
Manusha Dilan
 
PDF
The Ring programming language version 1.5.2 book - Part 13 of 181
Mahmoud Samir Fayed
 
PDF
Java 8 Stream API. A different way to process collections.
David Gómez García
 
PDF
Effective Modern C++ - Item 35 & 36
Chih-Hsuan Kuo
 
PPT
bluespec talk
Suman Karumuri
 
PDF
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch
 
PPTX
Deep Dumpster Diving
RonnBlack
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
NAVER / MusicPlatform
 
The Ring programming language version 1.6 book - Part 184 of 189
Mahmoud Samir Fayed
 
Reactive Programming no Android
Guilherme Branco
 
JVM Mechanics
Doug Hawkins
 
JVM Mechanics: Understanding the JIT's Tricks
Doug Hawkins
 
Reactive Programming on Android
Guilherme Branco
 
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
Apache Flink Training: DataSet API Basics
Flink Forward
 
Virtual machine and javascript engine
Duoyi Wu
 
The Ring programming language version 1.5.4 book - Part 26 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 25 of 181
Mahmoud Samir Fayed
 
Use C++ to Manipulate mozSettings in Gecko
Chih-Hsuan Kuo
 
Java_practical_handbook
Manusha Dilan
 
The Ring programming language version 1.5.2 book - Part 13 of 181
Mahmoud Samir Fayed
 
Java 8 Stream API. A different way to process collections.
David Gómez García
 
Effective Modern C++ - Item 35 & 36
Chih-Hsuan Kuo
 
bluespec talk
Suman Karumuri
 
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch
 
Deep Dumpster Diving
RonnBlack
 

Viewers also liked (13)

PDF
RxJava+RxAndroid (Lecture 20 – rx java)
Noveo
 
PDF
Practical RxJava for Android
Tomáš Kypta
 
PDF
RxJava + Retrofit
Dev2Dev
 
PDF
Rx java x retrofit
Shun Nakahara
 
PDF
Retrofit Android by Chris Ollenburg
Trey Robinson
 
PPTX
Reactive programming with RxAndroid
Savvycom Savvycom
 
PDF
Retrofit
bresiu
 
PPTX
Introduction to rx java for android
Esa Firman
 
PDF
Introduction to Retrofit and RxJava
Fabio Collini
 
PDF
Realm: Building a mobile database
Christian Melchior
 
PPTX
Reactive Programming on Android - RxAndroid - RxJava
Ali Muzaffar
 
PPTX
Retrofitting
Rizwan Samor
 
PDF
Designing Teams for Emerging Challenges
Aaron Irizarry
 
RxJava+RxAndroid (Lecture 20 – rx java)
Noveo
 
Practical RxJava for Android
Tomáš Kypta
 
RxJava + Retrofit
Dev2Dev
 
Rx java x retrofit
Shun Nakahara
 
Retrofit Android by Chris Ollenburg
Trey Robinson
 
Reactive programming with RxAndroid
Savvycom Savvycom
 
Retrofit
bresiu
 
Introduction to rx java for android
Esa Firman
 
Introduction to Retrofit and RxJava
Fabio Collini
 
Realm: Building a mobile database
Christian Melchior
 
Reactive Programming on Android - RxAndroid - RxJava
Ali Muzaffar
 
Retrofitting
Rizwan Samor
 
Designing Teams for Emerging Challenges
Aaron Irizarry
 
Ad

Similar to Dagger & rxjava & retrofit (18)

PDF
Functional Reactive Programming on Android
Sam Lee
 
PDF
Rxjava 介紹與 Android 中的 RxJava
Kros Huang
 
PDF
Testing Android apps based on Dagger and RxJava Droidcon UK
Fabio Collini
 
PDF
Sharper Better Faster Dagger ‡ - Droidcon SF
Pierre-Yves Ricau
 
PDF
Using Dagger in a Clean Architecture project
Fabio Collini
 
PDF
"Kotlin и rx в android" Дмитрий Воронин (Avito)
AvitoTech
 
PDF
Coding in Style
scalaconfjp
 
PDF
Modern Android app library stack
Tomáš Kypta
 
PDF
What we use to build Android apps at Silicon Straits
Silicon Straits
 
PDF
Intro to Retrofit 2 and RxJava2
Fabio Collini
 
PDF
Rxjava meetup presentation
Guillaume Valverde
 
PDF
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Sigma Software
 
PDF
It's complicated, but it doesn't have to be: a Dagger journey
Thiago “Fred” Porciúncula
 
PDF
Async code on kotlin: rx java or/and coroutines - Kotlin Night Turin
Fabio Collini
 
PDF
科特林λ學
彥彬 洪
 
PDF
Testing Android apps based on Dagger and RxJava
Fabio Collini
 
PDF
Programming Android Application in Scala.
Brian Hsu
 
PPTX
從零開始學 Android
秀吉(Hsiu-Chi) 蔡(Tsai)
 
Functional Reactive Programming on Android
Sam Lee
 
Rxjava 介紹與 Android 中的 RxJava
Kros Huang
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Fabio Collini
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Pierre-Yves Ricau
 
Using Dagger in a Clean Architecture project
Fabio Collini
 
"Kotlin и rx в android" Дмитрий Воронин (Avito)
AvitoTech
 
Coding in Style
scalaconfjp
 
Modern Android app library stack
Tomáš Kypta
 
What we use to build Android apps at Silicon Straits
Silicon Straits
 
Intro to Retrofit 2 and RxJava2
Fabio Collini
 
Rxjava meetup presentation
Guillaume Valverde
 
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Sigma Software
 
It's complicated, but it doesn't have to be: a Dagger journey
Thiago “Fred” Porciúncula
 
Async code on kotlin: rx java or/and coroutines - Kotlin Night Turin
Fabio Collini
 
科特林λ學
彥彬 洪
 
Testing Android apps based on Dagger and RxJava
Fabio Collini
 
Programming Android Application in Scala.
Brian Hsu
 
從零開始學 Android
秀吉(Hsiu-Chi) 蔡(Tsai)
 
Ad

More from Ted Liang (12)

PPTX
google play service 7.8 & new tech in M
Ted Liang
 
PPTX
what new in google io 2015
Ted Liang
 
PPTX
Android Activity Transition(ShareElement)
Ted Liang
 
PPTX
Android Activity Transition(ShareElement)
Ted Liang
 
PPTX
無標題簡報
Ted Liang
 
PDF
Android Gradle about using flavor
Ted Liang
 
PPTX
Strategy Pattern
Ted Liang
 
PPTX
Adapter Pattern
Ted Liang
 
PPTX
設計模式的解析與活用 -開拓視野
Ted Liang
 
PDF
Design pattern intro
Ted Liang
 
PPTX
物件導向範型
Ted Liang
 
PPT
Git簡報
Ted Liang
 
google play service 7.8 & new tech in M
Ted Liang
 
what new in google io 2015
Ted Liang
 
Android Activity Transition(ShareElement)
Ted Liang
 
Android Activity Transition(ShareElement)
Ted Liang
 
無標題簡報
Ted Liang
 
Android Gradle about using flavor
Ted Liang
 
Strategy Pattern
Ted Liang
 
Adapter Pattern
Ted Liang
 
設計模式的解析與活用 -開拓視野
Ted Liang
 
Design pattern intro
Ted Liang
 
物件導向範型
Ted Liang
 
Git簡報
Ted Liang
 

Recently uploaded (20)

PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PPT
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PPTX
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 

Dagger & rxjava & retrofit