Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 00c2564

Browse files
author
Irvine Sunday
committed
Code refactoring
1 parent b05531f commit 00c2564

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

app/src/main/java/com/microsoft/graph/connect/GraphServiceClientManager.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public class GraphServiceClientManager extends Application implements IAuthentic
2727
private static GraphServiceClientManager INSTANCE;
2828
private AuthenticationManager mAuthenticationManager;
2929
private static Activity connectActivity;
30+
private MSALAuthenticationProvider msalAuthenticationProvider;
31+
private IGraphServiceClient graphClient;
32+
3033

3134
public static GraphServiceClientManager getApp() {
3235
return INSTANCE;
@@ -77,17 +80,20 @@ public synchronized IGraphServiceClient getGraphServiceClient() {
7780

7881
public synchronized IGraphServiceClient getGraphServiceClient(IAuthenticationProvider authenticationProvider) {
7982
if (mGraphServiceClient == null) {
80-
MSALAuthenticationProvider msalAuthenticationProvider = new MSALAuthenticationProvider(
81-
getAppActivity(),
82-
GraphServiceClientManager.getApp(),
83-
mAuthenticationManager.getPublicClient(),
84-
Constants.SCOPES);
85-
86-
IGraphServiceClient graphClient =
87-
GraphServiceClient
88-
.builder()
89-
.authenticationProvider(msalAuthenticationProvider)
90-
.buildClient();
83+
if(msalAuthenticationProvider == null){
84+
msalAuthenticationProvider = new MSALAuthenticationProvider(
85+
getAppActivity(),
86+
GraphServiceClientManager.getApp(),
87+
mAuthenticationManager.getPublicClient(),
88+
Constants.SCOPES);
89+
}
90+
if(graphClient == null){
91+
graphClient =
92+
GraphServiceClient
93+
.builder()
94+
.authenticationProvider(msalAuthenticationProvider)
95+
.buildClient();
96+
}
9197
return graphClient;
9298
}
9399
return mGraphServiceClient;

0 commit comments

Comments
 (0)