1818import android .content .Context ;
1919import android .content .Intent ;
2020import android .support .annotation .LayoutRes ;
21- import android .support .annotation .NonNull ;
2221import android .support .annotation .Nullable ;
2322import android .support .v4 .app .FragmentActivity ;
2423import android .text .TextUtils ;
3029import com .firebase .ui .auth .R ;
3130import com .firebase .ui .auth .data .model .User ;
3231import com .firebase .ui .auth .util .ExtraConstants ;
33- import com .firebase .ui .auth .util .GoogleApiHelper ;
3432import com .google .android .gms .auth .api .Auth ;
33+ import com .google .android .gms .auth .api .signin .GoogleSignIn ;
3534import com .google .android .gms .auth .api .signin .GoogleSignInAccount ;
35+ import com .google .android .gms .auth .api .signin .GoogleSignInClient ;
3636import com .google .android .gms .auth .api .signin .GoogleSignInOptions ;
3737import com .google .android .gms .auth .api .signin .GoogleSignInResult ;
38- import com .google .android .gms .common .ConnectionResult ;
3938import com .google .android .gms .common .api .CommonStatusCodes ;
40- import com .google .android .gms .common .api .GoogleApiClient ;
4139import com .google .android .gms .common .api .Status ;
4240import com .google .firebase .auth .AuthCredential ;
4341import com .google .firebase .auth .GoogleAuthProvider ;
4442
45- public class GoogleProvider implements IdpProvider , GoogleApiClient . OnConnectionFailedListener {
43+ public class GoogleProvider implements IdpProvider {
4644 private static final String TAG = "GoogleProvider" ;
4745 private static final int RC_SIGN_IN = 20 ;
4846
49- private GoogleApiClient mGoogleApiClient ;
47+ private GoogleSignInClient mSignInClient ;
5048 private FragmentActivity mActivity ;
5149 private IdpConfig mIdpConfig ;
5250 private IdpCallback mIdpCallback ;
@@ -60,10 +58,8 @@ public GoogleProvider(FragmentActivity activity, IdpConfig idpConfig, @Nullable
6058 mActivity = activity ;
6159 mIdpConfig = idpConfig ;
6260 mSpecificAccount = !TextUtils .isEmpty (email );
63- mGoogleApiClient = new GoogleApiClient .Builder (mActivity )
64- .enableAutoManage (mActivity , GoogleApiHelper .getSafeAutoManageId (), this )
65- .addApi (Auth .GOOGLE_SIGN_IN_API , getSignInOptions (email ))
66- .build ();
61+
62+ mSignInClient = GoogleSignIn .getClient (mActivity , getSignInOptions (email ));
6763 }
6864
6965 public static AuthCredential createAuthCredential (IdpResponse response ) {
@@ -98,13 +94,6 @@ public void setAuthenticationCallback(IdpCallback callback) {
9894 mIdpCallback = callback ;
9995 }
10096
101- public void disconnect () {
102- if (mGoogleApiClient != null ) {
103- mGoogleApiClient .disconnect ();
104- mGoogleApiClient = null ;
105- }
106- }
107-
10897 private IdpResponse createIdpResponse (GoogleSignInAccount account ) {
10998 return new IdpResponse .Builder (
11099 new User .Builder (GoogleAuthProvider .PROVIDER_ID , account .getEmail ())
@@ -141,20 +130,15 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
141130
142131 @ Override
143132 public void startLogin (Activity activity ) {
144- Intent signInIntent = Auth . GoogleSignInApi . getSignInIntent (mGoogleApiClient );
133+ Intent signInIntent = mSignInClient . getSignInIntent ();
145134 activity .startActivityForResult (signInIntent , RC_SIGN_IN );
146135 }
147136
148137 private void onError (GoogleSignInResult result ) {
149138 Status status = result .getStatus ();
150139
151140 if (status .getStatusCode () == CommonStatusCodes .INVALID_ACCOUNT ) {
152- mGoogleApiClient .stopAutoManage (mActivity );
153- mGoogleApiClient .disconnect ();
154- mGoogleApiClient = new GoogleApiClient .Builder (mActivity )
155- .enableAutoManage (mActivity , GoogleApiHelper .getSafeAutoManageId (), this )
156- .addApi (Auth .GOOGLE_SIGN_IN_API , getSignInOptions (null ))
157- .build ();
141+ mSignInClient = GoogleSignIn .getClient (mActivity , getSignInOptions (null ));
158142 startLogin (mActivity );
159143 } else {
160144 if (status .getStatusCode () == CommonStatusCodes .DEVELOPER_ERROR ) {
@@ -170,10 +154,5 @@ private void onError(String errorMessage) {
170154 Log .e (TAG , "Error logging in with Google. " + errorMessage );
171155 mIdpCallback .onFailure ();
172156 }
173-
174- @ Override
175- public void onConnectionFailed (@ NonNull ConnectionResult connectionResult ) {
176- Log .w (TAG , "onConnectionFailed:" + connectionResult );
177- }
178157}
179158
0 commit comments