|
|
|
|
@@ -1,8 +1,5 @@
|
|
|
|
|
// 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';
|
|
|
|
|
import 'package:refilc/models/settings.dart';
|
|
|
|
|
@@ -39,13 +36,11 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
LiveCardState currentState = LiveCardState.empty;
|
|
|
|
|
late Timer _timer;
|
|
|
|
|
late final TimetableProvider _timetable;
|
|
|
|
|
late final SettingsProvider _settings;
|
|
|
|
|
|
|
|
|
|
late Duration _delay;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool _hasCheckedTimetable = false;
|
|
|
|
|
|
|
|
|
|
LiveCardProvider({
|
|
|
|
|
@@ -53,7 +48,6 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
required SettingsProvider settings,
|
|
|
|
|
}) : _timetable = timetable,
|
|
|
|
|
_settings = settings {
|
|
|
|
|
_timer = Timer.periodic(const Duration(seconds: 1), (timer) => update());
|
|
|
|
|
_delay = settings.bellDelayEnabled
|
|
|
|
|
? Duration(seconds: settings.bellDelay)
|
|
|
|
|
: Duration.zero;
|
|
|
|
|
@@ -87,19 +81,24 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
case LiveCardState.morning:
|
|
|
|
|
return {
|
|
|
|
|
"color":
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
"icon": nextLesson != null
|
|
|
|
|
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
|
|
|
|
: "book",
|
|
|
|
|
"title": "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)
|
|
|
|
|
_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("_", " ") ?? "",
|
|
|
|
|
};
|
|
|
|
|
@@ -107,19 +106,24 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
case LiveCardState.afternoon:
|
|
|
|
|
return {
|
|
|
|
|
"color":
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
"icon": nextLesson != null
|
|
|
|
|
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
|
|
|
|
: "book",
|
|
|
|
|
"title": "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)
|
|
|
|
|
_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("_", " ") ?? "",
|
|
|
|
|
};
|
|
|
|
|
@@ -127,19 +131,24 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
case LiveCardState.night:
|
|
|
|
|
return {
|
|
|
|
|
"color":
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
"icon": nextLesson != null
|
|
|
|
|
? SubjectIcon.resolveName(subject: nextLesson?.subject)
|
|
|
|
|
: "book",
|
|
|
|
|
"title": "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)
|
|
|
|
|
_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("_", " ") ?? "",
|
|
|
|
|
};
|
|
|
|
|
@@ -147,25 +156,28 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
case LiveCardState.duringLesson:
|
|
|
|
|
return {
|
|
|
|
|
"color":
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
"icon": currentLesson != null
|
|
|
|
|
? SubjectIcon.resolveName(subject: currentLesson?.subject)
|
|
|
|
|
: "book",
|
|
|
|
|
"index":
|
|
|
|
|
currentLesson != null ? '${currentLesson!.lessonIndex}. ' : "",
|
|
|
|
|
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("_", " ") ?? "",
|
|
|
|
|
"description": currentLesson?.description ?? "",
|
|
|
|
|
"startDate": ((currentLesson?.start.millisecondsSinceEpoch ?? 0) -
|
|
|
|
|
_delay.inMilliseconds)
|
|
|
|
|
_delay.inMilliseconds)
|
|
|
|
|
.toString(),
|
|
|
|
|
"endDate": ((currentLesson?.end.millisecondsSinceEpoch ?? 0) -
|
|
|
|
|
_delay.inMilliseconds)
|
|
|
|
|
_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("_", " ") ?? "",
|
|
|
|
|
};
|
|
|
|
|
@@ -181,21 +193,23 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"color":
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
'#${_settings.liveActivityColor.toString().substring(10, 16)}',
|
|
|
|
|
"icon": iconFloorMap[diff] ?? "cup.and.saucer",
|
|
|
|
|
"title": "Szünet",
|
|
|
|
|
"description": "go $diff".i18n.fill([
|
|
|
|
|
diff != "to room" ? (nextLesson!.getFloor() ?? 0) : nextLesson!.room
|
|
|
|
|
]),
|
|
|
|
|
"startDate": ((prevLesson?.end.millisecondsSinceEpoch ?? 0) -
|
|
|
|
|
_delay.inMilliseconds)
|
|
|
|
|
_delay.inMilliseconds)
|
|
|
|
|
.toString(),
|
|
|
|
|
"endDate": ((nextLesson?.start.millisecondsSinceEpoch ?? 0) -
|
|
|
|
|
_delay.inMilliseconds)
|
|
|
|
|
_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("_", " ") ?? "",
|
|
|
|
|
"index": "",
|
|
|
|
|
@@ -219,12 +233,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.afternoon ||
|
|
|
|
|
currentState == LiveCardState.night) &&
|
|
|
|
|
storeFirstRunDate == null) {
|
|
|
|
|
storeFirstRunDate = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -232,9 +246,9 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
// Filter label lessons #128
|
|
|
|
|
today = today
|
|
|
|
|
.where((lesson) =>
|
|
|
|
|
lesson.status?.name != "Elmaradt" &&
|
|
|
|
|
lesson.subject.id != '' &&
|
|
|
|
|
!lesson.isEmpty)
|
|
|
|
|
lesson.status?.name != "Elmaradt" &&
|
|
|
|
|
lesson.subject.id != '' &&
|
|
|
|
|
!lesson.isEmpty)
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
if (today.isNotEmpty) {
|
|
|
|
|
@@ -242,7 +256,7 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
today.sort((a, b) => a.start.compareTo(b.start));
|
|
|
|
|
|
|
|
|
|
final _lesson = today.firstWhere(
|
|
|
|
|
(l) => l.start.isBefore(now) && l.end.isAfter(now),
|
|
|
|
|
(l) => l.start.isBefore(now) && l.end.isAfter(now),
|
|
|
|
|
orElse: () => Lesson.fromJson({}));
|
|
|
|
|
|
|
|
|
|
if (_lesson.start.year != 0) {
|
|
|
|
|
@@ -291,22 +305,21 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
//LIVE ACTIVITIES
|
|
|
|
|
|
|
|
|
|
//CREATE
|
|
|
|
|
if (!hasActivityStarted && nextLesson != null && nextLesson!
|
|
|
|
|
.start
|
|
|
|
|
.difference(now)
|
|
|
|
|
.inMinutes <= 60 && (currentState == LiveCardState.morning ||
|
|
|
|
|
currentState == LiveCardState.afternoon ||
|
|
|
|
|
currentState == LiveCardState.night)) {
|
|
|
|
|
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 &&
|
|
|
|
|
currentLesson != null) ||
|
|
|
|
|
currentState == LiveCardState.duringBreak)) {
|
|
|
|
|
debugPrint(
|
|
|
|
|
"Óra van, vagy szünet, de nincs LiveActivity. létrehozás...");
|
|
|
|
|
} else if (!hasActivityStarted &&
|
|
|
|
|
((currentState == LiveCardState.duringLesson &&
|
|
|
|
|
currentLesson != null) ||
|
|
|
|
|
currentState == LiveCardState.duringBreak)) {
|
|
|
|
|
debugPrint("Óra van, vagy szünet, de nincs LiveActivity. létrehozás...");
|
|
|
|
|
PlatformChannel.createLiveActivity(toMap());
|
|
|
|
|
hasActivityStarted = true;
|
|
|
|
|
}
|
|
|
|
|
@@ -317,15 +330,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 +351,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();
|
|
|
|
|
@@ -355,4 +373,4 @@ class LiveCardProvider extends ChangeNotifier {
|
|
|
|
|
List<Lesson> _today(TimetableProvider p) => (p.getWeek(Week.current()) ?? [])
|
|
|
|
|
.where((l) => _sameDate(l.date, _now()))
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|