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/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/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()); } 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 1364a5e..ea481f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,10 +32,10 @@ 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 + shared_preferences: ^2.0.17 dev_dependencies: flutter_test: @@ -53,7 +53,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.