add startedAt Settingsproperty
parent
a5596b0934
commit
d9272bdfb2
|
@ -6,9 +6,10 @@ class Settings {
|
||||||
final QueryConfig? moodQuery;
|
final QueryConfig? moodQuery;
|
||||||
final QueryConfig? sleepQuery;
|
final QueryConfig? sleepQuery;
|
||||||
final TimeConfig? chessTime;
|
final TimeConfig? chessTime;
|
||||||
|
final DateTime startedAt;
|
||||||
|
|
||||||
Settings(this.group, this.relapseCategories, this.moodQuery, this.sleepQuery,
|
Settings(this.group, this.relapseCategories, this.moodQuery, this.sleepQuery,
|
||||||
this.chessTime);
|
this.chessTime, this.startedAt);
|
||||||
|
|
||||||
Settings.fromJson(Map<String, dynamic> json)
|
Settings.fromJson(Map<String, dynamic> json)
|
||||||
: group = json['group'] as int,
|
: group = json['group'] as int,
|
||||||
|
@ -17,7 +18,8 @@ class Settings {
|
||||||
sleepQuery = QueryConfig.fromJson(json['sleep_query']),
|
sleepQuery = QueryConfig.fromJson(json['sleep_query']),
|
||||||
chessTime = json['chess_time'] != null
|
chessTime = json['chess_time'] != null
|
||||||
? TimeConfig.fromJson(json['chess_time'])
|
? TimeConfig.fromJson(json['chess_time'])
|
||||||
: null;
|
: null,
|
||||||
|
startedAt = DateTime.parse(json['startedAt']);
|
||||||
}
|
}
|
||||||
|
|
||||||
class QueryConfig {
|
class QueryConfig {
|
||||||
|
|
|
@ -23,6 +23,8 @@ Future<int?> getMoodQueryMinutes() => _getIntSetting('mood_query_minutes');
|
||||||
Future<int?> getChessHours() => _getIntSetting('chess_hours');
|
Future<int?> getChessHours() => _getIntSetting('chess_hours');
|
||||||
Future<int?> getChessMinutes() => _getIntSetting('chess_minutes');
|
Future<int?> getChessMinutes() => _getIntSetting('chess_minutes');
|
||||||
|
|
||||||
|
Future<String?> getStartDay() => _getStringSetting('startedAt');
|
||||||
|
|
||||||
void _setIntSetting(String settingKey, int settingValue) =>
|
void _setIntSetting(String settingKey, int settingValue) =>
|
||||||
SharedPreferences.getInstance()
|
SharedPreferences.getInstance()
|
||||||
.then((pref) => pref.setInt(settingKey, settingValue));
|
.then((pref) => pref.setInt(settingKey, settingValue));
|
||||||
|
@ -30,6 +32,13 @@ void _setIntSetting(String settingKey, int settingValue) =>
|
||||||
Future<int?> _getIntSetting(String settingKey) =>
|
Future<int?> _getIntSetting(String settingKey) =>
|
||||||
SharedPreferences.getInstance().then((pref) => pref.getInt(settingKey));
|
SharedPreferences.getInstance().then((pref) => pref.getInt(settingKey));
|
||||||
|
|
||||||
|
void _setStringSetting(String settingKey, String settingValue) =>
|
||||||
|
SharedPreferences.getInstance()
|
||||||
|
.then((pref) => pref.setString(settingKey, settingValue));
|
||||||
|
|
||||||
|
Future<String?> _getStringSetting(String settingKey) =>
|
||||||
|
SharedPreferences.getInstance().then((pref) => pref.getString(settingKey));
|
||||||
|
|
||||||
void _setStringListSetting(String settingKey, List<String> list) =>
|
void _setStringListSetting(String settingKey, List<String> list) =>
|
||||||
SharedPreferences.getInstance()
|
SharedPreferences.getInstance()
|
||||||
.then((pref) => pref.setStringList(settingKey, list));
|
.then((pref) => pref.setStringList(settingKey, list));
|
||||||
|
@ -40,6 +49,7 @@ Future<List<String>?> _getStringListSetting(String settingKey) =>
|
||||||
|
|
||||||
Future<void> loadSettingsFromLocalJSON() async {
|
Future<void> loadSettingsFromLocalJSON() async {
|
||||||
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
||||||
|
configJSON['startedAt'] = DateTime.now().toIso8601String();
|
||||||
Settings settings = Settings.fromJson(configJSON);
|
Settings settings = Settings.fromJson(configJSON);
|
||||||
saveSettings(settings);
|
saveSettings(settings);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +63,7 @@ void saveSettings(Settings settings) {
|
||||||
_setStringListSetting('sleep_query_days', settings.sleepQuery!.days!);
|
_setStringListSetting('sleep_query_days', settings.sleepQuery!.days!);
|
||||||
_setIntSetting('sleep_query_hours', settings.sleepQuery!.hours!);
|
_setIntSetting('sleep_query_hours', settings.sleepQuery!.hours!);
|
||||||
_setIntSetting('sleep_query_minutes', settings.sleepQuery!.minutes!);
|
_setIntSetting('sleep_query_minutes', settings.sleepQuery!.minutes!);
|
||||||
|
_setStringSetting('startedAt', DateTime.now().toIso8601String());
|
||||||
if (settings.chessTime != null) {
|
if (settings.chessTime != null) {
|
||||||
_setIntSetting('chess_hours', settings.chessTime!.hours!);
|
_setIntSetting('chess_hours', settings.chessTime!.hours!);
|
||||||
_setIntSetting('chess_minutes', settings.chessTime!.minutes!);
|
_setIntSetting('chess_minutes', settings.chessTime!.minutes!);
|
||||||
|
@ -70,6 +81,8 @@ Future<Settings?> loadSettings() async {
|
||||||
List<String>? sleepDays = await getSleepQueryDaysCategories();
|
List<String>? sleepDays = await getSleepQueryDaysCategories();
|
||||||
int? chessHours = await getChessHours();
|
int? chessHours = await getChessHours();
|
||||||
int? chessMinutes = await getChessMinutes();
|
int? chessMinutes = await getChessMinutes();
|
||||||
|
DateTime startedAt =
|
||||||
|
DateTime.parse(await getStartDay() ?? DateTime.now().toIso8601String());
|
||||||
|
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
return Settings(
|
return Settings(
|
||||||
|
@ -77,7 +90,8 @@ Future<Settings?> loadSettings() async {
|
||||||
relapseCategories,
|
relapseCategories,
|
||||||
QueryConfig(moodHours, moodMinutes, moodDays),
|
QueryConfig(moodHours, moodMinutes, moodDays),
|
||||||
QueryConfig(sleepHours, sleepMinutes, sleepDays),
|
QueryConfig(sleepHours, sleepMinutes, sleepDays),
|
||||||
TimeConfig(chessHours, chessMinutes));
|
TimeConfig(chessHours, chessMinutes),
|
||||||
|
startedAt);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue