Persist UI option

This commit is contained in:
Hillel Coren 2021-10-21 15:52:26 +03:00
parent 0c01b9afbb
commit c03922a1ce
6 changed files with 163 additions and 115 deletions

View File

@ -134,6 +134,7 @@ class UpdateUserPreferences implements PersistPrefs {
this.colorTheme,
this.customColors,
this.persistData,
this.persistUi,
});
final AppLayout appLayout;
@ -151,6 +152,7 @@ class UpdateUserPreferences implements PersistPrefs {
final int rowsPerPage;
final String colorTheme;
final bool persistData;
final bool persistUi;
final BuiltMap<String, String> customColors;
}

View File

@ -27,6 +27,7 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
longPressSelectionIsDefault: true,
showKanban: false,
persistData: false,
persistUI: true,
companyPrefs: BuiltMap<String, CompanyPrefState>(),
sortFields: BuiltMap<EntityType, PrefStateSortField>(),
customColors: BuiltMap<String, String>(CONTRAST_COLORS),
@ -98,6 +99,8 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
bool get persistData;
bool get persistUI;
bool get longPressSelectionIsDefault;
bool get requireAuthentication;
@ -175,6 +178,7 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
..isPreviewVisible = false
..isFilterVisible = false
..persistData = false
..persistUI = true
..colorTheme =
builder.enableDarkMode == true ? kColorThemeLight : kColorThemeLight;

View File

