3030
3131public 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}
0 commit comments