forked from firka/student-legacy
LiveActivities design fix
- Fixed if the user opens the app 1 hour before their first class, the Room section is empty in LiveActivity lock screen - DynamicIsland reworked and improved - The room section moved to Flutter side
This commit is contained in:
parent
ae66a462e7
commit
2ca8f4b8fe
@ -1,7 +1,6 @@
|
||||
// ignore_for_file: no_leading_underscores_for_local_identifiers
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:refilc/api/providers/liveactivity/platform_channel.dart';
|
||||
import 'package:refilc/helpers/subject.dart';
|
||||
@ -18,9 +17,10 @@ enum LiveCardState {
|
||||
duringLesson,
|
||||
duringBreak,
|
||||
morning,
|
||||
weekendMorning,
|
||||
afternoon,
|
||||
night,
|
||||
summary
|
||||
summary,
|
||||
}
|
||||
|
||||
class LiveCardProvider extends ChangeNotifier {
|
||||
@ -34,18 +34,19 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
static bool hasDayEnd = false;
|
||||
static DateTime? storeFirstRunDate;
|
||||
static bool hasActivitySettingsChanged = false;
|
||||
// ignore: non_constant_identifier_names
|
||||
static Map<String, String> LAData = {};
|
||||
static DateTime? now;
|
||||
//
|
||||
|
||||
LiveCardState currentState = LiveCardState.empty;
|
||||
// ignore: unused_field
|
||||
late Timer _timer;
|
||||
late final TimetableProvider _timetable;
|
||||
late final SettingsProvider _settings;
|
||||
|
||||
late Duration _delay;
|
||||
|
||||
|
||||
bool _hasCheckedTimetable = false;
|
||||
|
||||
LiveCardProvider({
|
||||
@ -94,12 +95,17 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
"title": "Jó reggelt! Az első órádig:",
|
||||
"subtitle": "",
|
||||
"description": "",
|
||||
"startDate": storeFirstRunDate != null ? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) - (_delay.inMilliseconds)).toString(): "",
|
||||
"startDate": storeFirstRunDate != null
|
||||
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
||||
(_delay.inMilliseconds))
|
||||
.toString()
|
||||
: "",
|
||||
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||
_delay.inMilliseconds)
|
||||
.toString(),
|
||||
"nextSubject": nextLesson != null
|
||||
? nextLesson?.subject.renamedTo ?? ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
? nextLesson?.subject.renamedTo ??
|
||||
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
: "",
|
||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||
};
|
||||
@ -114,12 +120,17 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
"title": "Jó napot! Az első órádig:",
|
||||
"subtitle": "",
|
||||
"description": "",
|
||||
"startDate": storeFirstRunDate != null ? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) - (_delay.inMilliseconds)).toString(): "",
|
||||
"startDate": storeFirstRunDate != null
|
||||
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
||||
(_delay.inMilliseconds))
|
||||
.toString()
|
||||
: "",
|
||||
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||
_delay.inMilliseconds)
|
||||
.toString(),
|
||||
"nextSubject": nextLesson != null
|
||||
? nextLesson?.subject.renamedTo ?? ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
? nextLesson?.subject.renamedTo ??
|
||||
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
: "",
|
||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||
};
|
||||
@ -134,12 +145,17 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
"title": "Jó estét! Az első órádig:",
|
||||
"subtitle": "",
|
||||
"description": "",
|
||||
"startDate": storeFirstRunDate != null ? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) - (_delay.inMilliseconds)).toString(): "",
|
||||
"startDate": storeFirstRunDate != null
|
||||
? ((storeFirstRunDate?.millisecondsSinceEpoch ?? 0) -
|
||||
(_delay.inMilliseconds))
|
||||
.toString()
|
||||
: "",
|
||||
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||
_delay.inMilliseconds)
|
||||
.toString(),
|
||||
"nextSubject": nextLesson != null
|
||||
? nextLesson?.subject.renamedTo ?? ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
? nextLesson?.subject.renamedTo ??
|
||||
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
: "",
|
||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||
};
|
||||
@ -154,9 +170,11 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
"index":
|
||||
currentLesson != null ? '${currentLesson!.lessonIndex}. ' : "",
|
||||
"title": currentLesson != null
|
||||
? currentLesson?.subject.renamedTo ?? ShortSubject.resolve(subject: currentLesson?.subject).capital()
|
||||
? currentLesson?.subject.renamedTo ??
|
||||
ShortSubject.resolve(subject: currentLesson?.subject)
|
||||
.capital()
|
||||
: "",
|
||||
"subtitle": currentLesson?.room.replaceAll("_", " ") ?? "",
|
||||
"subtitle": "Terem: ${currentLesson?.room.replaceAll("_", " ") ?? ""}",
|
||||
"description": currentLesson?.description ?? "",
|
||||
"startDate": ((currentLesson?.start.millisecondsSinceEpoch ?? 0) -
|
||||
_delay.inMilliseconds)
|
||||
@ -165,7 +183,8 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
_delay.inMilliseconds)
|
||||
.toString(),
|
||||
"nextSubject": nextLesson != null
|
||||
? nextLesson?.subject.renamedTo ?? ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
? nextLesson?.subject.renamedTo ??
|
||||
ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
: "",
|
||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||
};
|
||||
@ -194,7 +213,9 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
_delay.inMilliseconds)
|
||||
.toString(),
|
||||
"nextSubject": (nextLesson != null
|
||||
? nextLesson?.subject.renamedTo ?? ShortSubject.resolve(subject: nextLesson?.subject).capital()
|
||||
? nextLesson?.subject.renamedTo ??
|
||||
ShortSubject.resolve(subject: nextLesson?.subject)
|
||||
.capital()
|
||||
: "")
|
||||
.capital(),
|
||||
"nextRoom": nextLesson?.room.replaceAll("_", " ") ?? "",
|
||||
@ -219,12 +240,12 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
? Duration(seconds: _settings.bellDelay)
|
||||
: Duration.zero;
|
||||
|
||||
|
||||
DateTime now = _now().add(_delay);
|
||||
|
||||
if ((currentState == LiveCardState.morning ||
|
||||
currentState == LiveCardState.afternoon ||
|
||||
currentState == LiveCardState.night) && storeFirstRunDate == null) {
|
||||
currentState == LiveCardState.night) &&
|
||||
storeFirstRunDate == null) {
|
||||
storeFirstRunDate = now;
|
||||
}
|
||||
|
||||
@ -283,7 +304,11 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
} else if (now.hour >= 20) {
|
||||
currentState = LiveCardState.night;
|
||||
} else if (now.hour >= 5 && now.hour <= 10) {
|
||||
if (nextLesson == null || now.weekday == 6 || now.weekday == 7) {
|
||||
currentState = LiveCardState.empty;
|
||||
} else {
|
||||
currentState = LiveCardState.morning;
|
||||
}
|
||||
} else {
|
||||
currentState = LiveCardState.empty;
|
||||
}
|
||||
@ -291,22 +316,21 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
//LIVE ACTIVITIES
|
||||
|
||||
//CREATE
|
||||
if (!hasActivityStarted && nextLesson != null && nextLesson!
|
||||
.start
|
||||
.difference(now)
|
||||
.inMinutes <= 60 && (currentState == LiveCardState.morning ||
|
||||
if (!hasActivityStarted &&
|
||||
nextLesson != null &&
|
||||
nextLesson!.start.difference(now).inMinutes <= 60 &&
|
||||
(currentState == LiveCardState.morning ||
|
||||
currentState == LiveCardState.afternoon ||
|
||||
currentState == LiveCardState.night)) {
|
||||
debugPrint(
|
||||
"Az első óra előtt állunk, kevesebb mint egy órával. Létrehozás...");
|
||||
PlatformChannel.createLiveActivity(toMap());
|
||||
hasActivityStarted = true;
|
||||
}
|
||||
else if (!hasActivityStarted && ((currentState == LiveCardState.duringLesson &&
|
||||
} else if (!hasActivityStarted &&
|
||||
((currentState == LiveCardState.duringLesson &&
|
||||
currentLesson != null) ||
|
||||
currentState == LiveCardState.duringBreak)) {
|
||||
debugPrint(
|
||||
"Óra van, vagy szünet, de nincs LiveActivity. létrehozás...");
|
||||
debugPrint("Óra van, vagy szünet, de nincs LiveActivity. létrehozás...");
|
||||
PlatformChannel.createLiveActivity(toMap());
|
||||
hasActivityStarted = true;
|
||||
}
|
||||
@ -317,15 +341,18 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
debugPrint("Valamelyik beállítás megváltozott. Frissítés...");
|
||||
PlatformChannel.updateLiveActivity(toMap());
|
||||
hasActivitySettingsChanged = false;
|
||||
}
|
||||
else if (nextLesson != null || currentLesson != null) {
|
||||
} else if (nextLesson != null || currentLesson != null) {
|
||||
bool afterPrevLessonEnd = prevLesson != null &&
|
||||
now.subtract(const Duration(seconds: 1)).isBefore(
|
||||
prevLesson!.end) && now.isAfter(prevLesson!.end);
|
||||
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);
|
||||
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...");
|
||||
@ -335,7 +362,9 @@ class LiveCardProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
//END
|
||||
if (hasActivityStarted && !hasDayEnd && nextLesson == null &&
|
||||
if (hasActivityStarted &&
|
||||
!hasDayEnd &&
|
||||
nextLesson == null &&
|
||||
now.isAfter(prevLesson!.end)) {
|
||||
debugPrint("Az utolsó óra véget ért. Befejezés...");
|
||||
PlatformChannel.endLiveActivity();
|
||||
|
Loading…
x
Reference in New Issue
Block a user