Merge branch 'feature/ZI-1/backend-mock' into 'main'

Feature/zi 1/backend mock

See merge request Crondung/hsma_cpd!3
main
Parricc35 2023-02-16 10:04:55 +00:00
commit 4b2e900bda
10 changed files with 267 additions and 5 deletions

View File

@ -0,0 +1,3 @@
abstract class DatabaseRecord {
String toCSV();
}

View File

@ -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<DatabaseRecord> _moodRecords = [];
final List<DatabaseRecord> _sleepRecords = [];
final List<DatabaseRecord> _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<DatabaseRecord> getMoodRecords() => _moodRecords;
List<DatabaseRecord> getSleepRecords() => _sleepRecords;
List<DatabaseRecord> getWorkoutRecords() => _workoutRecords;
}

View File

@ -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";
}

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -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<StopWatchTimerPage> {
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());
}

View File

@ -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<DatabaseRecord> getWorkoutRecords() => _database.getWorkoutRecords();
List<DatabaseRecord> getMoodRecords() => _database.getMoodRecords();
List<DatabaseRecord> getSleepRecords() => _database.getSleepRecords();
String recordsToCSV(List<DatabaseRecord> records) {
String csv = "";
for (DatabaseRecord record in records) {
csv += '${record.toCSV()}\n';
}
return csv;
}
}

View File

@ -0,0 +1,25 @@
import 'package:shared_preferences/shared_preferences.dart';
class SettingsService {
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
SettingsService() {
setIntSetting('workout_duration_minutes', 5);
}
void setStringSetting(String settingKey, String settingValue) =>
_prefs.then((pref) => pref.setString(settingKey, settingValue));
Future<String?> getStringSetting(String settingKey) =>
_prefs.then((pref) => pref.getString(settingKey));
void setIntSetting(String settingKey, int settingValue) =>
_prefs.then((pref) => pref.setInt(settingKey, settingValue));
Future<int?> 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
}

View File

@ -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"

View File

@ -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.