diff --git a/lib/providers/input_provider.dart b/lib/providers/input_provider.dart index 3bd473f..b8aed63 100644 --- a/lib/providers/input_provider.dart +++ b/lib/providers/input_provider.dart @@ -4,12 +4,17 @@ import 'package:smoke_cess_app/models/relapse.dart'; import 'package:smoke_cess_app/models/sleep.dart'; import '../globals.dart' as globals; +enum SleepTimes { + wokeUpAt, + sleptAt, +} + class InputProvider extends ChangeNotifier { double _sliderValue = 50; final TextEditingController _textController = TextEditingController(text: ''); - final Map _times = { - 'wokeUpAt': const TimeOfDay(hour: 8, minute: 0), - 'sleptAt': const TimeOfDay(hour: 22, minute: 0), + final Map _times = { + SleepTimes.wokeUpAt: const TimeOfDay(hour: 8, minute: 0), + SleepTimes.sleptAt: const TimeOfDay(hour: 22, minute: 0), }; String relapseCategory = ''; @@ -21,11 +26,11 @@ class InputProvider extends ChangeNotifier { notifyListeners(); } - TimeOfDay getTimeEntry(String key) { + TimeOfDay getTimeEntry(SleepTimes key) { return _times[key] ?? const TimeOfDay(hour: 12, minute: 0); } - void setTime(String key, TimeOfDay time) { + void setTime(SleepTimes key, TimeOfDay time) { _times[key] = time; notifyListeners(); } @@ -33,8 +38,8 @@ class InputProvider extends ChangeNotifier { void _resetFields() { _sliderValue = 50; _textController.text = ''; - setTime('wokeUpAt', const TimeOfDay(hour: 8, minute: 0)); - setTime('sleptAt', const TimeOfDay(hour: 22, minute: 0)); + setTime(SleepTimes.wokeUpAt, const TimeOfDay(hour: 8, minute: 0)); + setTime(SleepTimes.sleptAt, const TimeOfDay(hour: 22, minute: 0)); notifyListeners(); } @@ -52,7 +57,7 @@ class InputProvider extends ChangeNotifier { return globals.databaseService.addRelapse(relapse); } - Future saveSleep(String wokeUpKey, String sleptKey) { + Future saveSleep(SleepTimes wokeUpKey, SleepTimes sleptKey) { Sleep sleep = Sleep(_sliderValue.toInt(), _textController.text, DateTime.now(), getTimeEntry(sleptKey), getTimeEntry(wokeUpKey)); _resetFields(); diff --git a/lib/providers/workout_provider.dart b/lib/providers/workout_provider.dart index 5d85c18..ebcaf9c 100644 --- a/lib/providers/workout_provider.dart +++ b/lib/providers/workout_provider.dart @@ -5,6 +5,13 @@ import 'package:smoke_cess_app/providers/audio_provider.dart'; import 'package:smoke_cess_app/providers/timer_provider.dart'; import '../globals.dart' as globals; +enum WorkoutPhases { + warmUp, + highIntensity, + lowIntensity, + coolDown, +} + class WorkoutProvider extends ChangeNotifier { final TimerProvider timerProvider; final AudioProvider audioProvider; @@ -15,21 +22,21 @@ class WorkoutProvider extends ChangeNotifier { int motivationAfter = 50; int _workoutPhaseIndex = 0; - final List _workoutPhases = [ - 'Warm-Up', - 'High Intensity', - 'Low Intensity', - 'High Intensity', - 'Low Intensity', - 'High Intensity', - 'Low Intensity', - 'High Intensity', - 'Cool-down' + final List _workoutPhases = [ + WorkoutPhases.warmUp, + WorkoutPhases.highIntensity, + WorkoutPhases.lowIntensity, + WorkoutPhases.highIntensity, + WorkoutPhases.lowIntensity, + WorkoutPhases.highIntensity, + WorkoutPhases.lowIntensity, + WorkoutPhases.highIntensity, + WorkoutPhases.coolDown, ]; WorkoutProvider(this.timerProvider, this.audioProvider); - String get currentPhase => _workoutPhases[_workoutPhaseIndex]; + WorkoutPhases get currentPhase => _workoutPhases[_workoutPhaseIndex]; Duration get currentPhaseDuration => _workoutPhaseSettings[currentPhase]!['duration']; bool get isPhaseComplete => @@ -37,6 +44,7 @@ class WorkoutProvider extends ChangeNotifier { Color get currentPhaseColor => _workoutPhaseSettings[currentPhase]!['color']; AssetSource get currentPhaseSource => _workoutPhaseSettings[currentPhase]!['source']; + String get currentPhaseTitle => _workoutPhaseSettings[currentPhase]!['title']; void nextPhase() { if (_workoutPhaseIndex < _workoutPhases.length - 1) { @@ -89,23 +97,27 @@ class WorkoutProvider extends ChangeNotifier { } } -Map> _workoutPhaseSettings = { - 'Warm-Up': { +Map> _workoutPhaseSettings = { + WorkoutPhases.warmUp: { + 'title': 'Warm Up', 'duration': const Duration(seconds: 5), 'source': AssetSource('warmUp.mp3'), 'color': Colors.green }, - 'High Intensity': { + WorkoutPhases.highIntensity: { + 'title': 'High Intensity', 'duration': const Duration(seconds: 4), 'source': AssetSource('workout.mp3'), 'color': Colors.red }, - 'Low Intensity': { + WorkoutPhases.lowIntensity: { + 'title': 'Low Intensity', 'duration': const Duration(seconds: 3), 'source': AssetSource('workout.mp3'), 'color': Colors.orange }, - 'Cool-down': { + WorkoutPhases.coolDown: { + 'title': 'Cool Down', 'duration': const Duration(seconds: 5), 'source': AssetSource('cool_down.mp3'), 'color': Colors.blue diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index ad033ba..4996da7 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -17,20 +17,18 @@ class SleepForm extends StatelessWidget { Widget build(BuildContext context) { InputProvider inputModel = context.watch(); TasksProvider tasksModel = context.watch(); - String wokeUpKey = 'wokeUpAt'; - String sleptKey = 'sleptAt'; return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - ElevatedCard( + const ElevatedCard( title: 'Einschlafzeit', - child: TimePicker(sleptKey), + child: TimePicker(SleepTimes.sleptAt), ), const SizedBox(height: 16), - ElevatedCard( + const ElevatedCard( title: 'Aufwachzeit', - child: TimePicker(wokeUpKey), + child: TimePicker(SleepTimes.wokeUpAt), ), const SizedBox(height: 16), const ElevatedCard( @@ -46,7 +44,8 @@ class SleepForm extends StatelessWidget { height: 80, ), SubmitFormButton( - submitCallback: () => inputModel.saveSleep(wokeUpKey, sleptKey), + submitCallback: () => + inputModel.saveSleep(SleepTimes.wokeUpAt, SleepTimes.sleptAt), updateTasks: () => tasksModel.setTaskDone(Pages.mood), ) ], diff --git a/lib/widgets/timepicker.dart b/lib/widgets/timepicker.dart index 0b0926b..d6ab447 100644 --- a/lib/widgets/timepicker.dart +++ b/lib/widgets/timepicker.dart @@ -3,7 +3,7 @@ import 'package:smoke_cess_app/providers/input_provider.dart'; import 'package:provider/provider.dart'; class TimePicker extends StatelessWidget { - final String keyMap; + final SleepTimes keyMap; const TimePicker(this.keyMap, {super.key}); diff --git a/lib/widgets/workout_timer_widget.dart b/lib/widgets/workout_timer_widget.dart index c47bbf5..4f1b64c 100644 --- a/lib/widgets/workout_timer_widget.dart +++ b/lib/widgets/workout_timer_widget.dart @@ -62,7 +62,7 @@ class WorkoutTimerWidget extends StatelessWidget { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text(workoutProvider.currentPhase), + Text(workoutProvider.currentPhaseTitle), const SizedBox( height: 20, ),