Skip to content

Commit 49d14ae

Browse files
Add reset button for default symptoms
1 parent 93bcdc1 commit 49d14ae

File tree

13 files changed

+162
-36
lines changed

13 files changed

+162
-36
lines changed

app/lib/database/repositories/periods_repository.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class PeriodsRepository {
133133

134134
if (entry.symptoms.isNotEmpty) {
135135
final batch = txn.batch();
136-
for (final symptom in entry.symptoms.where((element) => element.type != SymptomType.add)) {
136+
for (final symptom in entry.symptoms.where((element) => element.type != SymptomType.other)) {
137137
batch.insert('log_symptoms', {
138138
'log_id_fk': newLogId,
139139
'symptom': symptom.getDbName(),

app/lib/l10n/app_en.arb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"cancel": "Cancel",
3939
"select": "Select",
4040
"close": "Close",
41+
"reset": "Reset",
4142

4243
"systemDefault": "System Default",
4344

@@ -186,6 +187,8 @@
186187
}
187188
}
188189
},
190+
"settingsScreen_resetDefaultSymptoms" : "Reset default symptoms?",
191+
"settingsScreen_resetDefaultSymptomsDescription" : "This will reset the default symptoms to the built in symptoms.\n\nExisting period logs will not be updated!",
189192
"settingsScreen_periodLoggingScreen" : "Period Logging",
190193
"settingsScreen_deleteDefaultSymptomDescription": "'{symptom}' will no longer be available when logging a period.\n\n{usageCount, plural, zero{There are currently no period logs with this symptom!} one{There is already 1 period log with this symptom!\nThis log will not be changed.} other{There are {usageCount} period logs with this symptom!\nThese logs will not be changed.}}",
191194
"@settingsScreen_deleteDefaultSymptomDescription": {

app/lib/l10n/app_localizations.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ abstract class AppLocalizations {
234234
/// **'Close'**
235235
String get close;
236236

237+
/// No description provided for @reset.
238+
///
239+
/// In en, this message translates to:
240+
/// **'Reset'**
241+
String get reset;
242+
237243
/// No description provided for @systemDefault.
238244
///
239245
/// In en, this message translates to:
@@ -726,6 +732,18 @@ abstract class AppLocalizations {
726732
/// **'Delete \'{symptom}\'?'**
727733
String settingsScreen_deleteDefaultSymptomQuestion(String symptom);
728734

735+
/// No description provided for @settingsScreen_resetDefaultSymptoms.
736+
///
737+
/// In en, this message translates to:
738+
/// **'Reset default symptoms?'**
739+
String get settingsScreen_resetDefaultSymptoms;
740+
741+
/// No description provided for @settingsScreen_resetDefaultSymptomsDescription.
742+
///
743+
/// In en, this message translates to:
744+
/// **'This will reset the default symptoms to the built in symptoms.\n\nExisting period logs will not be updated!'**
745+
String get settingsScreen_resetDefaultSymptomsDescription;
746+
729747
/// No description provided for @settingsScreen_periodLoggingScreen.
730748
///
731749
/// In en, this message translates to:

app/lib/l10n/app_localizations_de.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class AppLocalizationsDe extends AppLocalizations {
8282
@override
8383
String get close => 'Schließen';
8484

85+
@override
86+
String get reset => 'Reset';
87+
8588
@override
8689
String get systemDefault => 'System Standard';
8790

@@ -368,6 +371,13 @@ class AppLocalizationsDe extends AppLocalizations {
368371
return 'Delete \'$symptom\'?';
369372
}
370373

374+
@override
375+
String get settingsScreen_resetDefaultSymptoms => 'Reset default symptoms?';
376+
377+
@override
378+
String get settingsScreen_resetDefaultSymptomsDescription =>
379+
'This will reset the default symptoms to the built in symptoms.\n\nExisting period logs will not be updated!';
380+
371381
@override
372382
String get settingsScreen_periodLoggingScreen => 'Period Logging';
373383

app/lib/l10n/app_localizations_en.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class AppLocalizationsEn extends AppLocalizations {
8282
@override
8383
String get close => 'Close';
8484

85+
@override
86+
String get reset => 'Reset';
87+
8588
@override
8689
String get systemDefault => 'System Default';
8790

@@ -366,6 +369,13 @@ class AppLocalizationsEn extends AppLocalizations {
366369
return 'Delete \'$symptom\'?';
367370
}
368371

372+
@override
373+
String get settingsScreen_resetDefaultSymptoms => 'Reset default symptoms?';
374+
375+
@override
376+
String get settingsScreen_resetDefaultSymptomsDescription =>
377+
'This will reset the default symptoms to the built in symptoms.\n\nExisting period logs will not be updated!';
378+
369379
@override
370380
String get settingsScreen_periodLoggingScreen => 'Period Logging';
371381

app/lib/l10n/app_localizations_fr.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class AppLocalizationsFr extends AppLocalizations {
8282
@override
8383
String get close => 'Fermer';
8484

85+
@override
86+
String get reset => 'Reset';
87+
8588
@override
8689
String get systemDefault => 'System Default';
8790

@@ -373,6 +376,13 @@ class AppLocalizationsFr extends AppLocalizations {
373376
return 'Delete \'$symptom\'?';
374377
}
375378

379+
@override
380+
String get settingsScreen_resetDefaultSymptoms => 'Reset default symptoms?';
381+
382+
@override
383+
String get settingsScreen_resetDefaultSymptomsDescription =>
384+
'This will reset the default symptoms to the built in symptoms.\n\nExisting period logs will not be updated!';
385+
376386
@override
377387
String get settingsScreen_periodLoggingScreen => 'Period Logging';
378388

app/lib/l10n/app_localizations_it.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class AppLocalizationsIt extends AppLocalizations {
8282
@override
8383
String get close => 'Chiudi';
8484

85+
@override
86+
String get reset => 'Reset';
87+
8588
@override
8689
String get systemDefault => 'System Default';
8790

@@ -373,6 +376,13 @@ class AppLocalizationsIt extends AppLocalizations {
373376
return 'Delete \'$symptom\'?';
374377
}
375378

379+
@override
380+
String get settingsScreen_resetDefaultSymptoms => 'Reset default symptoms?';
381+
382+
@override
383+
String get settingsScreen_resetDefaultSymptomsDescription =>
384+
'This will reset the default symptoms to the built in symptoms.\n\nExisting period logs will not be updated!';
385+
376386
@override
377387
String get settingsScreen_periodLoggingScreen => 'Period Logging';
378388

app/lib/models/period_logs/symptom.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class Symptom {
1919
}
2020

2121
factory Symptom.addSymptom() {
22-
return Symptom(type: SymptomType.add, customName: "+");
22+
return Symptom(type: SymptomType.other, customName: "+");
23+
}
24+
25+
factory Symptom.refreshSymptom() {
26+
return Symptom(type: SymptomType.other, customName: "↻");
2327
}
2428

2529
@override
@@ -34,7 +38,7 @@ class Symptom {
3438
return false;
3539
}
3640

37-
if (type == SymptomType.custom) {
41+
if (type == SymptomType.custom || type == SymptomType.other) {
3842
return customName == otherSymptom.customName;
3943
}
4044

@@ -50,7 +54,7 @@ class Symptom {
5054
return SymptomType.values
5155
.where(
5256
(element) =>
53-
element != SymptomType.custom && element != SymptomType.add,
57+
element != SymptomType.custom && element != SymptomType.other,
5458
)
5559
.map((e) => Symptom.fromDbString(e.toString()))
5660
.toSet();
@@ -83,10 +87,8 @@ extension SymptomExtension on Symptom {
8387
return l10n.builtInSymptom_moodSwings;
8488
case SymptomType.builtInNausea:
8589
return l10n.builtInSymptom_nausea;
86-
case SymptomType.custom:
90+
case SymptomType.custom || SymptomType.other:
8791
return customName;
88-
case SymptomType.add:
89-
return "+";
9092
}
9193
}
9294
}

app/lib/models/period_logs/symptom_type_enum.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ enum SymptomType {
1010
builtInMoodSwings,
1111
builtInNausea,
1212
custom,
13-
add
13+
other
1414
}

app/lib/screens/settings/period_log_settings_screen.dart

Lines changed: 83 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class PeriodLogSettingsScreen extends StatefulWidget {
1111
const PeriodLogSettingsScreen({super.key});
1212

1313
@override
14-
State<PeriodLogSettingsScreen> createState() => _PeriodLogSettingsScreenState();
14+
State<PeriodLogSettingsScreen> createState() =>
15+
_PeriodLogSettingsScreenState();
1516
}
1617

1718
class _PeriodLogSettingsScreenState extends State<PeriodLogSettingsScreen> {
@@ -20,7 +21,7 @@ class _PeriodLogSettingsScreenState extends State<PeriodLogSettingsScreen> {
2021

2122
bool _isLoading = true;
2223

23-
Set<Symptom> _defaultSymptoms = {};
24+
final Set<Symptom> _defaultSymptoms = {};
2425

2526
@override
2627
void initState() {
@@ -29,50 +30,63 @@ class _PeriodLogSettingsScreenState extends State<PeriodLogSettingsScreen> {
2930
}
3031

3132
Future<void> _loadSettings() async {
33+
_isLoading = true;
34+
3235
var defaultSymptoms = await _settingsService.getDefaultSymptoms();
3336
defaultSymptoms.add(Symptom.addSymptom());
37+
defaultSymptoms.add(Symptom.refreshSymptom());
3438

3539
if (mounted) {
3640
setState(() {
41+
_defaultSymptoms.clear();
3742
_defaultSymptoms.addAll(defaultSymptoms);
38-
_isLoading = false;
3943
});
4044
}
45+
46+
_isLoading = false;
4147
}
4248

4349
Future<void> _showNewCustomSymptomDialog() async {
44-
final (String name, bool isDefault)? result = await showDialog<(String, bool)>(
45-
context: context,
46-
builder: (BuildContext context) {
47-
return const CustomSymptomDialog(showTemporarySymptomButton: true);
48-
},
49-
);
50+
final (String name, bool isDefault)? result =
51+
await showDialog<(String, bool)>(
52+
context: context,
53+
builder: (BuildContext context) {
54+
return const CustomSymptomDialog(showTemporarySymptomButton: true);
55+
},
56+
);
5057

51-
if (mounted && result != null && _defaultSymptoms.any((element) => element.customName == result.$1) == false) {
58+
if (mounted &&
59+
result != null &&
60+
_defaultSymptoms.any((element) => element.customName == result.$1) ==
61+
false) {
5262
var symptom = Symptom.fromDbString(result.$1);
5363

5464
await _settingsService.addDefaultSymptom(symptom);
55-
56-
setState(() {
57-
_defaultSymptoms.remove(Symptom.addSymptom());
58-
_defaultSymptoms.add(symptom);
59-
_defaultSymptoms.add(Symptom.addSymptom());
60-
});
65+
await _loadSettings();
6166
}
6267
}
6368

6469
Future<void> _removeDefaultSymptom(Symptom symptom) async {
6570
final l10n = AppLocalizations.of(context)!;
66-
final symptomUsageCount = await periodsRepo.getSingleSymptomFrequency(symptom);
71+
final symptomUsageCount = await periodsRepo.getSingleSymptomFrequency(
72+
symptom,
73+
);
6774

6875
if (mounted) {
6976
return showDialog<void>(
7077
context: context,
7178
builder: (BuildContext context) {
7279
return ConfirmationDialog(
73-
title: l10n.settingsScreen_deleteDefaultSymptomQuestion(symptom.getDisplayName(l10n)),
74-
contentText: l10n.settingsScreen_deleteDefaultSymptomDescription(symptom.getDisplayName(l10n), symptomUsageCount),
75-
confirmButtonText: symptomUsageCount > 0 ? l10n.deleteAnyways : l10n.delete,
80+
title: l10n.settingsScreen_deleteDefaultSymptomQuestion(
81+
symptom.getDisplayName(l10n),
82+
),
83+
contentText: l10n.settingsScreen_deleteDefaultSymptomDescription(
84+
symptom.getDisplayName(l10n),
85+
symptomUsageCount,
86+
),
87+
confirmButtonText: symptomUsageCount > 0
88+
? l10n.deleteAnyways
89+
: l10n.delete,
7690
onConfirm: () async {
7791
setState(() {
7892
_defaultSymptoms.remove(symptom);
@@ -85,31 +99,75 @@ class _PeriodLogSettingsScreenState extends State<PeriodLogSettingsScreen> {
8599
}
86100
}
87101

102+
Future<void> _refreshSymptoms() async {
103+
final l10n = AppLocalizations.of(context)!;
104+
105+
if (mounted) {
106+
return showDialog<void>(
107+
context: context,
108+
builder: (BuildContext context) {
109+
return ConfirmationDialog(
110+
title: l10n.settingsScreen_resetDefaultSymptoms,
111+
contentText: l10n.settingsScreen_resetDefaultSymptomsDescription,
112+
confirmButtonText: l10n.reset,
113+
onConfirm: () async {
114+
await _settingsService.resetDefaultSymptoms();
115+
await _loadSettings();
116+
},
117+
);
118+
},
119+
);
120+
}
121+
}
122+
88123
@override
89124
Widget build(BuildContext context) {
90125
final l10n = AppLocalizations.of(context)!;
91126
final theme = Theme.of(context);
92127
final colorScheme = theme.colorScheme;
93128
return Scaffold(
94-
appBar: AppBar(title: Text(l10n.settingsScreen_periodPredictionAndReminders)),
129+
appBar: AppBar(
130+
title: Text(l10n.settingsScreen_periodPredictionAndReminders),
131+
),
95132
body: _isLoading
96133
? const Center(child: CircularProgressIndicator())
97134
: ListView(
98135
children: [
99136
ListTile(
100137
title: Text(l10n.settingsScreen_defaultSymptoms),
101-
leading: Icon(Icons.bubble_chart_outlined, color: colorScheme.onSurfaceVariant, size: 20),
138+
leading: Icon(
139+
Icons.bubble_chart_outlined,
140+
color: colorScheme.onSurfaceVariant,
141+
size: 20,
142+
),
143+
),
144+
ListTile(
145+
subtitle: Text(l10n.settingsScreen_defaultSymptomsSubtitle),
102146
),
103-
ListTile(subtitle: Text(l10n.settingsScreen_defaultSymptomsSubtitle)),
104147
Padding(
105148
padding: EdgeInsets.symmetric(horizontal: 12),
106149
child: Wrap(
107150
alignment: WrapAlignment.start,
108151
spacing: 4.0,
109152
runSpacing: 4.0,
110153
children: _defaultSymptoms.map((symptom) {
111-
var isAdd = symptom.type == SymptomType.add;
112-
return RawChip(label: Text(symptom.getDisplayName(l10n)), backgroundColor: isAdd ? colorScheme.onSecondary : null, tapEnabled: true, onPressed: () => {if (isAdd) _showNewCustomSymptomDialog() else _removeDefaultSymptom(symptom)});
154+
var isAdd = symptom == Symptom.addSymptom();
155+
var isRefresh = symptom == Symptom.refreshSymptom();
156+
return RawChip(
157+
label: Text(symptom.getDisplayName(l10n)),
158+
backgroundColor: isAdd || isRefresh
159+
? colorScheme.onSecondary
160+
: null,
161+
tapEnabled: true,
162+
onPressed: () => {
163+
if (isRefresh)
164+
{_refreshSymptoms()}
165+
else if (isAdd)
166+
{_showNewCustomSymptomDialog()}
167+
else
168+
{_removeDefaultSymptom(symptom)},
169+
},
170+
);
113171
}).toList(),
114172
),
115173
),

0 commit comments

Comments
 (0)