diff --git a/lib/components/export_item_order.dart b/lib/components/export_item_order.dart index 2fdbe8f3..a275fc8d 100644 --- a/lib/components/export_item_order.dart +++ b/lib/components/export_item_order.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:badges/badges.dart' as badges; import 'package:blood_pressure_app/components/consistent_future_builder.dart'; +import 'package:blood_pressure_app/model/export_import.dart'; import 'package:blood_pressure_app/model/export_options.dart'; import 'package:blood_pressure_app/model/settings_store.dart'; import 'package:blood_pressure_app/screens/subsettings/export_column_data.dart'; @@ -105,7 +106,6 @@ class _ExportItemsCustomizerState extends State { Widget _buildManagePresetsBadge(BuildContext context, ExportConfigurationModel result, {required Widget child}) { final exportConfigurations = result.exportConfigurations; - final exportConfigurationKeys = exportConfigurations.keys.toList(); return badges.Badge( position: badges.BadgePosition.topEnd(top: 3, end: 3), badgeStyle: badges.BadgeStyle( @@ -116,13 +116,18 @@ class _ExportItemsCustomizerState extends State { icon: const Icon(Icons.collections_bookmark), itemBuilder: (BuildContext context) { return [ - for (var i = 0; i< exportConfigurationKeys.length; i++) - PopupMenuItem(value: i, child: Text(exportConfigurationKeys[i])), + for (var i = 0; i< exportConfigurations.length; i++) + PopupMenuItem(value: i, child: Text(exportConfigurations[i].$1)), ]; }, onSelected: (value) { final settings = Provider.of(context, listen: false); - settings.exportItemsCsv = exportConfigurations[exportConfigurationKeys[value]]!; + if (settings.exportFormat == ExportFormat.csv) { + settings.exportItemsCsv = exportConfigurations[value].$2; + } else { + assert(settings.exportFormat == ExportFormat.pdf); + settings.exportItemsPdf = exportConfigurations[value].$2; + } }, ), child: child, diff --git a/lib/model/export_options.dart b/lib/model/export_options.dart index fdca0e67..b57b8a13 100644 --- a/lib/model/export_options.dart +++ b/lib/model/export_options.dart @@ -23,11 +23,12 @@ class ExportConfigurationModel { final List _availableFormats = []; - Map> get exportConfigurations => { // todo change type to List and add pdf and csv seperately or remove entirely - // Not fully localized, as potemtial user added configurations can't be localized as well - localizations.default_: ['timestampUnixMs', 'systolic', 'diastolic', 'pulse', 'notes'], - '"My Heart" export': ['DATUM', 'SYSTOLE', 'DIASTOLE', 'PULS', 'Beschreibung', 'Tags', 'Gewicht', 'Sauerstoffsättigung'], - }; + /// Format: (title, List) + List<(String, List)> get exportConfigurations => [ + // Not fully localized, as potential user added configurations can't be localized as well + (localizations.default_, ['timestampUnixMs', 'systolic', 'diastolic', 'pulse', 'notes']), + ('"My Heart" export', ['DATUM', 'SYSTOLE', 'DIASTOLE', 'PULS', 'Beschreibung', 'Tags', 'Gewicht', 'Sauerstoffsättigung']), + ]; ExportConfigurationModel._create(this.settings, this.localizations); Future _asyncInit(String? dbPath, bool isFullPath) async { diff --git a/lib/model/settings_store.dart b/lib/model/settings_store.dart index fd5ddeb3..0dbc2d64 100644 --- a/lib/model/settings_store.dart +++ b/lib/model/settings_store.dart @@ -49,6 +49,14 @@ class Settings extends ChangeNotifier { if (keys.contains('exportAddableItems')) { toAwait.add(_prefs.remove('exportAddableItems')); } + if (keys.contains('exportCustomEntries')) { + await _prefs.setBool('exportCustomEntriesCsv', _prefs.getBool('exportCustomEntries') ?? false); + toAwait.add(_prefs.remove('exportCustomEntries')); + } + if (keys.contains('exportItems')) { + await _prefs.setStringList('exportItemsCsv', _prefs.getStringList('exportItems') ?? ExportFields.defaultCsv); + toAwait.add(_prefs.remove('exportItems')); + } // reset variables for new version. Necessary for reusing variable names in new version and avoid having unexpected // breaking values in the preferences @@ -454,20 +462,20 @@ class Settings extends ChangeNotifier { } bool get exportCustomEntriesCsv { - return _prefs.getBool('exportCustomEntries') ?? false; + return _prefs.getBool('exportCustomEntriesCsv') ?? false; } set exportCustomEntriesCsv(bool value) { - _prefs.setBool('exportCustomEntries', value); + _prefs.setBool('exportCustomEntriesCsv', value); notifyListeners(); } List get exportItemsCsv { - return _prefs.getStringList('exportItems') ?? ExportFields.defaultCsv; // TODO migrate var name + return _prefs.getStringList('exportItemsCsv') ?? ExportFields.defaultCsv; } set exportItemsCsv(List value) { - _prefs.setStringList('exportItems', value); + _prefs.setStringList('exportItemsCsv', value); notifyListeners(); }