SlideShare a Scribd company logo
1 of 14
Android Getting Started
The UPTech way
What’s on the list?
Basic Libraries
Dependency Injection with Dagger 2
RxAndroid
Custom Views FTW
The Future: Kotlin
Basic Libraries
Butterknife
Retrolambda
REST Trio: Retrofit, OkHttp, Gson
Image Loading: Glide, Fresco
Realm
Dependency Injection with Dagger 2
class ApiService {
public void uploadPhoto(String user, File file) {
OkHttpClient client = new OkHttpClient();
Gson gson = new Gson();
Request request = // TODO build a post request
client.newCall(request).execute();
}
}
Dependency Injection with Dagger 2
class ApiService {
Gson gson = new Gson();
OkHttpClient client = new OkHttpClient()
public void uploadPhoto(String user, File file) {
Request request = // TODO build a post request
client.newCall(request).execute();
}
}
Dependency Injection with Dagger 2
class ApiService {
Gson gson;
OkHttpClient client;
public ApiService(OkHttpClient client, Gson gson) {
this.client = client;
this.gson = gson;
}
public void uploadPhoto(String user, File file) {
Request request = // TODO build a post request
client.newCall(request).execute();
}
}
Dependency Injection with Dagger 2
OkHttpClient client = new OkHttpClient();
Gson gson = new Gson();
ApiService apiService = new ApiService(client, gson);
apiService.uploadPhoto("UPTechTeam", file);
Dependency Injection
OkHttpClient client = new OkHttpClient();
Gson gson = new Gson();
ApiService apiService = new ApiService(client, gson);
RealmConfiguration config = new RealmConfiguration.Builder(context)
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(config);
Realm realm = Realm.getDefaultInstance();
Preferences preferences = new Preferences(context);
AccountManager accountManager = new AccountManager(apiService, database, preferences);
accountManager.getUser();
Dependency Injection
@Inject
AccountManager accountManager;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Application.appComponent().inject(this);
accountManager.getUser()
}
Dependency Injection with Dagger 2
api.registerWithEmail(email, password, new Callback<RegisterResponse>() {
@Override
public void onResponse(Call<RegisterResponse> call, Response<RegisterResponse> response) {
if (response.isSuccess()) {
api.getUser(response.token, new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccess()) {}
database.saveUser()
} else {
showError(...);
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
showError(...);
}
});
} else {
if (ErrorResponse.isAlreadyRegistered(response.getErrorBody())) {
api.login(email, password, new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
preferences.saveToken(response);
api.getUser(response.token, new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
RxAndroid
public Observable<UserInfo> registerAndLogin(String email, String password) {
return apiService.registerWithEmail(new RegisterRequest(email, password))
.flatMap(userInfo -> apiService.signInWithEmail(new SignInRequest(email, password)))
.doOnNext(signInResponse -> preferences.saveAccessToken(signInResponse.accessToken))
.onErrorResumeNext(e -> ErrorResponse.isAlreadyRegistered(e) ? apiService.signInWithEmail(new
SignInRequest(email, password)) : errorObservable(e))
.flatMap(ignore -> getUser())
.doOnNext(user -> database.saveUser(user));
}
RxAndroid
>> Improving UX with RX
RxAndroid
>> Thanks!
UPTech

More Related Content

What's hot

Hidden-Web Induced by Client-Side Scripting: An Empirical Study
Hidden-Web Induced by Client-Side Scripting: An Empirical StudyHidden-Web Induced by Client-Side Scripting: An Empirical Study
Hidden-Web Induced by Client-Side Scripting: An Empirical Study
SALT Lab @ UBC
 
Understanding JavaScript Event-based Interactions
Understanding JavaScript Event-based InteractionsUnderstanding JavaScript Event-based Interactions
Understanding JavaScript Event-based Interactions
SALT Lab @ UBC
 

What's hot (20)

Event-Driven Systems With MongoDB
Event-Driven Systems With MongoDBEvent-Driven Systems With MongoDB
Event-Driven Systems With MongoDB
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
 
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
 
Hidden-Web Induced by Client-Side Scripting: An Empirical Study
Hidden-Web Induced by Client-Side Scripting: An Empirical StudyHidden-Web Induced by Client-Side Scripting: An Empirical Study
Hidden-Web Induced by Client-Side Scripting: An Empirical Study
 
RxSubject And Operators
RxSubject And OperatorsRxSubject And Operators
RxSubject And Operators
 
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
 
Apache Incubator Samza: Stream Processing at LinkedIn
Apache Incubator Samza: Stream Processing at LinkedInApache Incubator Samza: Stream Processing at LinkedIn
Apache Incubator Samza: Stream Processing at LinkedIn
 
iOS Keychain by 흰, 민디
iOS Keychain by 흰, 민디iOS Keychain by 흰, 민디
iOS Keychain by 흰, 민디
 
Understanding JavaScript Event-based Interactions
Understanding JavaScript Event-based InteractionsUnderstanding JavaScript Event-based Interactions
Understanding JavaScript Event-based Interactions
 
Retro vs volley (2)
Retro vs volley (2)Retro vs volley (2)
Retro vs volley (2)
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
 
Integration solution with daxtra resume indexing
Integration solution with daxtra resume indexingIntegration solution with daxtra resume indexing
Integration solution with daxtra resume indexing
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API Documentation
 
Automation in angular js
Automation in angular jsAutomation in angular js
Automation in angular js
 
05 binding and action
05 binding and action05 binding and action
05 binding and action
 
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
 
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
 
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB API
 
Integrando sistemas via OData (caso de estudiio GeneXus-SAP)
Integrando sistemas via OData (caso de estudiio GeneXus-SAP)Integrando sistemas via OData (caso de estudiio GeneXus-SAP)
Integrando sistemas via OData (caso de estudiio GeneXus-SAP)
 

Viewers also liked (6)

Generics. PECS
Generics. PECSGenerics. PECS
Generics. PECS
 
4919_for_Ikoma
4919_for_Ikoma4919_for_Ikoma
4919_for_Ikoma
 
Tuberculosis Pulmonar
Tuberculosis PulmonarTuberculosis Pulmonar
Tuberculosis Pulmonar
 
COLOMBIA NUESTRA TIERRA
COLOMBIA NUESTRA TIERRACOLOMBIA NUESTRA TIERRA
COLOMBIA NUESTRA TIERRA
 
Beer Bottle Night Lamp
Beer Bottle Night LampBeer Bottle Night Lamp
Beer Bottle Night Lamp
 
Clean architecture on Android
Clean architecture on AndroidClean architecture on Android
Clean architecture on Android
 

Similar to Android getting started

可抽換元件設計模式
可抽換元件設計模式可抽換元件設計模式
可抽換元件設計模式
Pete Chen
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice Presentation
Dmitry Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_service
NCCOMMS
 

Similar to Android getting started (20)

可抽換元件設計模式
可抽換元件設計模式可抽換元件設計模式
可抽換元件設計模式
 
Dagger 2 - Injeção de Dependência
Dagger 2 - Injeção de DependênciaDagger 2 - Injeção de Dependência
Dagger 2 - Injeção de Dependência
 
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdfAPI 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice Presentation
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Rapid development tools for java ee 8 [tut2998]
Rapid development tools for java ee 8 [tut2998]Rapid development tools for java ee 8 [tut2998]
Rapid development tools for java ee 8 [tut2998]
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 
Rapid Development Tools for Java EE 8 [TUT2998]
Rapid Development Tools for Java EE 8 [TUT2998]Rapid Development Tools for Java EE 8 [TUT2998]
Rapid Development Tools for Java EE 8 [TUT2998]
 
Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrap
 
Modern Android app library stack
Modern Android app library stackModern Android app library stack
Modern Android app library stack
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_service
 
Android development
Android developmentAndroid development
Android development
 
Retrofit 2 - O que devemos saber
Retrofit 2 - O que devemos saberRetrofit 2 - O que devemos saber
Retrofit 2 - O que devemos saber
 
The lazy programmers guide to consuming web services
The lazy programmers guide to consuming web services The lazy programmers guide to consuming web services
The lazy programmers guide to consuming web services
 

More from Uptech (6)

Android studio 2.2 Tips and Tricks
Android studio 2.2 Tips and TricksAndroid studio 2.2 Tips and Tricks
Android studio 2.2 Tips and Tricks
 
Scrum. A brief introduction
Scrum. A brief introductionScrum. A brief introduction
Scrum. A brief introduction
 
App coordinators in iOS
App coordinators in iOSApp coordinators in iOS
App coordinators in iOS
 
Ruby language overview
Ruby language overviewRuby language overview
Ruby language overview
 
Getting things done intro
Getting things done introGetting things done intro
Getting things done intro
 
Mvp tech talks
Mvp tech talksMvp tech talks
Mvp tech talks
 

Recently uploaded

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 

Android getting started

  • 2. What’s on the list? Basic Libraries Dependency Injection with Dagger 2 RxAndroid Custom Views FTW The Future: Kotlin
  • 3. Basic Libraries Butterknife Retrolambda REST Trio: Retrofit, OkHttp, Gson Image Loading: Glide, Fresco Realm
  • 4. Dependency Injection with Dagger 2 class ApiService { public void uploadPhoto(String user, File file) { OkHttpClient client = new OkHttpClient(); Gson gson = new Gson(); Request request = // TODO build a post request client.newCall(request).execute(); } }
  • 5. Dependency Injection with Dagger 2 class ApiService { Gson gson = new Gson(); OkHttpClient client = new OkHttpClient() public void uploadPhoto(String user, File file) { Request request = // TODO build a post request client.newCall(request).execute(); } }
  • 6. Dependency Injection with Dagger 2 class ApiService { Gson gson; OkHttpClient client; public ApiService(OkHttpClient client, Gson gson) { this.client = client; this.gson = gson; } public void uploadPhoto(String user, File file) { Request request = // TODO build a post request client.newCall(request).execute(); } }
  • 7. Dependency Injection with Dagger 2 OkHttpClient client = new OkHttpClient(); Gson gson = new Gson(); ApiService apiService = new ApiService(client, gson); apiService.uploadPhoto("UPTechTeam", file);
  • 9. OkHttpClient client = new OkHttpClient(); Gson gson = new Gson(); ApiService apiService = new ApiService(client, gson); RealmConfiguration config = new RealmConfiguration.Builder(context) .deleteRealmIfMigrationNeeded() .build(); Realm.setDefaultConfiguration(config); Realm realm = Realm.getDefaultInstance(); Preferences preferences = new Preferences(context); AccountManager accountManager = new AccountManager(apiService, database, preferences); accountManager.getUser(); Dependency Injection
  • 10. @Inject AccountManager accountManager; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); Application.appComponent().inject(this); accountManager.getUser() } Dependency Injection with Dagger 2
  • 11. api.registerWithEmail(email, password, new Callback<RegisterResponse>() { @Override public void onResponse(Call<RegisterResponse> call, Response<RegisterResponse> response) { if (response.isSuccess()) { api.getUser(response.token, new Callback<User>() { @Override public void onResponse(Call<User> call, Response<User> response) { if (response.isSuccess()) {} database.saveUser() } else { showError(...); } } @Override public void onFailure(Call<User> call, Throwable t) { showError(...); } }); } else { if (ErrorResponse.isAlreadyRegistered(response.getErrorBody())) { api.login(email, password, new Callback<LoginResponse>() { @Override public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) { preferences.saveToken(response); api.getUser(response.token, new Callback<User>() { @Override public void onResponse(Call<User> call, Response<User> response) { RxAndroid
  • 12. public Observable<UserInfo> registerAndLogin(String email, String password) { return apiService.registerWithEmail(new RegisterRequest(email, password)) .flatMap(userInfo -> apiService.signInWithEmail(new SignInRequest(email, password))) .doOnNext(signInResponse -> preferences.saveAccessToken(signInResponse.accessToken)) .onErrorResumeNext(e -> ErrorResponse.isAlreadyRegistered(e) ? apiService.signInWithEmail(new SignInRequest(email, password)) : errorObservable(e)) .flatMap(ignore -> getUser()) .doOnNext(user -> database.saveUser(user)); } RxAndroid
  • 13. >> Improving UX with RX RxAndroid