SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
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
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)

Contenu connexe

Tendances

オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 

Tendances (20)

서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189
 
Taking advantage of Prometheus relabeling
Taking advantage of Prometheus relabelingTaking advantage of Prometheus relabeling
Taking advantage of Prometheus relabeling
 
Reactive Programming no Android
Reactive Programming no AndroidReactive Programming no Android
Reactive Programming no Android
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
 
Reactive Programming on Android
Reactive Programming on AndroidReactive Programming on Android
Reactive Programming on Android
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
Apache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API BasicsApache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API Basics
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
 
The Ring programming language version 1.5.4 book - Part 26 of 185
The Ring programming language version 1.5.4 book - Part 26 of 185The Ring programming language version 1.5.4 book - Part 26 of 185
The Ring programming language version 1.5.4 book - Part 26 of 185
 
The Ring programming language version 1.5.2 book - Part 25 of 181
The Ring programming language version 1.5.2 book - Part 25 of 181The Ring programming language version 1.5.2 book - Part 25 of 181
The Ring programming language version 1.5.2 book - Part 25 of 181
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
The Ring programming language version 1.5.2 book - Part 13 of 181
The Ring programming language version 1.5.2 book - Part 13 of 181The Ring programming language version 1.5.2 book - Part 13 of 181
The Ring programming language version 1.5.2 book - Part 13 of 181
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
bluespec talk
bluespec talkbluespec talk
bluespec talk
 
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coinsoft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
 
Deep Dumpster Diving
Deep Dumpster DivingDeep Dumpster Diving
Deep Dumpster Diving
 

En vedette

En vedette (13)

RxJava+RxAndroid (Lecture 20 – rx java)
RxJava+RxAndroid (Lecture 20 – rx java)RxJava+RxAndroid (Lecture 20 – rx java)
RxJava+RxAndroid (Lecture 20 – rx java)
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
RxJava + Retrofit
RxJava + RetrofitRxJava + Retrofit
RxJava + Retrofit
 
Rx java x retrofit
Rx java x retrofitRx java x retrofit
Rx java x retrofit
 
Retrofit Android by Chris Ollenburg
Retrofit Android by Chris OllenburgRetrofit Android by Chris Ollenburg
Retrofit Android by Chris Ollenburg
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
 
Retrofit
RetrofitRetrofit
Retrofit
 
Introduction to rx java for android
Introduction to rx java for androidIntroduction to rx java for android
Introduction to rx java for android
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJava
 
Realm: Building a mobile database
Realm: Building a mobile databaseRealm: Building a mobile database
Realm: Building a mobile database
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
Retrofitting
RetrofittingRetrofitting
Retrofitting
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging Challenges
 

Similaire à Dagger & rxjava & retrofit

Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
Sri Prasanna
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
Ray Toal
 

Similaire à Dagger & rxjava & retrofit (20)

Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
C++ aptitude
C++ aptitudeC++ aptitude
C++ aptitude
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and Reagent
 
Generics
GenericsGenerics
Generics
 
PostgreSQL Open SV 2018
PostgreSQL Open SV 2018PostgreSQL Open SV 2018
PostgreSQL Open SV 2018
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
 
1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii
 
Classes and Inheritance
Classes and InheritanceClasses and Inheritance
Classes and Inheritance
 
Java puzzles
Java puzzlesJava puzzles
Java puzzles
 
The Ring programming language version 1.2 book - Part 78 of 84
The Ring programming language version 1.2 book - Part 78 of 84The Ring programming language version 1.2 book - Part 78 of 84
The Ring programming language version 1.2 book - Part 78 of 84
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
Jeop game-final-review
Jeop game-final-reviewJeop game-final-review
Jeop game-final-review
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
 
Dart London hackathon
Dart  London hackathonDart  London hackathon
Dart London hackathon
 

Plus de Ted Liang (12)

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

Dernier

Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Dernier (20)

(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 

Dagger & rxjava & retrofit