private bool TestIfGooglePlayServicesIsInstalled() { try { int queryResult = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this); if (queryResult == ConnectionResult.Success) { return(true); } if (GoogleApiAvailability.Instance.IsUserResolvableError(queryResult)) { Dialog errorDialog = GoogleApiAvailability.Instance.GetErrorDialog(this, queryResult, InstallGooglePlayServicesId); if (ErrorDialogFragment != null) { ErrorDialogFragment.Dismiss(); } ErrorDialogFragment = ErrorDialogFragment.NewInstance(errorDialog); ErrorDialogFragment.Cancelable = false; ErrorDialogFragment.Show(FragmentManager, "GooglePlayServicesDialog"); } } catch (Exception e) { ExceptionHandler.Catch(e); } return(false); }
private void ShowAuthError(string email, AuthResult res, bool googleAuth = false) { var dia = new ErrorDialogFragment(res); if (dia != null) { dia.Show(FragmentManager, "auth_result_dialog"); } }
void ShowErrorDialog(int errorCode) { var dialogFragment = new ErrorDialogFragment(); var args = new Bundle(); args.PutInt("dialog_error", errorCode); dialogFragment.Arguments = args; dialogFragment.Show(FragmentManager, "errordialog"); }
private void ShowAuthError(string email, AuthResult res, Mode mode, bool googleAuth = false) { DialogFragment dia = null; switch (res) { case AuthResult.InvalidCredentials: if (mode == Mode.Login && !googleAuth) { dia = new ErrorDialogFragment(LoginError.InvalidCredentials); } else if (mode == Mode.Signup) { dia = new ErrorDialogFragment(LoginError.SignupFailed); } else if (mode == Mode.Login && googleAuth) { dia = new ErrorDialogFragment(LoginError.NoAccount); } break; case AuthResult.NoDefaultWorkspace: dia = new NoWorkspaceDialogFragment(email); break; case AuthResult.NetworkError: dia = new ErrorDialogFragment(LoginError.NetworkError); break; default: dia = new ErrorDialogFragment(LoginError.SystemError); break; } if (dia != null) { dia.Show(FragmentManager, "auth_result_dialog"); } }
private async Task StartAuthAsync() { if (IsAuthenticating) { return; } IsAuthenticating = true; try { var log = ServiceContainer.Resolve <ILogger> (); var authManager = ServiceContainer.Resolve <AuthManager> (); var ctx = Activity; // No point in trying to reauth when old authentication is still running. if (authManager.IsAuthenticating) { return; } // Workaround for Android linker bug which forgets to register JNI types Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/GoogleAuthException", typeof(GoogleAuthException)); Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/GooglePlayServicesAvailabilityException", typeof(GooglePlayServicesAvailabilityException)); Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/UserRecoverableAuthException", typeof(UserRecoverableAuthException)); Java.Interop.TypeManager.RegisterType("com/google/android/gms/auth/UserRecoverableNotifiedException", typeof(UserRecoverableNotifiedException)); String token = null; try { token = await Task.Factory.StartNew(() => GoogleAuthUtil.GetToken(ctx, Email, GoogleOAuthScope)); } catch (GooglePlayServicesAvailabilityException exc) { var dia = GooglePlayServicesUtil.GetErrorDialog( exc.ConnectionStatusCode, ctx, GoogleAuthRequestCode); dia.Show(); } catch (UserRecoverableAuthException exc) { StartActivityForResult(exc.Intent, GoogleAuthRequestCode); } catch (Java.IO.IOException exc) { // Connectivity error.. nothing to do really? log.Info(LogTag, exc, "Failed to login with Google due to network issues."); } catch (Exception exc) { log.Error(LogTag, exc, "Failed to get access token for '{0}'.", Email); } // Failed to get token if (token == null) { return; } try { var authRes = await viewModel.TrySignupGoogleAsync(token); if (authRes != AuthResult.Success) { ClearGoogleToken(ctx, token); var dia = new ErrorDialogFragment(authRes); dia.Show(FragmentManager, "auth_result_dialog"); } } catch (InvalidOperationException ex) { log.Info(LogTag, ex, "Failed to authenticate user with Google login."); } } finally { IsAuthenticating = false; } // Clean up self: if (Activity != null) { FragmentManager.BeginTransaction() .Remove(this) .Commit(); } }
private void ShowAuthError (string email, AuthResult res, Mode mode, bool googleAuth=false) { DialogFragment dia = null; switch (res) { case AuthResult.InvalidCredentials: if (mode == Mode.Login && !googleAuth) { dia = new ErrorDialogFragment (LoginError.InvalidCredentials); } else if (mode == Mode.Signup) { dia = new ErrorDialogFragment (LoginError.SignupFailed); } else if (mode == Mode.Login && googleAuth) { dia = new ErrorDialogFragment (LoginError.NoAccount); } break; case AuthResult.NoDefaultWorkspace: dia = new NoWorkspaceDialogFragment (email); break; case AuthResult.NetworkError: dia = new ErrorDialogFragment (LoginError.NetworkError); break; default: dia = new ErrorDialogFragment (LoginError.SystemError); break; } if (dia != null) { dia.Show (FragmentManager, "auth_result_dialog"); } }
private async Task StartAuthAsync () { if (IsAuthenticating) { return; } IsAuthenticating = true; try { var log = ServiceContainer.Resolve<ILogger> (); var authManager = ServiceContainer.Resolve<AuthManager> (); var ctx = Activity; // No point in trying to reauth when old authentication is still running. if (authManager.IsAuthenticating) { return; } // Workaround for Android linker bug which forgets to register JNI types Java.Interop.TypeManager.RegisterType ("com/google/android/gms/auth/GoogleAuthException", typeof (GoogleAuthException)); Java.Interop.TypeManager.RegisterType ("com/google/android/gms/auth/GooglePlayServicesAvailabilityException", typeof (GooglePlayServicesAvailabilityException)); Java.Interop.TypeManager.RegisterType ("com/google/android/gms/auth/UserRecoverableAuthException", typeof (UserRecoverableAuthException)); Java.Interop.TypeManager.RegisterType ("com/google/android/gms/auth/UserRecoverableNotifiedException", typeof (UserRecoverableNotifiedException)); String token = null; try { token = await Task.Factory.StartNew (() => GoogleAuthUtil.GetToken (ctx, Email, GoogleOAuthScope)); } catch (GooglePlayServicesAvailabilityException exc) { var dia = GooglePlayServicesUtil.GetErrorDialog ( exc.ConnectionStatusCode, ctx, GoogleAuthRequestCode); dia.Show (); } catch (UserRecoverableAuthException exc) { StartActivityForResult (exc.Intent, GoogleAuthRequestCode); } catch (Java.IO.IOException exc) { // Connectivity error.. nothing to do really? log.Info (LogTag, exc, "Failed to login with Google due to network issues."); } catch (Exception exc) { log.Error (LogTag, exc, "Failed to get access token for '{0}'.", Email); } // Failed to get token if (token == null) { return; } try { var authRes = await viewModel.TrySignupGoogleAsync (token); if (authRes != AuthResult.Success) { ClearGoogleToken (ctx, token); var dia = new ErrorDialogFragment (authRes); dia.Show (FragmentManager, "auth_result_dialog"); } } catch (InvalidOperationException ex) { log.Info (LogTag, ex, "Failed to authenticate user with Google login."); } } finally { IsAuthenticating = false; } // Clean up self: if (Activity != null) { FragmentManager.BeginTransaction () .Remove (this) .Commit (); } }
private void ShowAuthError (string email, AuthResult res, bool googleAuth=false) { var dia = new ErrorDialogFragment (res); if (dia != null) { dia.Show (FragmentManager, "auth_result_dialog"); } }