From 5210106032daa602b186e42fdb5bdd8640e5d105 Mon Sep 17 00:00:00 2001 From: b3ni15 Date: Wed, 18 Mar 2026 09:48:32 +0100 Subject: [PATCH] Refactor LiveCardProvider to track previous state and lesson ID for updates --- .../lib/api/providers/live_card_provider.dart | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/refilc/lib/api/providers/live_card_provider.dart b/refilc/lib/api/providers/live_card_provider.dart index 214239c2..3c894afa 100644 --- a/refilc/lib/api/providers/live_card_provider.dart +++ b/refilc/lib/api/providers/live_card_provider.dart @@ -45,6 +45,8 @@ class LiveCardProvider extends ChangeNotifier { static DateTime? now; LiveCardState currentState = LiveCardState.empty; + static LiveCardState _previousState = LiveCardState.empty; + static String? _previousLessonId; // ignore: unused_field late Timer _timer; late final TimetableProvider _timetable; @@ -379,28 +381,22 @@ class LiveCardProvider extends ChangeNotifier { hasUserDismissed = false; _createAndSync(); } else if (hasActivityStarted) { + final currentLessonId = currentLesson?.id ?? nextLesson?.id; + final stateChanged = currentState != _previousState; + final lessonChanged = currentLessonId != _previousLessonId; + if (hasActivitySettingsChanged) { debugPrint("Valamelyik beállítás megváltozott. Frissítés..."); PlatformChannel.updateLiveActivity(toMap()); hasActivitySettingsChanged = false; - } else if (nextLesson != null || currentLesson != null) { - bool afterPrevLessonEnd = prevLesson != null && - now - .subtract(const Duration(seconds: 1)) - .isBefore(prevLesson!.end) && - now.isAfter(prevLesson!.end); - - bool afterCurrentLessonStart = currentLesson != null && - now - .subtract(const Duration(seconds: 1)) - .isBefore(currentLesson!.start) && - now.isAfter(currentLesson!.start); - if (afterPrevLessonEnd || afterCurrentLessonStart) { - debugPrint( - "Óra kezdete/vége után 1 másodperccel vagyunk. Frissítés..."); - PlatformChannel.updateLiveActivity(toMap()); - } + } else if (stateChanged || lessonChanged) { + debugPrint( + "Állapot vagy óra váltás: $currentState, lesson: $currentLessonId. Frissítés..."); + PlatformChannel.updateLiveActivity(toMap()); } + + _previousState = currentState; + _previousLessonId = currentLessonId; } if (_settings.developerMode && _settings.devLiveFakeLessons) { @@ -469,6 +465,8 @@ class LiveCardProvider extends ChangeNotifier { hasDayEnd = false; hasUserDismissed = false; storeFirstRunDate = null; + _previousState = LiveCardState.empty; + _previousLessonId = null; } List _today(TimetableProvider p) {