From a53750e69172933e89e41604268a660405d12e19 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Wed, 15 Feb 2023 14:02:56 +0100 Subject: [PATCH 1/4] added settings model and file structure --- lib/service/business.dart | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lib/service/business.dart diff --git a/lib/service/business.dart b/lib/service/business.dart new file mode 100644 index 0000000..401af20 --- /dev/null +++ b/lib/service/business.dart @@ -0,0 +1,9 @@ +import 'package:smoke_cess_app/models/settings.dart'; + +class Business { + late Settings settings; + + void setSettings(Settings settings) { + this.settings = settings; + } +} From 0792eb1190efc086a6c4250815b5b4fa1aa51d8e Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Wed, 15 Feb 2023 14:03:02 +0100 Subject: [PATCH 2/4] wip --- lib/enums/group.dart | 6 ++++++ lib/models/settings.dart | 38 ++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 2 -- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 lib/enums/group.dart create mode 100644 lib/models/settings.dart diff --git a/lib/enums/group.dart b/lib/enums/group.dart new file mode 100644 index 0000000..f58dd58 --- /dev/null +++ b/lib/enums/group.dart @@ -0,0 +1,6 @@ +enum Group { + gruppe1, //HIIT Morgens + gruppe2, //HIIT Abends + gruppe3, //HIIT Morgens + Schach + gruppe4, //HIIT Abends + Schach +} diff --git a/lib/models/settings.dart b/lib/models/settings.dart new file mode 100644 index 0000000..9d98a9e --- /dev/null +++ b/lib/models/settings.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/enums/group.dart'; + +class Settings { + //should use shared preferences package + //https://pub.dev/packages/shared_preferences + Group _group; + TimeOfDay _dailyTrainingStartTime; + late DateTime _experimentStartDate; + + Settings(this._group, this._dailyTrainingStartTime) { + _experimentStartDate = DateTime.now(); + } + + void setGroup(Group group) { + _group = group; + } + + void setDailyTrainingStartTime(TimeOfDay time) { + _dailyTrainingStartTime = time; + } + + void set(Group group) { + _group = group; + } + + Group getGroup() { + return _group; + } + + TimeOfDay getDailyTrainingStartTime() { + return _dailyTrainingStartTime; + } + + DateTime getExperimentStartDate() { + return _experimentStartDate; + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 1364a5e..802d4a0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,6 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 @@ -53,7 +52,6 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. From d14dafe61ffbaa82453ad6210dcc4c727a268097 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Thu, 16 Feb 2023 01:59:15 +0100 Subject: [PATCH 3/4] added record models, settings- and db mock --- lib/enums/group.dart | 6 -- lib/interface/db_record.dart | 3 + lib/mock/db_mock.dart | 23 ++++++ lib/models/hiit_workout.dart | 15 ++++ lib/models/mood.dart | 14 ++++ lib/models/settings.dart | 38 --------- lib/models/sleep.dart | 18 ++++ lib/service/business.dart | 9 -- lib/service/query_service.dart | 21 +++++ lib/service/settings_service.dart | 25 ++++++ pubspec.lock | 132 ++++++++++++++++++++++++++++++ pubspec.yaml | 1 + 12 files changed, 252 insertions(+), 53 deletions(-) delete mode 100644 lib/enums/group.dart create mode 100644 lib/interface/db_record.dart create mode 100644 lib/mock/db_mock.dart create mode 100644 lib/models/hiit_workout.dart create mode 100644 lib/models/mood.dart delete mode 100644 lib/models/settings.dart create mode 100644 lib/models/sleep.dart delete mode 100644 lib/service/business.dart create mode 100644 lib/service/query_service.dart create mode 100644 lib/service/settings_service.dart diff --git a/lib/enums/group.dart b/lib/enums/group.dart deleted file mode 100644 index f58dd58..0000000 --- a/lib/enums/group.dart +++ /dev/null @@ -1,6 +0,0 @@ -enum Group { - gruppe1, //HIIT Morgens - gruppe2, //HIIT Abends - gruppe3, //HIIT Morgens + Schach - gruppe4, //HIIT Abends + Schach -} diff --git a/lib/interface/db_record.dart b/lib/interface/db_record.dart new file mode 100644 index 0000000..f5c56c8 --- /dev/null +++ b/lib/interface/db_record.dart @@ -0,0 +1,3 @@ +abstract class DatabaseRecord { + String toCSV(); +} diff --git a/lib/mock/db_mock.dart b/lib/mock/db_mock.dart new file mode 100644 index 0000000..1a92cf9 --- /dev/null +++ b/lib/mock/db_mock.dart @@ -0,0 +1,23 @@ +import 'package:smoke_cess_app/interface/db_record.dart'; +import 'package:smoke_cess_app/models/mood.dart'; +import 'package:smoke_cess_app/models/sleep.dart'; + +class DatabaseMock { + final List _moodRecords = []; + final List _sleepRecords = []; + final List _workoutRecords = []; + + void saveRecord(DatabaseRecord record) { + if (record is Mood) { + _moodRecords.add(record); + } else if (record is Sleep) { + _sleepRecords.add(record); + } else { + _workoutRecords.add(record); + } + } + + List getMoodRecords() => _moodRecords; + List getSleepRecords() => _sleepRecords; + List getWorkoutRecords() => _workoutRecords; +} diff --git a/lib/models/hiit_workout.dart b/lib/models/hiit_workout.dart new file mode 100644 index 0000000..9aa69eb --- /dev/null +++ b/lib/models/hiit_workout.dart @@ -0,0 +1,15 @@ +import 'package:smoke_cess_app/interface/db_record.dart'; + +class HIITWorkout implements DatabaseRecord { + final Duration _workoutDuration; + final String _commentBefore; + final String _commentAfter; + final DateTime _workoutDate; + + HIITWorkout(this._workoutDuration, this._commentBefore, this._commentAfter, + this._workoutDate); + + @override + String toCSV() => + "${_workoutDate.toIso8601String()}, $_workoutDuration, $_commentBefore, $_commentAfter"; +} diff --git a/lib/models/mood.dart b/lib/models/mood.dart new file mode 100644 index 0000000..d17061a --- /dev/null +++ b/lib/models/mood.dart @@ -0,0 +1,14 @@ +import 'package:smoke_cess_app/interface/db_record.dart'; + +class Mood implements DatabaseRecord { + final double _moodValue; + final String _comment; + final DateTime _date; + + Mood(this._moodValue, this._comment, this._date); + + @override + String toCSV() { + return "${_date.toIso8601String()}, ${_moodValue.round().toString()}, $_comment"; + } +} diff --git a/lib/models/settings.dart b/lib/models/settings.dart deleted file mode 100644 index 9d98a9e..0000000 --- a/lib/models/settings.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:smoke_cess_app/enums/group.dart'; - -class Settings { - //should use shared preferences package - //https://pub.dev/packages/shared_preferences - Group _group; - TimeOfDay _dailyTrainingStartTime; - late DateTime _experimentStartDate; - - Settings(this._group, this._dailyTrainingStartTime) { - _experimentStartDate = DateTime.now(); - } - - void setGroup(Group group) { - _group = group; - } - - void setDailyTrainingStartTime(TimeOfDay time) { - _dailyTrainingStartTime = time; - } - - void set(Group group) { - _group = group; - } - - Group getGroup() { - return _group; - } - - TimeOfDay getDailyTrainingStartTime() { - return _dailyTrainingStartTime; - } - - DateTime getExperimentStartDate() { - return _experimentStartDate; - } -} diff --git a/lib/models/sleep.dart b/lib/models/sleep.dart new file mode 100644 index 0000000..f94be2e --- /dev/null +++ b/lib/models/sleep.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/interface/db_record.dart'; + +class Sleep implements DatabaseRecord { + final double _sleepQualityValue; + final String _comment; + final DateTime _date; + final TimeOfDay _sleepedAt; + final TimeOfDay _wokeUpAt; + + Sleep(this._sleepQualityValue, this._comment, this._date, this._sleepedAt, + this._wokeUpAt); + + @override + String toCSV() { + return "${_date.toIso8601String()}, ${_sleepQualityValue.round().toString()}, $_sleepedAt, $_wokeUpAt, $_comment"; + } +} diff --git a/lib/service/business.dart b/lib/service/business.dart deleted file mode 100644 index 401af20..0000000 --- a/lib/service/business.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:smoke_cess_app/models/settings.dart'; - -class Business { - late Settings settings; - - void setSettings(Settings settings) { - this.settings = settings; - } -} diff --git a/lib/service/query_service.dart b/lib/service/query_service.dart new file mode 100644 index 0000000..fc4f5a3 --- /dev/null +++ b/lib/service/query_service.dart @@ -0,0 +1,21 @@ +import 'package:smoke_cess_app/interface/db_record.dart'; +import 'package:smoke_cess_app/mock/db_mock.dart'; + +class QueryService { + final DatabaseMock _database; + + QueryService(this._database); + + void addRecord(DatabaseRecord record) => _database.saveRecord(record); + List getWorkoutRecords() => _database.getWorkoutRecords(); + List getMoodRecords() => _database.getMoodRecords(); + List getSleepRecords() => _database.getSleepRecords(); + + String recordsToCSV(List records) { + String csv = ""; + for (DatabaseRecord record in records) { + csv += '${record.toCSV()}\n'; + } + return csv; + } +} diff --git a/lib/service/settings_service.dart b/lib/service/settings_service.dart new file mode 100644 index 0000000..ebd5b05 --- /dev/null +++ b/lib/service/settings_service.dart @@ -0,0 +1,25 @@ +import 'package:shared_preferences/shared_preferences.dart'; + +class SettingsService { + final Future _prefs = SharedPreferences.getInstance(); + + SettingsService() { + setIntSetting('workout_duration_minutes', 5); + } + + void setStringSetting(String settingKey, String settingValue) => + _prefs.then((pref) => pref.setString(settingKey, settingValue)); + + Future getStringSetting(String settingKey) => + _prefs.then((pref) => pref.getString(settingKey)); + + void setIntSetting(String settingKey, int settingValue) => + _prefs.then((pref) => pref.setInt(settingKey, settingValue)); + + Future getIntSetting(String settingKey) => + _prefs.then((pref) => pref.getInt(settingKey)); + + //Add other setters and getters if needed + //other possible SharedPreferences Types: Int, Bool, Double, StringList + //see https://pub.dev/packages/shared_preferences +} diff --git a/pubspec.lock b/pubspec.lock index e9b9197..1cda953 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -50,6 +50,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.4" flutter: dependency: "direct main" description: flutter @@ -67,6 +81,18 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" lints: dependency: transitive description: @@ -102,6 +128,97 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.2" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.8" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.4" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.17" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.15" + shared_preferences_foundation: + dependency: transitive + description: + name: shared_preferences_foundation + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" sky_engine: dependency: transitive description: flutter @@ -156,5 +273,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.3" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" sdks: dart: ">=2.18.2 <3.0.0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 802d4a0..ea481f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 + shared_preferences: ^2.0.17 dev_dependencies: flutter_test: From 33485054903fa46dd66ca78a17a1ace9861f45b3 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Thu, 16 Feb 2023 02:08:15 +0100 Subject: [PATCH 4/4] use settings in timer page --- lib/pages/timer_page.dart | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/pages/timer_page.dart b/lib/pages/timer_page.dart index 899f862..691d15d 100644 --- a/lib/pages/timer_page.dart +++ b/lib/pages/timer_page.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/service/settings_service.dart'; import 'package:smoke_cess_app/widgets/timer_button.dart'; class StopWatchTimerPage extends StatefulWidget { @@ -10,15 +11,26 @@ class StopWatchTimerPage extends StatefulWidget { } class StopWatchTimerPageState extends State { - static const countdownDuration = Duration(minutes: 1); - Duration duration = countdownDuration; + SettingsService settings = SettingsService(); + Duration duration = const Duration(minutes: 1); Timer? timer; bool countDown = true; + @override + void initState() { + setDurationWithSetting(); + super.initState(); + } + + void setDurationWithSetting() { + settings.getIntSetting('workout_duration_minutes').then((workoutMinutes) => + {setState(() => duration = Duration(minutes: workoutMinutes ?? 10))}); + } + void reset() { if (countDown) { - setState(() => duration = countdownDuration); + setDurationWithSetting(); } else { setState(() => duration = const Duration()); }