Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 1eb121a

Browse files
author
Brian Melton
committed
Bugfix for Activity 'doubling'. This change also addresses #7
1 parent 81e64ff commit 1eb121a

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

app/src/main/java/com/microsoft/o365_android_onenote_rest/SignInActivity.java

+36-28
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,47 @@
3030

3131
public class SignInActivity
3232
extends BaseActivity
33-
implements AuthenticationCallback<AuthenticationResult>, LiveAuthListener {
33+
implements AuthenticationCallback<AuthenticationResult> {
34+
35+
protected final LiveAuthListener mLiveAuthListener = new LiveAuthListener() {
36+
37+
@Override
38+
public void onAuthComplete(final LiveStatus status,
39+
final LiveConnectSession session,
40+
final Object userState) {
41+
Timber.d("MSA: Auth Complete...");
42+
if (null != status) {
43+
Timber.d(status.toString());
44+
}
45+
if (null != session) {
46+
Timber.d(session.toString());
47+
SharedPrefsUtil.persistAuthToken(session);
48+
}
49+
if (null != userState) {
50+
Timber.d(userState.toString());
51+
}
52+
if (status == LiveStatus.CONNECTED) {
53+
start();
54+
}
55+
}
56+
57+
@Override
58+
public void onAuthError(LiveAuthException exception, Object userState) {
59+
exception.printStackTrace();
60+
}
61+
};
3462

3563
@Override
3664
protected void onCreate(Bundle savedInstanceState) {
3765
super.onCreate(savedInstanceState);
3866
setContentView(R.layout.activity_signin);
3967
if (User.isOrg()) {
4068
mAuthenticationManager.connect(this);
69+
} else if (User.isMsa()
70+
// this check has side effects: see mLiveAuthListener implementation
71+
&& mLiveAuthClient.loginSilent(mLiveAuthListener)) {
72+
// callback will be fired, do not inject ButterKnife
73+
return;
4174
}
4275
ButterKnife.inject(this);
4376
}
@@ -92,7 +125,7 @@ public void onSignInMsaClicked() {
92125
private void authenticateMsa() {
93126
try {
94127
validateMsaArgs();
95-
mLiveAuthClient.login(this, sSCOPES, this);
128+
mLiveAuthClient.login(this, sSCOPES, mLiveAuthListener);
96129
} catch (IllegalArgumentException e) {
97130
warnBadClient();
98131
}
@@ -106,12 +139,12 @@ private void validateMsaArgs() throws IllegalArgumentException {
106139

107140
@Override
108141
public void onSuccess(AuthenticationResult authenticationResult) {
109-
finish();
110142
SharedPrefsUtil.persistAuthToken(authenticationResult);
111143
start();
112144
}
113145

114146
private void start() {
147+
finish();
115148
Intent appLaunch = new Intent(this, SnippetListActivity.class);
116149
startActivity(appLaunch);
117150
}
@@ -125,29 +158,4 @@ public void onError(Exception e) {
125158
}
126159
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
127160
}
128-
129-
@Override
130-
public void onAuthComplete(final LiveStatus status,
131-
final LiveConnectSession session,
132-
final Object userState) {
133-
Timber.d("MSA: Auth Complete...");
134-
if (null != status) {
135-
Timber.d(status.toString());
136-
}
137-
if (null != session) {
138-
Timber.d(session.toString());
139-
SharedPrefsUtil.persistAuthToken(session);
140-
}
141-
if (null != userState) {
142-
Timber.d(userState.toString());
143-
}
144-
if (status == LiveStatus.CONNECTED) {
145-
start();
146-
}
147-
}
148-
149-
@Override
150-
public void onAuthError(LiveAuthException exception, Object userState) {
151-
exception.printStackTrace();
152-
}
153161
}

app/src/main/java/com/microsoft/o365_android_onenote_rest/SnippetListFragment.java

+2
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,6 @@ private void setActivatedPosition(int position) {
125125

126126
mActivatedPosition = position;
127127
}
128+
129+
128130
}

app/src/main/java/com/microsoft/o365_android_onenote_rest/inject/AppModule.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.content.Context;
88
import android.content.SharedPreferences;
99

10+
import com.microsoft.o365_android_onenote_rest.BaseActivity;
1011
import com.microsoft.o365_android_onenote_rest.application.SnippetApp;
1112
import com.microsoft.o365_android_onenote_rest.conf.ServiceConstants;
1213
import com.microsoft.o365_android_onenote_rest.util.SharedPrefsUtil;
@@ -67,6 +68,10 @@ public void intercept(RequestFacade request) {
6768
@Provides
6869
@Singleton
6970
public LiveAuthClient providesLiveAuthClient() {
70-
return new LiveAuthClient(SnippetApp.getApp(), ServiceConstants.MSA_CLIENT_ID);
71+
return new LiveAuthClient(
72+
SnippetApp.getApp(),
73+
ServiceConstants.MSA_CLIENT_ID,
74+
BaseActivity.sSCOPES
75+
);
7176
}
7277
}

0 commit comments

Comments
 (0)