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:
Elias Müller 2024-01-07 21:19:39 +01:00
parent dce569cb99
commit b99769e192
5 changed files with 76 additions and 51 deletions

View File

@ -0,0 +1,5 @@
extension IsSameDay on DateTime {
bool isSameDay(DateTime other) {
return year == other.year && month == other.month && day == other.day;
}
}

View File

@ -1,8 +1,7 @@
import 'dart:convert';
import 'package:intl/intl.dart';
import '../../api/apiResponse.dart';
import '../../api/webuntis/queries/getHolidays/getHolidaysCache.dart';
import '../../api/webuntis/queries/getHolidays/getHolidaysResponse.dart';
import '../../api/webuntis/queries/getRooms/getRoomsCache.dart';
import '../../api/webuntis/queries/getRooms/getRoomsResponse.dart';
@ -79,15 +78,16 @@ class TimetableProps extends DataHolder {
}
);
// GetHolidaysCache( // TODO is this fixed by webuntis? miese kriese
// onUpdate: (GetHolidaysResponse data) => {
// _getHolidaysResponse = data,
// notifyListeners(),
// }
// );
_getHolidaysResponse = GetHolidaysResponse.fromJson(jsonDecode("""
{"jsonrpc":"2.0","id":"ID","result":[]}
"""));
GetHolidaysCache( // This broke in the past. Below here is backup simulation for an empty holiday block
onUpdate: (GetHolidaysResponse data) => {
_getHolidaysResponse = data,
notifyListeners(),
}
);
// _getHolidaysResponse = GetHolidaysResponse.fromJson(jsonDecode("""
// {"jsonrpc":"2.0","id":"ID","result":[]}
// """));
notifyListeners();
}

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:loader_overlay/loader_overlay.dart';
import 'package:marianum_mobile/extensions/dateTime.dart';
import 'package:provider/provider.dart';
import '../../../api/marianumcloud/talk/chat/getChatResponse.dart';
@ -39,10 +40,6 @@ class _ChatViewState extends State<ChatView> {
Provider.of<ChatProps>(context, listen: false).setQueryToken(widget.room.token);
}
bool isSameDay(DateTime date1, DateTime date2) {
return date1.year == date2.year && date1.month == date2.month && date1.day == date2.day;
}
@override
Widget build(BuildContext context) {
return Consumer<ChatProps>(
@ -57,7 +54,7 @@ class _ChatViewState extends State<ChatView> {
if(element.systemMessage.contains("reaction")) return;
if(!isSameDay(elementDate, lastDate)) {
if(!elementDate.isSameDay(lastDate)) {
lastDate = elementDate;
messages.add(ChatBubble(
context: context,

View File

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

View File

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