Esempio n. 1
0
            public static ErrorDialogFragment Create(int errorCode, int requestCode)
            {
                ErrorDialogFragment fragment = new ErrorDialogFragment();

                fragment.SetArguments(CreateArguments(errorCode, requestCode));
                return(fragment);
            }
        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);
        }
        protected bool ReadyToGo()
        {
            int status = GooglePlayServicesUtil.IsGooglePlayServicesAvailable(this);

            if (status == ConnectionResult.Success)
            {
                if (GetVersionFromPackageManager(this) >= 2)
                {
                    return(true);
                }
                else
                {
                    Toast.MakeText(this, Resource.String.no_maps, ToastLength.Long).Show();
                    Finish();
                }
            }
            else if (GooglePlayServicesUtil.IsUserRecoverableError(status))
            {
                ErrorDialogFragment e = new ErrorDialogFragment();

                e.NewInstance(status).Show(FragmentManager, TAG_ERROR_DIALOG_FRAGMENT);
            }
            else
            {
                Toast.MakeText(this, Resource.String.no_maps, ToastLength.Long).Show();
                Finish();
            }

            return(false);
        }
Esempio n. 4
0
        private void ShowAuthError(string email, AuthResult res, bool googleAuth = false)
        {
            var dia = new ErrorDialogFragment(res);

            if (dia != null)
            {
                dia.Show(FragmentManager, "auth_result_dialog");
            }
        }
Esempio n. 5
0
        void ShowErrorDialog(int errorCode)
        {
            var dialogFragment = new ErrorDialogFragment();
            var args           = new Bundle();

            args.PutInt("dialog_error", errorCode);
            dialogFragment.Arguments = args;
            dialogFragment.Show(FragmentManager, "errordialog");
        }
            public ErrorDialogFragment NewInstance(int status)
            {
                Bundle args = new Bundle();

                args.PutInt(ARG_STATUS, status);

                ErrorDialogFragment result = new ErrorDialogFragment();

                result.Arguments = args;

                return(result);
            }
Esempio n. 7
0
        // Perform resolution given a non-null result.
        private void resolveLastResult()
        {
            if (GooglePlayServicesUtil.IsUserRecoverableError(mLastConnectionResult.GetErrorCode()))
            {
                // Show a dialog to install or enable Google Play services.
                showErrorDialog(ErrorDialogFragment.Create(mLastConnectionResult.GetErrorCode(),
                                                           mRequestCode));
                return;
            }

            if (mLastConnectionResult.HasResolution())
            {
                startResolution();
            }
        }
Esempio n. 8
0
        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");
            }
        }
Esempio n. 9
0
            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();
                }
            }
Esempio n. 10
0
 public void ShowError(String errorMessage)
 {
     Android.Support.V4.App.DialogFragment fragment = ErrorDialogFragment.NewInstance(
         Resource.String.validationErrors, errorMessage);
     fragment.Show(mFragmentManager, "error");
 }
Esempio n. 11
0
        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");
            }
        }
Esempio n. 12
0
            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 ();
                }
            }
Esempio n. 13
0
        private void ShowAuthError (string email, AuthResult res, bool googleAuth=false)
        {
            var dia = new ErrorDialogFragment (res);

            if (dia != null) {
                dia.Show (FragmentManager, "auth_result_dialog");
            }
        }
 public static ErrorDialogFragment Create(int errorCode, int requestCode)
 {
    ErrorDialogFragment fragment = new ErrorDialogFragment();
    fragment.SetArguments(CreateArguments(errorCode, requestCode));
    return fragment;
 }