public class GoogleLoginImpl
{
static String TAG = "GoogleLoginImpl";
private Context context = null;
private GoogleApiClient googleApiClient = null;
private GoogleSignInOptions googleSignInOptions = null;
private GoogleSignInAccount googleSignInAccount = null;
public GoogleLoginImpl(Context cxt, int id)
{
context = cxt;
googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
if(googleApiClient == null)
{
initGoogleApiClient(id);
}
}
private void initGoogleApiClient(int id)
{
googleApiClient = new GoogleApiClient.Builder(context)
.enableAutoManage((FragmentActivity)context,id, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.e(TAG, "Connection failed : " + connectionResult.getErrorMessage());
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build();
googleApiClient.connect();
}
public GoogleApiClient getGoogleApiClient()
{
return googleApiClient;
}
public GoogleSignInAccount getGoogleSignInAccount()
{
return googleSignInAccount;
}
public void setGoogleSignInAccount(GoogleSignInAccount googleSignInAccount)
{
this.googleSignInAccount = googleSignInAccount;
}
}
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(googleLogin.getGoogleApiClient());
if(opr.isDone())
{
googleLogin.setGoogleSignInAccount(opr.get().getSignInAccount());
updateUILogin(true);
}