@ -154,6 +154,9 @@ class _$PrefStateSerializer implements StructuredSerializer<PrefState> {
'persistData',
serializers.serialize(object.persistData,
specifiedType: const FullType(bool)),
'persistUI',
serializers.serialize(object.persistUI,
specifiedType: const FullType(bool)),
'longPressSelectionIsDefault',
serializers.serialize(object.longPressSelectionIsDefault,
specifiedType: const FullType(bool)),
@ -248,6 +251,10 @@ class _$PrefStateSerializer implements StructuredSerializer<PrefState> {
result.persistData = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool;
break;
case 'persistUI':
result.persistUI = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool;
break;
case 'longPressSelectionIsDefault':
result.longPressSelectionIsDefault = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool;
@ -535,6 +542,8 @@ class _$PrefState extends PrefState {
@override
final bool persistData;
@override
final bool persistUI;
@override
final bool longPressSelectionIsDefault;
@override
final bool requireAuthentication;
@ -564,6 +573,7 @@ class _$PrefState extends PrefState {
this.enableDarkMode,
this.isFilterVisible,
this.persistData,
this.persistUI,
this.longPressSelectionIsDefault,
this.requireAuthentication,
this.rowsPerPage,
@ -596,6 +606,7 @@ class _$PrefState extends PrefState {
isFilterVisible, 'PrefState', 'isFilterVisible');
BuiltValueNullFieldError.checkNotNull(
persistData, 'PrefState', 'persistData');
BuiltValueNullFieldError.checkNotNull(persistUI, 'PrefState', 'persistUI');
BuiltValueNullFieldError.checkNotNull(longPressSelectionIsDefault,
'PrefState', 'longPressSelectionIsDefault');
BuiltValueNullFieldError.checkNotNull(
@ -634,6 +645,7 @@ class _$PrefState extends PrefState {
enableDarkMode == other.enableDarkMode &&
isFilterVisible == other.isFilterVisible &&
persistData == other.persistData &&
persistUI == other.persistUI &&
longPressSelectionIsDefault == other.longPressSelectionIsDefault &&
requireAuthentication == other.requireAuthentication &&
rowsPerPage == other.rowsPerPage &&
@ -662,6 +674,7 @@ class _$PrefState extends PrefState {
$jc(
$jc(
$jc(
$jc(
$jc(
$jc(
0,
@ -685,6 +698,7 @@ class _$PrefState extends PrefState {
enableDarkMode.hashCode),
isFilterVisible.hashCode),
persistData.hashCode),
persistUI.hashCode),
longPressSelectionIsDefault.hashCode),
requireAuthentication.hashCode),
rowsPerPage.hashCode),
@ -709,6 +723,7 @@ class _$PrefState extends PrefState {
..add('enableDarkMode', enableDarkMode)
..add('isFilterVisible', isFilterVisible)
..add('persistData', persistData)
..add('persistUI', persistUI)
..add('longPressSelectionIsDefault', longPressSelectionIsDefault)
..add('requireAuthentication', requireAuthentication)
..add('rowsPerPage', rowsPerPage)
@ -786,6 +801,10 @@ class PrefStateBuilder implements Builder<PrefState, PrefStateBuilder> {
bool get persistData => _$this._persistData;
set persistData(bool persistData) => _$this._persistData = persistData;
bool _persistUI;
bool get persistUI => _$this._persistUI;
set persistUI(bool persistUI) => _$this._persistUI = persistUI;
bool _longPressSelectionIsDefault;
bool get longPressSelectionIsDefault => _$this._longPressSelectionIsDefault;
set longPressSelectionIsDefault(bool longPressSelectionIsDefault) =>
@ -836,6 +855,7 @@ class PrefStateBuilder implements Builder<PrefState, PrefStateBuilder> {
_enableDarkMode = $v.enableDarkMode;
_isFilterVisible = $v.isFilterVisible;
_persistData = $v.persistData;
_persistUI = $v.persistUI;
_longPressSelectionIsDefault = $v.longPressSelectionIsDefault;
_requireAuthentication = $v.requireAuthentication;
_rowsPerPage = $v.rowsPerPage;
@ -885,6 +905,7 @@ class PrefStateBuilder implements Builder<PrefState, PrefStateBuilder> {
enableDarkMode: BuiltValueNullFieldError.checkNotNull(enableDarkMode, 'PrefState', 'enableDarkMode'),
isFilterVisible: BuiltValueNullFieldError.checkNotNull(isFilterVisible, 'PrefState', 'isFilterVisible'),
persistData: BuiltValueNullFieldError.checkNotNull(persistData, 'PrefState', 'persistData'),
persistUI: BuiltValueNullFieldError.checkNotNull(persistUI, 'PrefState', 'persistUI'),
longPressSelectionIsDefault: BuiltValueNullFieldError.checkNotNull(longPressSelectionIsDefault, 'PrefState', 'longPressSelectionIsDefault'),
requireAuthentication: BuiltValueNullFieldError.checkNotNull(requireAuthentication, 'PrefState', 'requireAuthentication'),
rowsPerPage: BuiltValueNullFieldError.checkNotNull(rowsPerPage, 'PrefState', 'rowsPerPage'),

View File

@ -196,6 +196,15 @@ class _DeviceSettingsState extends State<DeviceSettings>
}
},
),
SwitchListTile(
title: Text(localization.persistUi),
subtitle: Text(localization.persistUiHelp),
value: prefState.persistUI,
onChanged: (value) =>
viewModel.onPersistUiChanged(context, value),
activeColor: Theme.of(context).accentColor,
secondary: Icon(Icons.save_alt),
),
SwitchListTile(
title: Text(localization.persistData),
subtitle: Text(localization.persistDataHelp),

View File

@ -49,6 +49,7 @@ class DeviceSettingsVM {
@required this.onRowsPerPageChanged,
@required this.onCustomColorsChanged,
@required this.onPersistDataChanged,
@required this.onPersistUiChanged,
});
static DeviceSettingsVM fromStore(Store<AppState> store) {
@ -71,8 +72,7 @@ class DeviceSettingsVM {
store.dispatch(UpdatedSetting());
AppBuilder.of(context).rebuild();
},
onLongPressSelectionIsDefault:
(BuildContext context, bool value) async {
onLongPressSelectionIsDefault: (BuildContext context, bool value) async {
store.dispatch(
UpdateUserPreferences(longPressSelectionIsDefault: value));
},
@ -112,8 +112,7 @@ class DeviceSettingsVM {
}
});
},
onRequireAuthenticationChanged:
(BuildContext context, bool value) async {
onRequireAuthenticationChanged: (BuildContext context, bool value) async {
bool authenticated = false;
try {
authenticated = await LocalAuthentication().authenticate(
@ -152,7 +151,14 @@ class DeviceSettingsVM {
if (value) {
store.dispatch(UserLoginSuccess());
}
});
},
onPersistUiChanged: (context, value) {
store.dispatch(UpdateUserPreferences(persistUi: value));
if (value) {
store.dispatch(PersistUI());
}
},
);
}
final AppState state;
@ -167,6 +173,7 @@ class DeviceSettingsVM {
final Function(BuildContext, bool) onLongPressSelectionIsDefault;
final Function(BuildContext, bool) onRequireAuthenticationChanged;
final Function(BuildContext, bool) onPersistDataChanged;
final Function(BuildContext, bool) onPersistUiChanged;
final Function(BuildContext, int) onRowsPerPageChanged;
final Future<bool> authenticationSupported;
}

View File

@ -16,9 +16,10 @@ mixin LocalizationsProvider on LocaleCodeAware {
'en': {
// STARTER: lang key - do not remove comment
'persist_data_help':
'Save data locally to enable the app to start faster\nMay affect performance',
'persist_data_ui':
'Save UI state to enable the app to start at the last location\nMay slightly affect performance',
'Save data locally to enable the app to start faster, disabling may improve performance in large accounts',
'persist_ui': 'Persist UI',
'persist_ui_help':
'Save UI state to enable the app to start at the last location, disabling may slightly improve performance',
'client_postal_code': 'Client Postal Code',
'client_vat_number': 'Client VAT Number',
'has_tasks': 'Has Tasks',
@ -62733,10 +62734,14 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['persist_data_help'] ??
_localizedValues['en']['persist_data_help'];
String get persistUIHelp =>
String get persistUiHelp =>
_localizedValues[localeCode]['persist_ui_help'] ??
_localizedValues['en']['persist_ui_help'];
String get persistUi =>
_localizedValues[localeCode]['persist_ui'] ??
_localizedValues['en']['persist_ui'];
// STARTER: lang field - do not remove comment
String lookup(String key) {