18
18
import android .content .Context ;
19
19
import android .content .Intent ;
20
20
import android .support .annotation .LayoutRes ;
21
- import android .support .annotation .NonNull ;
22
21
import android .support .annotation .Nullable ;
23
22
import android .support .v4 .app .FragmentActivity ;
24
23
import android .text .TextUtils ;
30
29
import com .firebase .ui .auth .R ;
31
30
import com .firebase .ui .auth .data .model .User ;
32
31
import com .firebase .ui .auth .util .ExtraConstants ;
33
- import com .firebase .ui .auth .util .GoogleApiHelper ;
34
32
import com .google .android .gms .auth .api .Auth ;
33
+ import com .google .android .gms .auth .api .signin .GoogleSignIn ;
35
34
import com .google .android .gms .auth .api .signin .GoogleSignInAccount ;
35
+ import com .google .android .gms .auth .api .signin .GoogleSignInClient ;
36
36
import com .google .android .gms .auth .api .signin .GoogleSignInOptions ;
37
37
import com .google .android .gms .auth .api .signin .GoogleSignInResult ;
38
- import com .google .android .gms .common .ConnectionResult ;
39
38
import com .google .android .gms .common .api .CommonStatusCodes ;
40
- import com .google .android .gms .common .api .GoogleApiClient ;
41
39
import com .google .android .gms .common .api .Status ;
42
40
import com .google .firebase .auth .AuthCredential ;
43
41
import com .google .firebase .auth .GoogleAuthProvider ;
44
42
45
- public class GoogleProvider implements IdpProvider , GoogleApiClient . OnConnectionFailedListener {
43
+ public class GoogleProvider implements IdpProvider {
46
44
private static final String TAG = "GoogleProvider" ;
47
45
private static final int RC_SIGN_IN = 20 ;
48
46
49
- private GoogleApiClient mGoogleApiClient ;
47
+ private GoogleSignInClient mSignInClient ;
50
48
private FragmentActivity mActivity ;
51
49
private IdpConfig mIdpConfig ;
52
50
private IdpCallback mIdpCallback ;
@@ -60,10 +58,8 @@ public GoogleProvider(FragmentActivity activity, IdpConfig idpConfig, @Nullable
60
58
mActivity = activity ;
61
59
mIdpConfig = idpConfig ;
62
60
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 ));
67
63
}
68
64
69
65
public static AuthCredential createAuthCredential (IdpResponse response ) {
@@ -98,13 +94,6 @@ public void setAuthenticationCallback(IdpCallback callback) {
98
94
mIdpCallback = callback ;
99
95
}
100
96
101
- public void disconnect () {
102
- if (mGoogleApiClient != null ) {
103
- mGoogleApiClient .disconnect ();
104
- mGoogleApiClient = null ;
105
- }
106
- }
107
-
108
97
private IdpResponse createIdpResponse (GoogleSignInAccount account ) {
109
98
return new IdpResponse .Builder (
110
99
new User .Builder (GoogleAuthProvider .PROVIDER_ID , account .getEmail ())
@@ -141,20 +130,15 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
141
130
142
131
@ Override
143
132
public void startLogin (Activity activity ) {
144
- Intent signInIntent = Auth . GoogleSignInApi . getSignInIntent (mGoogleApiClient );
133
+ Intent signInIntent = mSignInClient . getSignInIntent ();
145
134
activity .startActivityForResult (signInIntent , RC_SIGN_IN );
146
135
}
147
136
148
137
private void onError (GoogleSignInResult result ) {
149
138
Status status = result .getStatus ();
150
139
151
140
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 ));
158
142
startLogin (mActivity );
159
143
} else {
160
144
if (status .getStatusCode () == CommonStatusCodes .DEVELOPER_ERROR ) {
@@ -170,10 +154,5 @@ private void onError(String errorMessage) {
170
154
Log .e (TAG , "Error logging in with Google. " + errorMessage );
171
155
mIdpCallback .onFailure ();
172
156
}
173
-
174
- @ Override
175
- public void onConnectionFailed (@ NonNull ConnectionResult connectionResult ) {
176
- Log .w (TAG , "onConnectionFailed:" + connectionResult );
177
- }
178
157
}
179
158
0 commit comments