Convert Settings to Notificationdates
parent
de7361f9ad
commit
3f3cc26325
|
@ -0,0 +1,57 @@
|
||||||
|
import 'package:smoke_cess_app/service/settings_service.dart';
|
||||||
|
import 'package:timezone/timezone.dart';
|
||||||
|
|
||||||
|
const int trainingTime = 40;
|
||||||
|
|
||||||
|
const weekDays = {
|
||||||
|
"Montag": 1,
|
||||||
|
"Dienstag": 2,
|
||||||
|
"Mittwoch": 3,
|
||||||
|
"Donnerstag": 4,
|
||||||
|
"Freitag": 5,
|
||||||
|
"Samstag": 6,
|
||||||
|
"Sonntag": 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
Future<List<TZDateTime>> getDatesforAll() async {
|
||||||
|
List<TZDateTime> allDates = [];
|
||||||
|
List<TZDateTime> moodDates = await getDatesforMood();
|
||||||
|
List<TZDateTime> sleepDates = await getDatesforSleep();
|
||||||
|
allDates.addAll(moodDates);
|
||||||
|
allDates.addAll(sleepDates);
|
||||||
|
return allDates;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<TZDateTime>> getDatesforMood() async {
|
||||||
|
final List<String>? selectedDays = await getMoodQueryDaysCategories();
|
||||||
|
final int? selectedHours = await getMoodQueryHours();
|
||||||
|
final int? selectedMinutes = await getMoodQueryMinutes();
|
||||||
|
return createTZDateTimes(selectedDays, selectedHours, selectedMinutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<TZDateTime>> getDatesforSleep() async {
|
||||||
|
final List<String>? selectedDays = await getSleepQueryDaysCategories();
|
||||||
|
final int? selectedHours = await getSleepQueryHours();
|
||||||
|
final int? selectedMinutes = await getSleepQueryMinutes();
|
||||||
|
return createTZDateTimes(selectedDays, selectedHours, selectedMinutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TZDateTime> createTZDateTimes(
|
||||||
|
List<String>? selectedDays, int? selectedHours, int? selectedMinutes) {
|
||||||
|
List<TZDateTime> tzDateTimes = [];
|
||||||
|
if (selectedDays == null ||
|
||||||
|
selectedHours == null ||
|
||||||
|
selectedMinutes == null) {
|
||||||
|
return tzDateTimes;
|
||||||
|
}
|
||||||
|
final Iterable<int?> selectedDaysInt =
|
||||||
|
selectedDays.map((day) => weekDays[day]);
|
||||||
|
for (int i = 0; i < trainingTime; i++) {
|
||||||
|
final DateTime date = DateTime.now().add(Duration(days: i));
|
||||||
|
if (selectedDaysInt.contains(date.weekday)) {
|
||||||
|
tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day,
|
||||||
|
selectedHours, selectedMinutes, 0, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tzDateTimes;
|
||||||
|
}
|
Loading…
Reference in New Issue