diff --git a/lib/view/pages/timetable/timetable.dart b/lib/view/pages/timetable/timetable.dart index 7c6cfa6..6a4b575 100644 --- a/lib/view/pages/timetable/timetable.dart +++ b/lib/view/pages/timetable/timetable.dart @@ -129,10 +129,7 @@ class _TimetableState extends State { timeRegionBuilder: (BuildContext context, TimeRegionDetails timeRegionDetails) => TimeRegionComponent(details: timeRegionDetails), appointmentBuilder: (BuildContext context, CalendarAppointmentDetails details) => AppointmentComponent( details: details, - crossedOut: ( - (details.appointments.first.id as GetTimetableResponseObject).code == "cancelled" - || (details.appointments.first.id as GetTimetableResponseObject).te.first.id == 0 - ) + crossedOut: _isCrossedOut(details) ), headerHeight: 0, @@ -211,7 +208,7 @@ class _TimetableState extends State { "\n" "${element.te.first.longname}", notes: element.activityType, - color: _getEventColor(element.code, startTime, endTime), + color: _getEventColor(element, startTime, endTime), ); } catch(e) { return Appointment( @@ -236,15 +233,29 @@ class _TimetableState extends State { return DateTime.parse('$date ${timeString.substring(0, 2)}:${timeString.substring(2, 4)}'); } - Color _getEventColor(String? code, DateTime startTime, DateTime endTime) { + Color _getEventColor(GetTimetableResponseObject webuntisElement, DateTime startTime, DateTime endTime) { + // Make element darker, when it already took place int opacity = endTime.isBefore(DateTime.now()) ? 100 : 255; - if(code == "cancelled") return const Color(0xff000000).withAlpha(opacity); - if(code == "irregular") return const Color(0xff8F19B3).withAlpha(opacity); + // Cancelled + if(webuntisElement.code == "cancelled") return const Color(0xff000000).withAlpha(opacity); + // Any changes or no teacher at this element + if(webuntisElement.code == "irregular" || webuntisElement.te.first.id == 0) return const Color(0xff8F19B3).withAlpha(opacity); + + // Event was in the past if(endTime.isBefore(DateTime.now())) return Theme.of(context).primaryColor.withAlpha(opacity); + + // Event takes currently place if(endTime.isAfter(DateTime.now()) && startTime.isBefore(DateTime.now())) return Theme.of(context).primaryColor.withRed(100); + // Fallback return Theme.of(context).primaryColor; } + + bool _isCrossedOut(CalendarAppointmentDetails calendarEntry) { + GetTimetableResponseObject webuntisElement = (calendarEntry.appointments.first.id as GetTimetableResponseObject); + + return webuntisElement.code == "cancelled"; + } } diff --git a/pubspec.yaml b/pubspec.yaml index 9e1f549..22c164a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 0.0.1+8 +version: 0.0.1+9 environment: sdk: '>3.0.0'