From 50fe5e51aa699f583373f364b0ff0e84f7d33bad Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 13 May 2021 14:58:42 +0300 Subject: [PATCH] Gmail --- lib/ui/settings/user_details.dart | 23 +++++++---------------- lib/ui/settings/user_details_vm.dart | 2 +- lib/utils/i18n.dart | 13 ++++--------- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/lib/ui/settings/user_details.dart b/lib/ui/settings/user_details.dart index cd5f60325..28e45f6cf 100644 --- a/lib/ui/settings/user_details.dart +++ b/lib/ui/settings/user_details.dart @@ -53,8 +53,7 @@ class _UserDetailsState extends State static const GMAIL_DEFAULT = 0; static const GMAIL_1_SIGN_IN = 1; - static const GMAIL_2_REQUEST_SCOPE = 2; - static const GMAIL_3_AUTHORIZE_OFFLINE = 4; + static const GMAIL_2_AUTHORIZE = 2; int _connectGmailStep = GMAIL_DEFAULT; String _password; @@ -150,23 +149,17 @@ class _UserDetailsState extends State }); } else if (_connectGmailStep == GMAIL_1_SIGN_IN) { print('## STEP 1'); - GoogleOAuth.signIn((idToken, accessToken) { - print('## $idToken, $accessToken'); + GoogleOAuth.grantOfflineAccess((idToken, accessToken, serverAuthCode) { + print('## id: $idToken, acces: $accessToken, auth: $serverAuthCode'); if (idToken.isEmpty || accessToken.isEmpty) { GoogleOAuth.signOut(); } else { setState(() { - _connectGmailStep = GMAIL_2_REQUEST_SCOPE; + _connectGmailStep = GMAIL_2_AUTHORIZE; }); } }); - } else if (_connectGmailStep == GMAIL_2_REQUEST_SCOPE) { - print('## STEP 2'); - GoogleOAuth.requestGmailScope(); - setState(() { - _connectGmailStep = GMAIL_3_AUTHORIZE_OFFLINE; - }); - } else if (_connectGmailStep == GMAIL_3_AUTHORIZE_OFFLINE) { + } else if (_connectGmailStep == GMAIL_2_AUTHORIZE) { print('## STEP 3'); final completer = Completer(); completer.future.catchError((Object error) { @@ -189,10 +182,8 @@ class _UserDetailsState extends State gmailButtonLabel = localization.disconnectGmail; } else if (_connectGmailStep == GMAIL_1_SIGN_IN) { gmailButtonLabel = localization.step1SignIn; - } else if (_connectGmailStep == GMAIL_2_REQUEST_SCOPE) { - gmailButtonLabel = localization.step2RequestScope; - } else if (_connectGmailStep == GMAIL_3_AUTHORIZE_OFFLINE) { - gmailButtonLabel = localization.step3AuthorizeOffline; + } else if (_connectGmailStep == GMAIL_2_AUTHORIZE) { + gmailButtonLabel = localization.step2Authorize; } return EditScaffold( diff --git a/lib/ui/settings/user_details_vm.dart b/lib/ui/settings/user_details_vm.dart index 270dcbc1b..2bb99f025 100644 --- a/lib/ui/settings/user_details_vm.dart +++ b/lib/ui/settings/user_details_vm.dart @@ -61,7 +61,7 @@ class UserDetailsVM { final signedIn = await GoogleOAuth.grantOfflineAccess( (idToken, accessToken, serverAuthCode) { print( - '## onConnectGmailPressed: 3 $idToken, $accessToken, $serverAuthCode'); + '## id: $idToken, acces: $accessToken, auth: $serverAuthCode'); if (idToken.isEmpty || accessToken.isEmpty || diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index c949d8e53..ed779c25a 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -16,8 +16,7 @@ mixin LocalizationsProvider on LocaleCodeAware { 'en': { // STARTER: lang key - do not remove comment 'step_1_sign_in': 'Step 1: Sign In', - 'step_2_request_scope': 'Step 2: Request Scope', - 'step_3_authorize_offline': 'Step 3: Authorize', + 'step_2_authorize': 'Step 3: Authorize', 'account_id': 'Account ID', 'migration_not_yet_completed': 'The migration has not yet completed', 'wizard_warning': @@ -60365,13 +60364,9 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]['step_1_sign_in'] ?? _localizedValues['en']['step_1_sign_in']; - String get step2RequestScope => - _localizedValues[localeCode]['step_2_request_scope'] ?? - _localizedValues['en']['step_2_request_scope']; - - String get step3AuthorizeOffline => - _localizedValues[localeCode]['step_3_authorize_offline'] ?? - _localizedValues['en']['step_3_authorize_offline']; + String get step2Authorize => + _localizedValues[localeCode]['step_2_authorize'] ?? + _localizedValues['en']['step_2_authorize']; String lookup(String key) { final lookupKey = toSnakeCase(key);