From 971abbf2938c7db2d22530a10a9c47ce60936f17 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 1 Dec 2021 18:32:10 +0200 Subject: [PATCH] Feature request: Turn off PDF / HTML invoice preview #361 --- lib/redux/app/app_actions.dart | 2 ++ lib/redux/ui/pref_state.dart | 4 +++ lib/redux/ui/pref_state.g.dart | 39 +++++++++++++++++++------ lib/ui/settings/device_settings.dart | 17 +++++++++-- lib/ui/settings/device_settings_vm.dart | 5 ++++ lib/utils/i18n.dart | 5 ++++ 6 files changed, 60 insertions(+), 12 deletions(-) diff --git a/lib/redux/app/app_actions.dart b/lib/redux/app/app_actions.dart index 219aaab37..58dda9379 100644 --- a/lib/redux/app/app_actions.dart +++ b/lib/redux/app/app_actions.dart @@ -148,6 +148,7 @@ class UpdateUserPreferences implements PersistPrefs { this.persistData, this.persistUi, this.tapSelectedToEdit, + this.showPdfPreview, }); final AppLayout appLayout; @@ -167,6 +168,7 @@ class UpdateUserPreferences implements PersistPrefs { final bool persistData; final bool persistUi; final bool tapSelectedToEdit; + final bool showPdfPreview; final BuiltMap customColors; } diff --git a/lib/redux/ui/pref_state.dart b/lib/redux/ui/pref_state.dart index 6f2343da7..9ecd46a49 100644 --- a/lib/redux/ui/pref_state.dart +++ b/lib/redux/ui/pref_state.dart @@ -33,6 +33,7 @@ abstract class PrefState implements Built { tapSelectedToEdit: false, hideDesktopWarning: false, showKanban: false, + showPdfPreview: true, persistData: false, persistUI: true, companyPrefs: BuiltMap(), @@ -98,6 +99,8 @@ abstract class PrefState implements Built { bool get showKanban; + bool get showPdfPreview; + bool get isHistoryVisible; bool get enableDarkMode; @@ -186,6 +189,7 @@ abstract class PrefState implements Built { ..tapSelectedToEdit = false ..persistData = false ..persistUI = true + ..showPdfPreview = true ..colorTheme = builder.enableDarkMode == true ? kColorThemeLight : kColorThemeLight; diff --git a/lib/redux/ui/pref_state.g.dart b/lib/redux/ui/pref_state.g.dart index c174fcf62..51780c1a3 100644 --- a/lib/redux/ui/pref_state.g.dart +++ b/lib/redux/ui/pref_state.g.dart @@ -142,6 +142,9 @@ class _$PrefStateSerializer implements StructuredSerializer { 'showKanban', serializers.serialize(object.showKanban, specifiedType: const FullType(bool)), + 'showPdfPreview', + serializers.serialize(object.showPdfPreview, + specifiedType: const FullType(bool)), 'isHistoryVisible', serializers.serialize(object.isHistoryVisible, specifiedType: const FullType(bool)), @@ -241,6 +244,10 @@ class _$PrefStateSerializer implements StructuredSerializer { result.showKanban = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; break; + case 'showPdfPreview': + result.showPdfPreview = serializers.deserialize(value, + specifiedType: const FullType(bool)) as bool; + break; case 'isHistoryVisible': result.isHistoryVisible = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; @@ -548,6 +555,8 @@ class _$PrefState extends PrefState { @override final bool showKanban; @override + final bool showPdfPreview; + @override final bool isHistoryVisible; @override final bool enableDarkMode; @@ -587,6 +596,7 @@ class _$PrefState extends PrefState { this.isPreviewVisible, this.isMenuVisible, this.showKanban, + this.showPdfPreview, this.isHistoryVisible, this.enableDarkMode, this.isFilterVisible, @@ -618,6 +628,8 @@ class _$PrefState extends PrefState { isMenuVisible, 'PrefState', 'isMenuVisible'); BuiltValueNullFieldError.checkNotNull( showKanban, 'PrefState', 'showKanban'); + BuiltValueNullFieldError.checkNotNull( + showPdfPreview, 'PrefState', 'showPdfPreview'); BuiltValueNullFieldError.checkNotNull( isHistoryVisible, 'PrefState', 'isHistoryVisible'); BuiltValueNullFieldError.checkNotNull( @@ -665,6 +677,7 @@ class _$PrefState extends PrefState { isPreviewVisible == other.isPreviewVisible && isMenuVisible == other.isMenuVisible && showKanban == other.showKanban && + showPdfPreview == other.showPdfPreview && isHistoryVisible == other.isHistoryVisible && enableDarkMode == other.enableDarkMode && isFilterVisible == other.isFilterVisible && @@ -701,13 +714,13 @@ class _$PrefState extends PrefState { $jc( $jc( $jc( - $jc($jc($jc($jc(0, appLayout.hashCode), moduleLayout.hashCode), menuSidebarMode.hashCode), - historySidebarMode.hashCode), - useSidebarEditor.hashCode), - customColors.hashCode), - isPreviewVisible.hashCode), - isMenuVisible.hashCode), - showKanban.hashCode), + $jc($jc($jc($jc($jc(0, appLayout.hashCode), moduleLayout.hashCode), menuSidebarMode.hashCode), historySidebarMode.hashCode), + useSidebarEditor.hashCode), + customColors.hashCode), + isPreviewVisible.hashCode), + isMenuVisible.hashCode), + showKanban.hashCode), + showPdfPreview.hashCode), isHistoryVisible.hashCode), enableDarkMode.hashCode), isFilterVisible.hashCode), @@ -735,6 +748,7 @@ class _$PrefState extends PrefState { ..add('isPreviewVisible', isPreviewVisible) ..add('isMenuVisible', isMenuVisible) ..add('showKanban', showKanban) + ..add('showPdfPreview', showPdfPreview) ..add('isHistoryVisible', isHistoryVisible) ..add('enableDarkMode', enableDarkMode) ..add('isFilterVisible', isFilterVisible) @@ -800,6 +814,11 @@ class PrefStateBuilder implements Builder { bool get showKanban => _$this._showKanban; set showKanban(bool showKanban) => _$this._showKanban = showKanban; + bool _showPdfPreview; + bool get showPdfPreview => _$this._showPdfPreview; + set showPdfPreview(bool showPdfPreview) => + _$this._showPdfPreview = showPdfPreview; + bool _isHistoryVisible; bool get isHistoryVisible => _$this._isHistoryVisible; set isHistoryVisible(bool isHistoryVisible) => @@ -879,6 +898,7 @@ class PrefStateBuilder implements Builder { _isPreviewVisible = $v.isPreviewVisible; _isMenuVisible = $v.isMenuVisible; _showKanban = $v.showKanban; + _showPdfPreview = $v.showPdfPreview; _isHistoryVisible = $v.isHistoryVisible; _enableDarkMode = $v.enableDarkMode; _isFilterVisible = $v.isFilterVisible; @@ -930,8 +950,9 @@ class PrefStateBuilder implements Builder { isMenuVisible, 'PrefState', 'isMenuVisible'), showKanban: BuiltValueNullFieldError.checkNotNull( showKanban, 'PrefState', 'showKanban'), - isHistoryVisible: BuiltValueNullFieldError.checkNotNull( - isHistoryVisible, 'PrefState', 'isHistoryVisible'), + showPdfPreview: BuiltValueNullFieldError.checkNotNull( + showPdfPreview, 'PrefState', 'showPdfPreview'), + isHistoryVisible: BuiltValueNullFieldError.checkNotNull(isHistoryVisible, 'PrefState', 'isHistoryVisible'), enableDarkMode: BuiltValueNullFieldError.checkNotNull(enableDarkMode, 'PrefState', 'enableDarkMode'), isFilterVisible: BuiltValueNullFieldError.checkNotNull(isFilterVisible, 'PrefState', 'isFilterVisible'), persistData: BuiltValueNullFieldError.checkNotNull(persistData, 'PrefState', 'persistData'), diff --git a/lib/ui/settings/device_settings.dart b/lib/ui/settings/device_settings.dart index 199bfe558..cdae2316e 100644 --- a/lib/ui/settings/device_settings.dart +++ b/lib/ui/settings/device_settings.dart @@ -149,7 +149,7 @@ class _DeviceSettingsState extends State disabledLabel: localization.showOrHide, ), ], - if (isDesktop(context)) + if (isDesktop(context)) ...[ BoolDropdownButton( label: localization.clickSelected, value: prefState.tapSelectedToEdit, @@ -158,8 +158,19 @@ class _DeviceSettingsState extends State }, enabledLabel: localization.editRecord, disabledLabel: localization.hidePreview, - ) - else + ), + Padding( + padding: const EdgeInsets.only(top: 10), + child: SwitchListTile( + title: Text(localization.showPdfPreview), + value: prefState.showPdfPreview, + onChanged: (value) => + viewModel.onShowPdfChanged(context, value), + activeColor: Theme.of(context).colorScheme.secondary, + secondary: Icon(MdiIcons.filePdfBox), + ), + ), + ] else BoolDropdownButton( label: localization.listLongPress, value: !prefState.longPressSelectionIsDefault, diff --git a/lib/ui/settings/device_settings_vm.dart b/lib/ui/settings/device_settings_vm.dart index 63ea05cf1..f2703b9fb 100644 --- a/lib/ui/settings/device_settings_vm.dart +++ b/lib/ui/settings/device_settings_vm.dart @@ -54,6 +54,7 @@ class DeviceSettingsVM { @required this.onCustomColorsChanged, @required this.onPersistDataChanged, @required this.onPersistUiChanged, + @required this.onShowPdfChanged, @required this.onTapSelectedChanged, }); @@ -98,6 +99,9 @@ class DeviceSettingsVM { onTapSelectedChanged: (context, value) async { store.dispatch(UpdateUserPreferences(tapSelectedToEdit: value)); }, + onShowPdfChanged: (context, value) { + store.dispatch(UpdateUserPreferences(showPdfPreview: value)); + }, onColorThemeChanged: (context, value) async { if (store.state.prefState.colorTheme != value) { store.dispatch(UpdateUserPreferences(colorTheme: value)); @@ -182,5 +186,6 @@ class DeviceSettingsVM { final Function(BuildContext, bool) onRequireAuthenticationChanged; final Function(BuildContext, bool) onPersistDataChanged; final Function(BuildContext, bool) onPersistUiChanged; + final Function(BuildContext, bool) onShowPdfChanged; final Future authenticationSupported; } diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 93736c22d..f6f4f1ea9 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 + 'show_pdf_preview': 'Show PDF Preview', 'print_pdf': 'Print PDF', 'remind_me': 'Remind Me', 'instant_bank_pay': 'Instant Bank Pay', @@ -62844,6 +62845,10 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]['print_pdf'] ?? _localizedValues['en']['print_pdf']; + String get showPdfPreview => + _localizedValues[localeCode]['show_pdf_preview'] ?? + _localizedValues['en']['show_pdf_preview']; + // STARTER: lang field - do not remove comment String lookup(String key) {