Ignore disabled live activity
This commit is contained in:
parent
85c6d548ad
commit
cc40fb9c0f
@ -44,10 +44,20 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
required SettingsProvider settings,
|
required SettingsProvider settings,
|
||||||
}) : _timetable = timetable,
|
}) : _timetable = timetable,
|
||||||
_settings = settings {
|
_settings = settings {
|
||||||
_liveActivitiesPlugin.init(appGroupId: "group.refilc.livecard");
|
// Check if live card is enabled .areActivitiesEnabled()
|
||||||
_liveActivitiesPlugin.getAllActivitiesIds().then((value) {
|
_liveActivitiesPlugin.areActivitiesEnabled().then((value) {
|
||||||
_latestActivityId = value.isNotEmpty ? value.first : null;
|
// Console log
|
||||||
|
print("Live card enabled: $value");
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
_liveActivitiesPlugin.init(appGroupId: "group.refilc2.livecard");
|
||||||
|
|
||||||
|
_liveActivitiesPlugin.getAllActivitiesIds().then((value) {
|
||||||
|
_latestActivityId = value.isNotEmpty ? value.first : null;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) => update());
|
_timer = Timer.periodic(const Duration(seconds: 1), (timer) => update());
|
||||||
_delay = settings.bellDelayEnabled
|
_delay = settings.bellDelayEnabled
|
||||||
? Duration(seconds: settings.bellDelay)
|
? Duration(seconds: settings.bellDelay)
|
||||||
@ -58,8 +68,15 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_timer.cancel();
|
_timer.cancel();
|
||||||
if (_latestActivityId != null && Platform.isIOS)
|
if (Platform.isIOS) {
|
||||||
_liveActivitiesPlugin.endActivity(_latestActivityId!);
|
_liveActivitiesPlugin.areActivitiesEnabled().then((value) {
|
||||||
|
if (value) {
|
||||||
|
if (_latestActivityId != null) {
|
||||||
|
_liveActivitiesPlugin.endActivity(_latestActivityId!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,30 +163,34 @@ class LiveCardProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
void update() async {
|
void update() async {
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
final cmap = toMap();
|
_liveActivitiesPlugin.areActivitiesEnabled().then((value) {
|
||||||
if (!mapEquals(cmap, _lastActivity)) {
|
if (value) {
|
||||||
_lastActivity = cmap;
|
final cmap = toMap();
|
||||||
try {
|
if (!mapEquals(cmap, _lastActivity)) {
|
||||||
if (_lastActivity.isNotEmpty) {
|
_lastActivity = cmap;
|
||||||
if (_latestActivityId == null) {
|
try {
|
||||||
_liveActivitiesPlugin
|
if (_lastActivity.isNotEmpty) {
|
||||||
.createActivity(_lastActivity)
|
if (_latestActivityId == null) {
|
||||||
.then((value) => _latestActivityId = value);
|
_liveActivitiesPlugin
|
||||||
} else {
|
.createActivity(_lastActivity)
|
||||||
_liveActivitiesPlugin.updateActivity(
|
.then((value) => _latestActivityId = value);
|
||||||
_latestActivityId!, _lastActivity);
|
} else {
|
||||||
|
_liveActivitiesPlugin.updateActivity(
|
||||||
|
_latestActivityId!, _lastActivity);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (_latestActivityId != null) {
|
||||||
|
_liveActivitiesPlugin.endActivity(_latestActivityId!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('ERROR: Unable to create or update iOS LiveCard!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (_latestActivityId != null) {
|
|
||||||
_liveActivitiesPlugin.endActivity(_latestActivityId!);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (kDebugMode) {
|
|
||||||
print('ERROR: Unable to create or update iOS LiveCard!');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Lesson> today = _today(_timetable);
|
List<Lesson> today = _today(_timetable);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user