Bulk download

This commit is contained in:
Hillel Coren 2021-06-10 16:09:27 +03:00
parent 37e622ba15
commit dae40b04f7
1 changed files with 6 additions and 64 deletions

View File

@ -1,10 +1,8 @@
import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter_styled_toast/flutter_styled_toast.dart'; import 'package:flutter_styled_toast/flutter_styled_toast.dart';
import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/ui/app/forms/app_dropdown_button.dart'; import 'package:invoiceninja_flutter/ui/app/forms/app_dropdown_button.dart';
import 'package:invoiceninja_flutter/ui/app/forms/bool_dropdown_button.dart'; import 'package:invoiceninja_flutter/ui/app/forms/bool_dropdown_button.dart';
import 'package:invoiceninja_flutter/utils/oauth.dart';
import 'package:invoiceninja_flutter/utils/platforms.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart';
import 'package:qr_flutter/qr_flutter.dart'; import 'package:qr_flutter/qr_flutter.dart';
import 'package:built_collection/built_collection.dart'; import 'package:built_collection/built_collection.dart';
@ -53,13 +51,6 @@ class _UserDetailsState extends State<UserDetails>
TabController _controller; TabController _controller;
bool autoValidate = false; bool autoValidate = false;
static const GMAIL_DEFAULT = 0;
static const GMAIL_1_SIGN_IN = 1;
static const GMAIL_2_AUTHORIZE = 2;
int _connectGmailStep = GMAIL_DEFAULT;
String _password;
final _firstNameController = TextEditingController(); final _firstNameController = TextEditingController();
final _lastNameController = TextEditingController(); final _lastNameController = TextEditingController();
final _phoneController = TextEditingController(); final _phoneController = TextEditingController();
@ -136,49 +127,6 @@ class _UserDetailsState extends State<UserDetails>
} }
} }
void _connectToGmail() {
if (_connectGmailStep == GMAIL_DEFAULT) {
GoogleOAuth.signOut();
passwordCallback(
context: context,
skipOAuth: true,
callback: (password, idToken) async {
setState(() {
_connectGmailStep = GMAIL_1_SIGN_IN;
_password = password;
});
});
} else if (_connectGmailStep == GMAIL_1_SIGN_IN) {
try {
GoogleOAuth.grantOfflineAccess((idToken, accessToken, serverAuthCode) {
if (idToken.isEmpty || accessToken.isEmpty) {
GoogleOAuth.signOut();
setState(() {
_connectGmailStep = GMAIL_1_SIGN_IN;
});
} else {
setState(() {
_connectGmailStep = GMAIL_2_AUTHORIZE;
});
}
}, () {
// TODO Gmail always fails the first time
setState(() {
_connectGmailStep = GMAIL_2_AUTHORIZE;
});
});
} catch (error) {
showErrorDialog(context: context, message: error);
}
} else if (_connectGmailStep == GMAIL_2_AUTHORIZE) {
final completer = Completer<Null>();
completer.future.catchError((Object error) {
showErrorDialog(context: context, message: error);
});
widget.viewModel.onConnectGmailPressed(context, completer, _password);
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final localization = AppLocalization.of(context); final localization = AppLocalization.of(context);
@ -186,15 +134,6 @@ class _UserDetailsState extends State<UserDetails>
final user = viewModel.user; final user = viewModel.user;
final state = viewModel.state; final state = viewModel.state;
String gmailButtonLabel = localization.connectGmail;
if (state.user.isConnectedToGmail) {
gmailButtonLabel = localization.disconnectGmail;
} else if (_connectGmailStep == GMAIL_1_SIGN_IN) {
gmailButtonLabel = localization.step1SignIn;
} else if (_connectGmailStep == GMAIL_2_AUTHORIZE) {
gmailButtonLabel = localization.step2Authorize;
}
return EditScaffold( return EditScaffold(
title: localization.userDetails, title: localization.userDetails,
onSavePressed: (context) { onSavePressed: (context) {
@ -298,8 +237,11 @@ class _UserDetailsState extends State<UserDetails>
SizedBox(width: kTableColumnGap), SizedBox(width: kTableColumnGap),
Expanded( Expanded(
child: OutlinedButton( child: OutlinedButton(
child: Text(gmailButtonLabel.toUpperCase()), child: Text((user.isConnectedToGmail
onPressed: !state.user.isConnectedToGoogle ? localization.disconnectGmail
: localization.connectGmail)
.toUpperCase()),
onPressed: !state.user.isConnectedToGoogle && false
? null ? null
: () async { : () async {
if (state.settingsUIState.isChanged) { if (state.settingsUIState.isChanged) {
@ -313,7 +255,7 @@ class _UserDetailsState extends State<UserDetails>
if (state.user.isConnectedToGmail) { if (state.user.isConnectedToGmail) {
viewModel.onDisconnectGmailPressed(context); viewModel.onDisconnectGmailPressed(context);
} else { } else {
_connectToGmail(); launch('$kAppProductionUrl/auth/google');
} }
}, },
), ),