Click here to load reader

Dagger & rxjava & retrofit

  • View

  • Download

Embed Size (px)


about using android third party library Dagger, Rxjava, Retrofit

Text of Dagger & rxjava & retrofit

  • 1. Dagger & RxJava &RetrofitTed

2. what is DaggerDagger is a Dependency Injector 3. example1public class School {public Teacher teacher = new Teacher();} 4. Cons? school teachersetter schoolteacher how to test? 5. example2public class School {public Teacher teacher ;public void setTeacher(Teacher t){teacher = t;}} 6. Pros now we can set whoever we want. and easy to test 7. TestSamples = new Schoole();s.setTeacher(new MockTeacher());assert.equals(s.getTeacherName(),balabala); 8. to use dagger source (Module) target (class) 9. Source (Module)create a @Moduletell the module you are going to @Inject towhich [email protected] a type to that class 10. Target(class)@Inject the Modules to classauto @Inject to field or get type by code 11. example1demo and explain = feature/simpleDagger 12. example2demo and explain = feature/plusIfNecessary 13. whats the meaning of plus?AppGraphNetworkModulesAccountModules 14. whats the meaning of plus?AppGraphNetworkModulesAccountModulesLoginGraphLoginHelperModulesUserLogin App + Login Graph 15. whats the meaning of plus?UserLogoutAppGraphNetworkModulesAccountModules 16. what about testoverride 17. example3 = feature/testTeacher 18. RxjavaFuntional Programing 19. forEachrx.Observable.from("1","2","3").forEach(new Action1() {@Overridepublic void call(String s) {Log.d("Ted","s "+s);}});s 1s 2s 3 20. maprx.Observable.from("1","2","3").map(new Func1() {@Overridepublic Boolean call(String s) {return s.equals("1");}}).subscribe(new Action1() {@Overridepublic void call(Object o) {Log.d("Ted","o "+o);}});o trueo falseo false 21. flapMaprx.Observable.from("1","2","3").flatMap(new Func1 call(String s) {Log.d("Ted","num "+s);return rx.Observable.from(s);}}).subscribe(new Action1() {@Overridepublic void call(Object o) {}});num 1num 2num 3 22. filterrx.Observable.from("1","2","3").filter(new Func1() {@Overridepublic Boolean call(String s) {return s.equals("1");}}).subscribe(new Action1() {@Overridepublic void call(String s) {Log.d("Ted","s "+s);}});s 1 23. toSortedListrx.Observable.from("1","3","2").toSortedList(new Func2() {@Overridepublic Integer call(String s, String s2) {return Integer.valueOf(s2) - Integer.valueOf(s);}}).subscribe(new Action1() {@Overridepublic void call(List strings) {for(String s :strings){Log.d("Ted","s "+s);}}});s 3s 2s 1 24. groupbyfalse integer 1 false integer 3true integer 2 true integer 2 false integer 3false integer 5 true integer 6 false integer 7true integer 8 false integer 9 25. Observable.just vs Observable.from? 26. without publish + connectD s url1D s url2D s url3D s2 url1D s2 url2D s2 url3 27. publish + connectD s url1D s2 url1D s url2D s2 url2D s url3D s2 url3 28. refcountXD 29. Pros & ConsProslogic will be clearConshigh leaning curvelots of callback(with retrolamda maybe better) 30. Ingram 31. 32. .. 33. again 34. XDrxjavaliblearning curve.but api + data handle or data combining...( ) 35. Retrofitthree steps1. create interface2. create api3. handleData 36. retrofit1. build in gson2. no need to implement parcelable3. easy to test 37. test 38. test more with gradle + daggerrandy: XXXListView.get(url) ; layout? 39. ex : adapter view 40. so what can we do with these libDemo Time again 41. Conclusion use Retrofit to handle Network api use dagger to injection every retrofitsadapter(so we can mock the api data) use rxjava to handle every event includingapi call back(so our logic will be clearly)