Skip to content

Commit

Permalink
fix todos
Browse files Browse the repository at this point in the history
  • Loading branch information
derdilla committed Aug 26, 2023
1 parent 0b17bcd commit fba9ef0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
13 changes: 9 additions & 4 deletions lib/components/export_item_order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -105,7 +106,6 @@ class _ExportItemsCustomizerState extends State<ExportItemsCustomizer> {

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(
Expand All @@ -116,13 +116,18 @@ class _ExportItemsCustomizerState extends State<ExportItemsCustomizer> {
icon: const Icon(Icons.collections_bookmark),
itemBuilder: (BuildContext context) {
return [
for (var i = 0; i< exportConfigurationKeys.length; i++)
PopupMenuItem<int>(value: i, child: Text(exportConfigurationKeys[i])),
for (var i = 0; i< exportConfigurations.length; i++)
PopupMenuItem<int>(value: i, child: Text(exportConfigurations[i].$1)),
];
},
onSelected: (value) {
final settings = Provider.of<Settings>(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,
Expand Down
11 changes: 6 additions & 5 deletions lib/model/export_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class ExportConfigurationModel {

final List<ExportColumn> _availableFormats = [];

Map<String, List<String>> get exportConfigurations => { // todo change type to List<String, List<String> 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<internalNameOfExportFormat>)
List<(String, List<String>)> 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<void> _asyncInit(String? dbPath, bool isFullPath) async {
Expand Down
16 changes: 12 additions & 4 deletions lib/model/settings_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> get exportItemsCsv {
return _prefs.getStringList('exportItems') ?? ExportFields.defaultCsv; // TODO migrate var name
return _prefs.getStringList('exportItemsCsv') ?? ExportFields.defaultCsv;
}

set exportItemsCsv(List<String> value) {
_prefs.setStringList('exportItems', value);
_prefs.setStringList('exportItemsCsv', value);
notifyListeners();
}

Expand Down

0 comments on commit fba9ef0

Please sign in to comment.