fixed overwrite on internal copy, DST drift in widget anchors, inline errors without controller and removed dead room lookup
This commit is contained in:
@@ -2,7 +2,6 @@ import 'dart:developer';
|
||||
import 'dart:ui';
|
||||
|
||||
import '../api/marianumconnect/queries/timetable_get_holidays/timetable_get_holidays_response.dart';
|
||||
import '../api/marianumconnect/queries/timetable_get_rooms/timetable_get_rooms_response.dart';
|
||||
import '../api/marianumconnect/queries/timetable_get_subjects/timetable_get_subjects_response.dart';
|
||||
import '../api/marianumconnect/queries/timetable_get_timegrid/timetable_get_timegrid_response.dart';
|
||||
import '../api/marianumconnect/queries/timetable_get_week/timetable_get_week_response.dart';
|
||||
@@ -27,14 +26,14 @@ class WidgetDataMapper {
|
||||
static const _weekend = {DateTime.saturday, DateTime.sunday};
|
||||
|
||||
static DateTime resolveDayAnchor(DateTime now) {
|
||||
var candidate = DateTime(now.year, now.month, now.day);
|
||||
var candidate = now.dateOnly;
|
||||
final shiftToTomorrow =
|
||||
now.hour >= _dayWidgetCutoffHour || _weekend.contains(now.weekday);
|
||||
if (shiftToTomorrow) {
|
||||
candidate = candidate.add(const Duration(days: 1));
|
||||
candidate = candidate.addDays(1);
|
||||
}
|
||||
while (_weekend.contains(candidate.weekday)) {
|
||||
candidate = candidate.add(const Duration(days: 1));
|
||||
candidate = candidate.addDays(1);
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
@@ -44,10 +43,8 @@ class WidgetDataMapper {
|
||||
|
||||
/// Monday of the calendar week containing [reference] — no roll-forward,
|
||||
/// unlike [resolveWeekAnchor]. Start of the week payload's 14-day window.
|
||||
static DateTime startOfCalendarWeek(DateTime reference) {
|
||||
final monday = reference.subtract(Duration(days: reference.weekday - 1));
|
||||
return DateTime(monday.year, monday.month, monday.day);
|
||||
}
|
||||
static DateTime startOfCalendarWeek(DateTime reference) =>
|
||||
reference.mondayOfWeek;
|
||||
|
||||
/// Days covered by the week payload: current calendar week + the next, so
|
||||
/// native renderers can roll the view forward without fresh data.
|
||||
@@ -58,7 +55,6 @@ class WidgetDataMapper {
|
||||
required DateTime now,
|
||||
required Iterable<McTimetableEntry> lessons,
|
||||
required TimetableGetSubjectsResponse? subjects,
|
||||
required TimetableGetRoomsResponse? rooms,
|
||||
required TimetableGetHolidaysResponse? holidays,
|
||||
TimetableGetTimegridResponse? timegrid,
|
||||
GetCustomTimetableEventResponse? customEvents,
|
||||
@@ -69,7 +65,6 @@ class WidgetDataMapper {
|
||||
now: now,
|
||||
lessons: lessons,
|
||||
subjects: subjects,
|
||||
rooms: rooms,
|
||||
holidays: holidays,
|
||||
timegrid: timegrid,
|
||||
customEvents: customEvents,
|
||||
@@ -80,7 +75,6 @@ class WidgetDataMapper {
|
||||
now: now,
|
||||
lessons: lessons,
|
||||
subjects: subjects,
|
||||
rooms: rooms,
|
||||
holidays: holidays,
|
||||
timegrid: timegrid,
|
||||
customEvents: customEvents,
|
||||
@@ -93,7 +87,6 @@ class WidgetDataMapper {
|
||||
required DateTime now,
|
||||
required Iterable<McTimetableEntry> lessons,
|
||||
required TimetableGetSubjectsResponse? subjects,
|
||||
required TimetableGetRoomsResponse? rooms,
|
||||
required TimetableGetHolidaysResponse? holidays,
|
||||
TimetableGetTimegridResponse? timegrid,
|
||||
GetCustomTimetableEventResponse? customEvents,
|
||||
@@ -103,7 +96,7 @@ class WidgetDataMapper {
|
||||
final anchor = resolveDayAnchor(now);
|
||||
final holiday = _findHoliday(anchor, holidays);
|
||||
final dayStart = anchor;
|
||||
final dayEnd = anchor.add(const Duration(days: 1));
|
||||
final dayEnd = anchor.addDays(1);
|
||||
final dayLessons = lessons.where((l) => l.date.isSameDay(anchor)).toList();
|
||||
final source = connectDoubleLessons
|
||||
? LessonMerger.merge(dayLessons)
|
||||
@@ -115,7 +108,6 @@ class WidgetDataMapper {
|
||||
source,
|
||||
now,
|
||||
subjects,
|
||||
rooms,
|
||||
customEvents,
|
||||
dayStart,
|
||||
dayEnd,
|
||||
@@ -131,7 +123,6 @@ class WidgetDataMapper {
|
||||
required DateTime now,
|
||||
required Iterable<McTimetableEntry> lessons,
|
||||
required TimetableGetSubjectsResponse? subjects,
|
||||
required TimetableGetRoomsResponse? rooms,
|
||||
required TimetableGetHolidaysResponse? holidays,
|
||||
TimetableGetTimegridResponse? timegrid,
|
||||
GetCustomTimetableEventResponse? customEvents,
|
||||
@@ -143,7 +134,7 @@ class WidgetDataMapper {
|
||||
// (possibly rolled-forward) week anchor: on Friday evening the payload
|
||||
// must still contain today for renderers that derive day slices.
|
||||
final windowStart = startOfCalendarWeek(now);
|
||||
final endExclusive = windowStart.add(const Duration(days: weekWindowDays));
|
||||
final endExclusive = windowStart.addDays(weekWindowDays);
|
||||
final weekLessons = lessons.where((l) {
|
||||
final dt = l.startDateTime;
|
||||
return !dt.isBefore(windowStart) && dt.isBefore(endExclusive);
|
||||
@@ -170,7 +161,6 @@ class WidgetDataMapper {
|
||||
source,
|
||||
now,
|
||||
subjects,
|
||||
rooms,
|
||||
customEvents,
|
||||
windowStart,
|
||||
endExclusive,
|
||||
@@ -340,7 +330,6 @@ class WidgetDataMapper {
|
||||
Iterable<McTimetableEntry> source,
|
||||
DateTime now,
|
||||
TimetableGetSubjectsResponse? subjects,
|
||||
TimetableGetRoomsResponse? rooms,
|
||||
GetCustomTimetableEventResponse? customEvents,
|
||||
DateTime start,
|
||||
DateTime endExclusive, {
|
||||
@@ -352,7 +341,6 @@ class WidgetDataMapper {
|
||||
lesson,
|
||||
now,
|
||||
subjects,
|
||||
rooms,
|
||||
showClassInsteadOfTeacher: showClassInsteadOfTeacher,
|
||||
),
|
||||
..._expandCustomEvents(customEvents, start, endExclusive),
|
||||
@@ -363,8 +351,7 @@ class WidgetDataMapper {
|
||||
static WidgetLesson _mapLesson(
|
||||
McTimetableEntry lesson,
|
||||
DateTime now,
|
||||
TimetableGetSubjectsResponse? subjects,
|
||||
TimetableGetRoomsResponse? rooms, {
|
||||
TimetableGetSubjectsResponse? subjects, {
|
||||
required bool showClassInsteadOfTeacher,
|
||||
}) {
|
||||
final start = lesson.startDateTime;
|
||||
@@ -389,15 +376,6 @@ class WidgetDataMapper {
|
||||
.where((s) => s.shortName == subjectShortRaw)
|
||||
.firstOrNull;
|
||||
final subjectLong = subject?.longName;
|
||||
final roomShort = lesson.rooms.firstOrNull;
|
||||
var roomName = roomShort;
|
||||
if (rooms != null && roomShort != null) {
|
||||
roomName = rooms.result
|
||||
.where((r) => r.shortName == roomShort)
|
||||
.firstOrNull
|
||||
?.shortName ??
|
||||
roomName;
|
||||
}
|
||||
final teacher = lesson.teachers.firstOrNull;
|
||||
// Lehrerpläne: Klasse in den Teacher-Slot mappen, damit die nativen
|
||||
// Renderer unverändert bleiben. Klassenlose Einträge (Aufsichten) lassen
|
||||
@@ -413,7 +391,7 @@ class WidgetDataMapper {
|
||||
end: end,
|
||||
subjectShort: subjectShort,
|
||||
subjectLong: subjectLong,
|
||||
room: roomName,
|
||||
room: lesson.rooms.firstOrNull,
|
||||
teacher: teacherName,
|
||||
originalTeacher: originalTeacher,
|
||||
status: _mapStatus(lessonStatus),
|
||||
@@ -562,11 +540,7 @@ class WidgetDataMapper {
|
||||
final actualEnd = occurrenceStart.add(duration);
|
||||
var segmentStart = occurrenceStart;
|
||||
while (segmentStart.isBefore(actualEnd)) {
|
||||
final nextMidnight = DateTime(
|
||||
segmentStart.year,
|
||||
segmentStart.month,
|
||||
segmentStart.day,
|
||||
).add(const Duration(days: 1));
|
||||
final nextMidnight = segmentStart.dateOnly.addDays(1);
|
||||
final segmentEnd = actualEnd.isBefore(nextMidnight)
|
||||
? actualEnd
|
||||
: nextMidnight.subtract(const Duration(minutes: 1));
|
||||
|
||||
@@ -85,7 +85,6 @@ class WidgetPublisher {
|
||||
now: now,
|
||||
lessons: state.getAllKnownLessons(),
|
||||
subjects: state.subjects,
|
||||
rooms: state.rooms,
|
||||
holidays: state.schoolHolidays,
|
||||
timegrid: state.timegrid,
|
||||
customEvents: state.customEvents,
|
||||
|
||||
Reference in New Issue
Block a user