From 02f43005ff28dc6969a41b827aaa2efdfb8992eb Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 6 Jun 2022 07:07:19 +0300 Subject: [PATCH] Code refactor --- lib/constants.dart | 2 +- lib/main_app.dart | 6 ++--- lib/ui/app/main_screen.dart | 6 ++--- .../company_gateway_screen.dart | 2 +- ...ne_payments.dart => payment_settings.dart} | 16 +++++++------- ...ments_vm.dart => payment_settings_vm.dart} | 22 +++++++++---------- lib/ui/settings/settings_list.dart | 4 ++-- lib/utils/i18n.dart | 5 +++++ lib/utils/icons.dart | 2 +- 9 files changed, 35 insertions(+), 30 deletions(-) rename lib/ui/settings/{online_payments.dart => payment_settings.dart} (93%) rename lib/ui/settings/{online_payments_vm.dart => payment_settings_vm.dart} (86%) diff --git a/lib/constants.dart b/lib/constants.dart index 4baa905d1..347750948 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -416,7 +416,7 @@ const String kSettingsPaymentTermView = 'payment_term/view'; const String kSettingsPaymentTermEdit = 'payment_term/edit'; const String kSettingsUserDetails = 'user_details'; const String kSettingsLocalization = 'localization'; -const String kSettingsOnlinePayments = 'online_payments'; +const String kSettingsPaymentSettings = 'payment_settings'; const String kSettingsCompanyGateways = 'company_gateways'; const String kSettingsCompanyGatewaysView = 'company_gateways/view'; const String kSettingsCompanyGatewaysEdit = 'company_gateways/edit'; diff --git a/lib/main_app.dart b/lib/main_app.dart index 0a167e8da..537fb20af 100644 --- a/lib/main_app.dart +++ b/lib/main_app.dart @@ -11,6 +11,7 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_styled_toast/flutter_styled_toast.dart'; import 'package:intl/intl.dart'; +import 'package:invoiceninja_flutter/ui/settings/payment_settings_vm.dart'; import 'package:local_auth/local_auth.dart'; import 'package:redux/redux.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; @@ -68,7 +69,6 @@ import 'package:invoiceninja_flutter/ui/reports/reports_screen_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/account_management_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/device_settings_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/expense_settings_vm.dart'; -import 'package:invoiceninja_flutter/ui/settings/online_payments_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/settings_screen_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/task_settings_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/tax_settings_vm.dart'; @@ -565,8 +565,8 @@ class InvoiceNinjaAppState extends State { UserDetailsScreen(), LocalizationScreen.route: (context) => LocalizationScreen(), - OnlinePaymentsScreen.route: (context) => - OnlinePaymentsScreen(), + PaymentsSettingsScreen.route: (context) => + PaymentsSettingsScreen(), CompanyGatewayScreen.route: (context) => CompanyGatewayScreenBuilder(), CompanyGatewayViewScreen.route: (context) => diff --git a/lib/ui/app/main_screen.dart b/lib/ui/app/main_screen.dart index fad60d9e3..f7158b6c0 100644 --- a/lib/ui/app/main_screen.dart +++ b/lib/ui/app/main_screen.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; // Package imports: import 'package:flutter_redux/flutter_redux.dart'; import 'package:invoiceninja_flutter/ui/app/app_title_bar.dart'; +import 'package:invoiceninja_flutter/ui/settings/payment_settings_vm.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart'; import 'package:redux/redux.dart'; @@ -59,7 +60,6 @@ import 'package:invoiceninja_flutter/ui/reports/reports_screen_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/account_management_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/device_settings_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/expense_settings_vm.dart'; -import 'package:invoiceninja_flutter/ui/settings/online_payments_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/settings_screen_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/task_settings_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/tax_settings_vm.dart'; @@ -758,8 +758,8 @@ class SettingsScreens extends StatelessWidget { case kSettingsLocalization: screen = LocalizationScreen(); break; - case kSettingsOnlinePayments: - screen = OnlinePaymentsScreen(); + case kSettingsPaymentSettings: + screen = PaymentsSettingsScreen(); break; case kSettingsCompanyGateways: screen = CompanyGatewayScreenBuilder(); diff --git a/lib/ui/company_gateway/company_gateway_screen.dart b/lib/ui/company_gateway/company_gateway_screen.dart index 6131a8d3a..e7d077e61 100644 --- a/lib/ui/company_gateway/company_gateway_screen.dart +++ b/lib/ui/company_gateway/company_gateway_screen.dart @@ -101,7 +101,7 @@ class CompanyGatewayScreen extends StatelessWidget { store.dispatch(ResetSettings()); } else { store.dispatch( - ViewSettings(section: kSettingsOnlinePayments)); + ViewSettings(section: kSettingsPaymentSettings)); } }, ) diff --git a/lib/ui/settings/online_payments.dart b/lib/ui/settings/payment_settings.dart similarity index 93% rename from lib/ui/settings/online_payments.dart rename to lib/ui/settings/payment_settings.dart index 660deaf13..e0da354c0 100644 --- a/lib/ui/settings/online_payments.dart +++ b/lib/ui/settings/payment_settings.dart @@ -11,25 +11,25 @@ import 'package:invoiceninja_flutter/ui/app/forms/app_dropdown_button.dart'; import 'package:invoiceninja_flutter/ui/app/forms/app_form.dart'; import 'package:invoiceninja_flutter/ui/app/forms/bool_dropdown_button.dart'; import 'package:invoiceninja_flutter/ui/app/forms/decorated_form_field.dart'; -import 'package:invoiceninja_flutter/ui/settings/online_payments_vm.dart'; +import 'package:invoiceninja_flutter/ui/settings/payment_settings_vm.dart'; import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; -class OnlinePayments extends StatefulWidget { - const OnlinePayments({ +class PaymentSettings extends StatefulWidget { + const PaymentSettings({ Key key, @required this.viewModel, }) : super(key: key); - final OnlinePaymentsVM viewModel; + final PaymentSettingsVM viewModel; @override - _OnlinePaymentsState createState() => _OnlinePaymentsState(); + _PaymentSettingsState createState() => _PaymentSettingsState(); } -class _OnlinePaymentsState extends State { +class _PaymentSettingsState extends State { static final GlobalKey _formKey = - GlobalKey(debugLabel: '_onlinePayments'); + GlobalKey(debugLabel: '_paymentSettings'); FocusScopeNode _focusNode; final _minimumAmountController = TextEditingController(); List _controllers = []; @@ -82,7 +82,7 @@ class _OnlinePaymentsState extends State { final settings = viewModel.settings; return EditScaffold( - title: localization.onlinePayments, + title: localization.paymentSettings, onSavePressed: viewModel.onSavePressed, body: AppForm( formKey: _formKey, diff --git a/lib/ui/settings/online_payments_vm.dart b/lib/ui/settings/payment_settings_vm.dart similarity index 86% rename from lib/ui/settings/online_payments_vm.dart rename to lib/ui/settings/payment_settings_vm.dart index 3de8ab0a5..db37c7142 100644 --- a/lib/ui/settings/online_payments_vm.dart +++ b/lib/ui/settings/payment_settings_vm.dart @@ -4,6 +4,7 @@ import 'package:flutter/widgets.dart'; // Package imports: import 'package:flutter_redux/flutter_redux.dart'; +import 'package:invoiceninja_flutter/ui/settings/payment_settings.dart'; import 'package:redux/redux.dart'; // Project imports: @@ -18,20 +19,19 @@ import 'package:invoiceninja_flutter/redux/client/client_actions.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; import 'package:invoiceninja_flutter/redux/group/group_actions.dart'; import 'package:invoiceninja_flutter/redux/settings/settings_actions.dart'; -import 'package:invoiceninja_flutter/ui/settings/online_payments.dart'; import 'package:invoiceninja_flutter/utils/completers.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; -class OnlinePaymentsScreen extends StatelessWidget { - const OnlinePaymentsScreen({Key key}) : super(key: key); - static const String route = '/$kSettings/$kSettingsOnlinePayments'; +class PaymentsSettingsScreen extends StatelessWidget { + const PaymentsSettingsScreen({Key key}) : super(key: key); + static const String route = '/$kSettings/$kSettingsPaymentSettings'; @override Widget build(BuildContext context) { - return StoreConnector( - converter: OnlinePaymentsVM.fromStore, + return StoreConnector( + converter: PaymentSettingsVM.fromStore, builder: (context, viewModel) { - return OnlinePayments( + return PaymentSettings( viewModel: viewModel, key: ValueKey(viewModel.state.settingsUIState.updatedAt), ); @@ -40,8 +40,8 @@ class OnlinePaymentsScreen extends StatelessWidget { } } -class OnlinePaymentsVM { - OnlinePaymentsVM({ +class PaymentSettingsVM { + PaymentSettingsVM({ @required this.state, @required this.company, @required this.onCompanyChanged, @@ -51,10 +51,10 @@ class OnlinePaymentsVM { @required this.onConfigureGatewaysPressed, }); - static OnlinePaymentsVM fromStore(Store store) { + static PaymentSettingsVM fromStore(Store store) { final state = store.state; - return OnlinePaymentsVM( + return PaymentSettingsVM( state: state, company: state.uiState.settingsUIState.company, settings: state.uiState.settingsUIState.settings, diff --git a/lib/ui/settings/settings_list.dart b/lib/ui/settings/settings_list.dart index 9ee007911..3e6ac0234 100644 --- a/lib/ui/settings/settings_list.dart +++ b/lib/ui/settings/settings_list.dart @@ -121,7 +121,7 @@ class _SettingsListState extends State { viewModel: widget.viewModel, ), SettingsListTile( - section: kSettingsOnlinePayments, + section: kSettingsPaymentSettings, viewModel: widget.viewModel, ), SettingsListTile( @@ -375,7 +375,7 @@ class SettingsSearch extends StatelessWidget { 'custom_labels', ], ], - kSettingsOnlinePayments: [ + kSettingsPaymentSettings: [ [ 'company_gateways', 'auto_bill_on', diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 832b9aede..83141c81f 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -16,6 +16,7 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'payment_settings': 'Payment Settings', 'default': 'Default', 'stock_quantity': 'Stock Quantity', 'notification_threshold': 'Notification Threshold', @@ -70583,6 +70584,10 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]['default'] ?? _localizedValues['en']['default']; + String get paymentSettings => + _localizedValues[localeCode]['payment_settings'] ?? + _localizedValues['en']['payment_settings']; + // STARTER: lang field - do not remove comment String lookup(String key) { diff --git a/lib/utils/icons.dart b/lib/utils/icons.dart index 1d59f5096..2324bf241 100644 --- a/lib/utils/icons.dart +++ b/lib/utils/icons.dart @@ -192,7 +192,7 @@ IconData getSettingIcon(String section) { return Icons.person; case kSettingsLocalization: return Icons.language; - case kSettingsOnlinePayments: + case kSettingsPaymentSettings: case kSettingsCompanyGateways: return MdiIcons.creditCard; case kSettingsTaxSettings: