30
30
31
31
public class SignInActivity
32
32
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
+ };
34
62
35
63
@ Override
36
64
protected void onCreate (Bundle savedInstanceState ) {
37
65
super .onCreate (savedInstanceState );
38
66
setContentView (R .layout .activity_signin );
39
67
if (User .isOrg ()) {
40
68
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 ;
41
74
}
42
75
ButterKnife .inject (this );
43
76
}
@@ -92,7 +125,7 @@ public void onSignInMsaClicked() {
92
125
private void authenticateMsa () {
93
126
try {
94
127
validateMsaArgs ();
95
- mLiveAuthClient .login (this , sSCOPES , this );
128
+ mLiveAuthClient .login (this , sSCOPES , mLiveAuthListener );
96
129
} catch (IllegalArgumentException e ) {
97
130
warnBadClient ();
98
131
}
@@ -106,12 +139,12 @@ private void validateMsaArgs() throws IllegalArgumentException {
106
139
107
140
@ Override
108
141
public void onSuccess (AuthenticationResult authenticationResult ) {
109
- finish ();
110
142
SharedPrefsUtil .persistAuthToken (authenticationResult );
111
143
start ();
112
144
}
113
145
114
146
private void start () {
147
+ finish ();
115
148
Intent appLaunch = new Intent (this , SnippetListActivity .class );
116
149
startActivity (appLaunch );
117
150
}
@@ -125,29 +158,4 @@ public void onError(Exception e) {
125
158
}
126
159
Toast .makeText (this , msg , Toast .LENGTH_SHORT ).show ();
127
160
}
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
- }
153
161
}
0 commit comments