Skip to content

Commit

Permalink
More polish and i18n work
Browse files Browse the repository at this point in the history
Also make sure that we don't update the routine while editing, since
some of the changes could pull the rug under our feet and felt strange.
Now there's a manual refresh button for the resulting routine
  • Loading branch information
rolandgeider committed Nov 16, 2024
1 parent 7499033 commit 94ed94c
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 72 deletions.
11 changes: 11 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@
"@reps": {
"description": "Shorthand for repetitions, used when space constraints are tighter"
},
"sets": "Sets",
"@sets": {
"description": "The number of sets to be done for one exercise"
},
"rir": "RiR",
"@rir": {
"description": "Shorthand for Repetitions In Reserve"
Expand Down Expand Up @@ -201,6 +205,9 @@
"@workoutSession": {
"description": "A (logged) workout session"
},
"restDay": "Rest day",
"isRestDay": "Is rest day",
"isRestDayHelp": "Please consider that all sets are removed from rest days when saved",
"newDay": "New day",
"@newDay": {},
"newSet": "New set",
Expand Down Expand Up @@ -697,7 +704,11 @@
"images": "Images",
"language": "Language",
"addExercise": "Add exercise",
"fitInWeek": "Fit in week",
"fitInWeekHelp": "Select if you want to fit the workout days into a week, you can add e.g. three days and mark this checkbox.",
"addSuperset": "Add superset",
"setHasProgression": "Set has progression",
"setHasProgressionWarning": "Please note that at the moment it is not possible to edit all settings for a set on the mobile application or configure the progression. ",
"setHasNoExercises": "This set has no exercises yet!",
"contributeExercise": "Contribute an exercise",
"translation": "Translation",
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/routines.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class RoutinesProvider with ChangeNotifier {
day = Day.fromJson(data);
day.slots = [];
final routine = findById(day.routineId);
routine.days.insert(0, day);
routine.days.add(day);
if (refresh) {
fetchAndSetRoutineFull(day.routineId);
}
Expand Down
10 changes: 8 additions & 2 deletions lib/widgets/core/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SettingsPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);
final exerciseProvider = Provider.of<ExercisesProvider>(context, listen: false);
final nutritionProvider = Provider.of<NutritionPlansProvider>(context, listen: false);

Expand All @@ -40,7 +41,12 @@ class SettingsPage extends StatelessWidget {
body: ListView(
children: [
ListTile(
title: Text(AppLocalizations.of(context).settingsExerciseCacheDescription),
title: Text(
i18n.settingsCacheTitle,
style: Theme.of(context).textTheme.headlineSmall,
)),
ListTile(
title: Text(i18n.settingsExerciseCacheDescription),
trailing: IconButton(
key: const ValueKey('cacheIconExercises'),
icon: const Icon(Icons.delete),
Expand All @@ -49,7 +55,7 @@ class SettingsPage extends StatelessWidget {

if (context.mounted) {
final snackBar = SnackBar(
content: Text(AppLocalizations.of(context).settingsCacheDeletedSnackbar),
content: Text(i18n.settingsCacheDeletedSnackbar),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/dashboard/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
children: [
Expanded(
child: Text(
dayData.day == null || dayData.day!.isRest ? 'REST DAY' : dayData.day!.name,
dayData.day == null || dayData.day!.isRest
? AppLocalizations.of(context).restDay
: dayData.day!.name,
style: const TextStyle(fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
),
Expand Down
5 changes: 4 additions & 1 deletion lib/widgets/routines/day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:wger/models/workouts/day_data.dart';
import 'package:wger/models/workouts/set_config_data.dart';
import 'package:wger/models/workouts/slot_data.dart';
Expand Down Expand Up @@ -135,13 +136,15 @@ class DayHeader extends StatelessWidget {

@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);

if (_dayData.day == null || _dayData.day!.isRest) {
return ListTile(
// tileColor: Colors.amber,
tileColor: Theme.of(context).focusColor,
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
title: Text(
'REST DAY',
i18n.restDay,
style: Theme.of(context).textTheme.headlineSmall,
overflow: TextOverflow.ellipsis,
),
Expand Down
71 changes: 48 additions & 23 deletions lib/widgets/routines/forms/day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ReorderableDaysList extends StatefulWidget {
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Confirm Delete'),
content: const Text('Are you sure you want to delete this day?'),
title: Text(AppLocalizations.of(context).delete),
content: Text(AppLocalizations.of(context).confirmDelete(day.name)),
actions: [
TextButton(
onPressed: () {
Expand Down Expand Up @@ -55,6 +55,9 @@ class ReorderableDaysList extends StatefulWidget {
class _ReorderableDaysListState extends State<ReorderableDaysList> {
@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);
final provider = context.read<RoutinesProvider>();

return Column(
children: [
ReorderableListView.builder(
Expand All @@ -72,13 +75,13 @@ class _ReorderableDaysListState extends State<ReorderableDaysList> {
//selected: day.id == widget.selectedDayId,
tileColor: isDaySelected ? Theme.of(context).highlightColor : null,
key: ValueKey(day),
title: Text(day.isRest ? 'REST DAY!' : day.name),
title: Text(day.isRest ? i18n.restDay : day.name),
leading: ReorderableDragStartListener(
index: index,
child: const Icon(Icons.drag_handle),
),
subtitle: Text(
day.isRest ? '' : day.description,
day.description,
style: const TextStyle(overflow: TextOverflow.ellipsis),
),
trailing: Row(
Expand Down Expand Up @@ -117,7 +120,7 @@ class _ReorderableDaysListState extends State<ReorderableDaysList> {
}
});

Provider.of<RoutinesProvider>(context, listen: false).editDays(widget.days);
provider.editDays(widget.days);
},
),
ListTile(
Expand All @@ -129,11 +132,17 @@ class _ReorderableDaysListState extends State<ReorderableDaysList> {
style: Theme.of(context).textTheme.titleMedium,
),
onTap: () async {
final newDay = Day.empty();
newDay.routineId = widget.routineId;
final result = await Provider.of<RoutinesProvider>(context, listen: false)
.addDay(newDay, refresh: true);
widget.onDaySelected(result.id!);
final day = Day.empty();
day.name = i18n.newDay;
day.routineId = widget.routineId;
final newDay = await provider.addDay(day);

// final newSlot = await provider.addSlot(Slot.withData(
// day: newDay.id,
// order: 1,
// ));

widget.onDaySelected(newDay.id!);
},
),
],
Expand Down Expand Up @@ -177,15 +186,32 @@ class _DayFormWidgetState extends State<DayFormWidget> {

@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);

return Form(
key: _form,
child: Column(
children: [
Text(
widget.day.isRest ? 'REST DAY' : widget.day.name,
widget.day.isRest ? i18n.restDay : widget.day.name,
style: Theme.of(context).textTheme.titleLarge,
),
SwitchListTile(
title: Text(i18n.isRestDay),
subtitle: Text(i18n.isRestDayHelp),
value: isRestDay,
contentPadding: const EdgeInsets.all(4),
onChanged: (value) {
setState(() {
isRestDay = value;
nameController.clear();
descriptionController.clear();
});
widget.day.isRest = value;
},
),
TextFormField(
enabled: !widget.day.isRest,
key: const Key('field-name'),
decoration: InputDecoration(
labelText: AppLocalizations.of(context).name,
Expand All @@ -195,6 +221,10 @@ class _DayFormWidgetState extends State<DayFormWidget> {
widget.day.name = value!;
},
validator: (value) {
if (widget.day.isRest) {
return null;
}

if (value!.isEmpty ||
value.length < Day.MIN_LENGTH_NAME ||
value.length > Day.MAX_LENGTH_NAME) {
Expand All @@ -207,19 +237,9 @@ class _DayFormWidgetState extends State<DayFormWidget> {
return null;
},
),
SwitchListTile(
title: const Text('is rest day'),
value: isRestDay,
contentPadding: const EdgeInsets.all(4),
onChanged: (value) {
setState(() {
isRestDay = value;
});
widget.day.isRest = value;
},
),
TextFormField(
key: const Key('field-description'),
enabled: !widget.day.isRest,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).description,
helperText: AppLocalizations.of(context).dayDescriptionHelp,
Expand All @@ -232,6 +252,10 @@ class _DayFormWidgetState extends State<DayFormWidget> {
minLines: 2,
maxLines: 10,
validator: (value) {
if (widget.day.isRest) {
return null;
}

if (value != null && value.length > Day.MAX_LENGTH_DESCRIPTION) {
return AppLocalizations.of(context).enterCharacters(0, Day.MAX_LENGTH_DESCRIPTION);
}
Expand Down Expand Up @@ -271,7 +295,8 @@ class _DayFormWidgetState extends State<DayFormWidget> {
}
},
),
ReorderableSlotList(widget.day.slots, widget.day.id!),
const SizedBox(height: 5),
ReorderableSlotList(widget.day.slots, widget.day),
],
),
);
Expand Down
14 changes: 9 additions & 5 deletions lib/widgets/routines/forms/routine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,21 @@ class _RoutineFormState extends State<RoutineForm> {

@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context);

return Form(
key: _form,
child: Column(
children: [
TextFormField(
key: const Key('field-name'),
decoration: InputDecoration(labelText: AppLocalizations.of(context).name),
decoration: InputDecoration(labelText: i18n.name),
controller: workoutNameController,
validator: (value) {
if (value!.isEmpty ||
value.length < Routine.MIN_LENGTH_NAME ||
value.length > Routine.MAX_LENGTH_NAME) {
return AppLocalizations.of(context).enterCharacters(
return i18n.enterCharacters(
Routine.MIN_LENGTH_NAME,
Routine.MAX_LENGTH_NAME,
);
Expand All @@ -68,13 +70,13 @@ class _RoutineFormState extends State<RoutineForm> {
),
TextFormField(
key: const Key('field-description'),
decoration: InputDecoration(labelText: AppLocalizations.of(context).description),
decoration: InputDecoration(labelText: i18n.description),
minLines: 3,
maxLines: 10,
controller: workoutDescriptionController,
validator: (value) {
if (value!.length > Routine.MAX_LENGTH_DESCRIPTION) {
return AppLocalizations.of(context).enterCharacters(
return i18n.enterCharacters(
Routine.MIN_LENGTH_DESCRIPTION,
Routine.MAX_LENGTH_DESCRIPTION,
);
Expand Down Expand Up @@ -172,7 +174,9 @@ class _RoutineFormState extends State<RoutineForm> {
},
),
SwitchListTile(
title: const Text('Fit in week'),
title: Text(i18n.fitInWeek),
subtitle: Text(i18n.fitInWeekHelp),
isThreeLine: true,
value: widget._routine.fitInWeek,
contentPadding: const EdgeInsets.all(4),
onChanged: (bool? value) {
Expand Down
Loading

0 comments on commit 94ed94c

Please sign in to comment.