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:
parent
dce569cb99
commit
591bbbeb45
5
lib/extensions/dateTime.dart
Normal file
5
lib/extensions/dateTime.dart
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
extension IsSameDay on DateTime {
|
||||||
|
bool isSameDay(DateTime other) {
|
||||||
|
return year == other.year && month == other.month && day == other.day;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,7 @@
|
|||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
import '../../api/apiResponse.dart';
|
import '../../api/apiResponse.dart';
|
||||||
|
import '../../api/webuntis/queries/getHolidays/getHolidaysCache.dart';
|
||||||
import '../../api/webuntis/queries/getHolidays/getHolidaysResponse.dart';
|
import '../../api/webuntis/queries/getHolidays/getHolidaysResponse.dart';
|
||||||
import '../../api/webuntis/queries/getRooms/getRoomsCache.dart';
|
import '../../api/webuntis/queries/getRooms/getRoomsCache.dart';
|
||||||
import '../../api/webuntis/queries/getRooms/getRoomsResponse.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
|
GetHolidaysCache( // This broke in the past. Below here is backup simulation for an empty holiday block
|
||||||
// onUpdate: (GetHolidaysResponse data) => {
|
onUpdate: (GetHolidaysResponse data) => {
|
||||||
// _getHolidaysResponse = data,
|
_getHolidaysResponse = data,
|
||||||
// notifyListeners(),
|
notifyListeners(),
|
||||||
// }
|
}
|
||||||
// );
|
);
|
||||||
_getHolidaysResponse = GetHolidaysResponse.fromJson(jsonDecode("""
|
// _getHolidaysResponse = GetHolidaysResponse.fromJson(jsonDecode("""
|
||||||
{"jsonrpc":"2.0","id":"ID","result":[]}
|
// {"jsonrpc":"2.0","id":"ID","result":[]}
|
||||||
"""));
|
// """));
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:loader_overlay/loader_overlay.dart';
|
import 'package:loader_overlay/loader_overlay.dart';
|
||||||
|
import 'package:marianum_mobile/extensions/dateTime.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../../../api/marianumcloud/talk/chat/getChatResponse.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);
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Consumer<ChatProps>(
|
return Consumer<ChatProps>(
|
||||||
@ -57,7 +54,7 @@ class _ChatViewState extends State<ChatView> {
|
|||||||
|
|
||||||
if(element.systemMessage.contains("reaction")) return;
|
if(element.systemMessage.contains("reaction")) return;
|
||||||
|
|
||||||
if(!isSameDay(elementDate, lastDate)) {
|
if(!elementDate.isSameDay(lastDate)) {
|
||||||
lastDate = elementDate;
|
lastDate = elementDate;
|
||||||
messages.add(ChatBubble(
|
messages.add(ChatBubble(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -31,10 +31,10 @@ class _TimeRegionComponentState extends State<TimeRegionComponent> {
|
|||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 15),
|
||||||
const Icon(Icons.cake),
|
const Icon(Icons.cake),
|
||||||
const Text("FREI"),
|
const Text("FREI"),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 10),
|
||||||
RotatedBox(
|
RotatedBox(
|
||||||
quarterTurns: 1,
|
quarterTurns: 1,
|
||||||
child: Text(
|
child: Text(
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:marianum_mobile/extensions/dateTime.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
||||||
|
|
||||||
@ -154,46 +155,68 @@ class _TimetableState extends State<Timetable> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TimeRegion> _buildSpecialTimeRegions(GetHolidaysResponse holidays, ) {
|
List<TimeRegion> _buildSpecialTimeRegions(GetHolidaysResponse holidays) {
|
||||||
DateTime lastMonday = DateTime.now().subtract(Duration(days: DateTime.now().weekday - 1));
|
DateTime lastMonday = DateTime.now().subtract(Duration(days: DateTime.now().weekday - 1));
|
||||||
DateTime firstBreak = lastMonday.copyWith(hour: 10, minute: 15);
|
DateTime firstBreak = lastMonday.copyWith(hour: 10, minute: 15);
|
||||||
DateTime secondBreak = lastMonday.copyWith(hour: 13, minute: 50);
|
DateTime secondBreak = lastMonday.copyWith(hour: 13, minute: 50);
|
||||||
DateTime beforeSchool = lastMonday.copyWith(hour: 7, minute: 30);
|
DateTime beforeSchool = lastMonday.copyWith(hour: 7, minute: 30);
|
||||||
|
|
||||||
return [
|
Iterable<TimeRegion> holidayList = holidays.result.map((holiday) {
|
||||||
...holidays.result.map((e) {
|
DateTime startDay = _parseWebuntisTimestamp(holiday.startDate, 0);
|
||||||
return TimeRegion(
|
int dayCount = _parseWebuntisTimestamp(holiday.endDate, 0)
|
||||||
startTime: _parseWebuntisTimestamp(e.startDate, 755),
|
.difference(startDay)
|
||||||
endTime: _parseWebuntisTimestamp(e.startDate, 1630),
|
.inDays;
|
||||||
text: 'holiday:${e.name}',
|
List<DateTime> days = List.generate(dayCount, (index) => startDay.add(Duration(days: index)));
|
||||||
color: Theme.of(context).disabledColor.withAlpha(50),
|
|
||||||
iconData: Icons.holiday_village_outlined
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
|
|
||||||
TimeRegion(
|
return days.map((holidayDay) {
|
||||||
startTime: firstBreak,
|
return TimeRegion(
|
||||||
endTime: firstBreak.add(const Duration(minutes: 20)),
|
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',
|
recurrenceRule: 'FREQ=DAILY;INTERVAL=1;COUNT=5',
|
||||||
text: 'centerIcon',
|
color: Theme.of(context).disabledColor.withAlpha(50),
|
||||||
color: Theme.of(context).primaryColor.withAlpha(50),
|
text: "centerIcon",
|
||||||
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",
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user