Enabled Webuntis Holiday query Implemented Holiday view in Timetable Hide other special time regions like breaks when shown in holiday
This commit is contained in:
@ -31,10 +31,10 @@ class _TimeRegionComponentState extends State<TimeRegionComponent> {
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 5),
|
||||
const SizedBox(height: 15),
|
||||
const Icon(Icons.cake),
|
||||
const Text("FREI"),
|
||||
const SizedBox(height: 5),
|
||||
const SizedBox(height: 10),
|
||||
RotatedBox(
|
||||
quarterTurns: 1,
|
||||
child: Text(
|
||||
|
@ -2,6 +2,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/extensions/dateTime.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||
|
||||
@ -154,46 +155,68 @@ class _TimetableState extends State<Timetable> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
List<TimeRegion> _buildSpecialTimeRegions(GetHolidaysResponse holidays, ) {
|
||||
List<TimeRegion> _buildSpecialTimeRegions(GetHolidaysResponse holidays) {
|
||||
DateTime lastMonday = DateTime.now().subtract(Duration(days: DateTime.now().weekday - 1));
|
||||
DateTime firstBreak = lastMonday.copyWith(hour: 10, minute: 15);
|
||||
DateTime secondBreak = lastMonday.copyWith(hour: 13, minute: 50);
|
||||
DateTime beforeSchool = lastMonday.copyWith(hour: 7, minute: 30);
|
||||
|
||||
return [
|
||||
...holidays.result.map((e) {
|
||||
return TimeRegion(
|
||||
startTime: _parseWebuntisTimestamp(e.startDate, 755),
|
||||
endTime: _parseWebuntisTimestamp(e.startDate, 1630),
|
||||
text: 'holiday:${e.name}',
|
||||
color: Theme.of(context).disabledColor.withAlpha(50),
|
||||
iconData: Icons.holiday_village_outlined
|
||||
);
|
||||
}),
|
||||
Iterable<TimeRegion> holidayList = holidays.result.map((holiday) {
|
||||
DateTime startDay = _parseWebuntisTimestamp(holiday.startDate, 0);
|
||||
int dayCount = _parseWebuntisTimestamp(holiday.endDate, 0)
|
||||
.difference(startDay)
|
||||
.inDays;
|
||||
List<DateTime> days = List.generate(dayCount, (index) => startDay.add(Duration(days: index)));
|
||||
|
||||
TimeRegion(
|
||||
startTime: firstBreak,
|
||||
endTime: firstBreak.add(const Duration(minutes: 20)),
|
||||
return days.map((holidayDay) {
|
||||
return TimeRegion(
|
||||
startTime: holidayDay.copyWith(hour: 07, minute: 55),
|
||||
endTime: holidayDay.copyWith(hour: 16, minute: 30),
|
||||
text: 'holiday:${holiday.name}',
|
||||
color: Theme
|
||||
.of(context)
|
||||
.disabledColor
|
||||
.withAlpha(50),
|
||||
iconData: Icons.holiday_village_outlined
|
||||
);
|
||||
});
|
||||
}).expand((e) => e);
|
||||
|
||||
bool isInHoliday(DateTime time) {
|
||||
return holidayList.any((element) => element.startTime.isSameDay(time));
|
||||
}
|
||||
|
||||
return [
|
||||
...holidayList,
|
||||
|
||||
if(!isInHoliday(firstBreak))
|
||||
TimeRegion(
|
||||
startTime: firstBreak,
|
||||
endTime: firstBreak.add(const Duration(minutes: 20)),
|
||||
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||
text: 'centerIcon',
|
||||
color: Theme.of(context).primaryColor.withAlpha(50),
|
||||
iconData: Icons.restaurant
|
||||
),
|
||||
|
||||
if(!isInHoliday(secondBreak))
|
||||
TimeRegion(
|
||||
startTime: secondBreak,
|
||||
endTime: secondBreak.add(const Duration(minutes: 15)),
|
||||
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||
text: 'centerIcon',
|
||||
color: Theme.of(context).primaryColor.withAlpha(50),
|
||||
iconData: Icons.restaurant
|
||||
),
|
||||
|
||||
if(!isInHoliday(beforeSchool))
|
||||
TimeRegion(
|
||||
startTime: beforeSchool,
|
||||
endTime: beforeSchool.add(const Duration(minutes: 25)),
|
||||
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||
text: 'centerIcon',
|
||||
color: Theme.of(context).primaryColor.withAlpha(50),
|
||||
iconData: Icons.restaurant
|
||||
),
|
||||
TimeRegion(
|
||||
startTime: secondBreak,
|
||||
endTime: secondBreak.add(const Duration(minutes: 15)),
|
||||
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||
text: 'centerIcon',
|
||||
color: Theme.of(context).primaryColor.withAlpha(50),
|
||||
iconData: Icons.restaurant
|
||||
),
|
||||
TimeRegion(
|
||||
startTime: beforeSchool,
|
||||
endTime: beforeSchool.add(const Duration(minutes: 25)),
|
||||
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||
color: Theme.of(context).disabledColor.withAlpha(50),
|
||||
text: "centerIcon",
|
||||
),
|
||||
color: Theme.of(context).disabledColor.withAlpha(50),
|
||||
text: "centerIcon",
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user