Fix release notification resource and add multiple advance reminders
This commit is contained in:
@@ -17,14 +17,15 @@ class ImportMetadata {
|
||||
|
||||
class AppSnapshot {
|
||||
AppSnapshot({
|
||||
this.settings = const AppSettings(),
|
||||
AppSettings? settings,
|
||||
List<Course> courses = const [],
|
||||
this.importMetadata,
|
||||
this.examSchedule,
|
||||
SchoolTerm? schoolTerm,
|
||||
this.calendarCleanupPending = false,
|
||||
Map<String, String> calendarEventIds = const {},
|
||||
}) : schoolTerm = schoolTerm ?? _legacyTerm(courses, examSchedule),
|
||||
}) : settings = settings ?? AppSettings(),
|
||||
schoolTerm = schoolTerm ?? _legacyTerm(courses, examSchedule),
|
||||
courses = List.unmodifiable(courses),
|
||||
calendarEventIds = Map.unmodifiable(calendarEventIds);
|
||||
final AppSettings settings;
|
||||
@@ -85,6 +86,7 @@ class AppSnapshot {
|
||||
},
|
||||
'remindersEnabled': settings.remindersEnabled,
|
||||
'reminderMinutes': settings.reminderMinutes,
|
||||
'reminderOffsets': settings.reminderOffsets,
|
||||
'colorMode': settings.colorMode.name,
|
||||
'singleColorArgb': settings.singleColorArgb,
|
||||
'calendarEnabled': settings.calendarEnabled,
|
||||
@@ -112,10 +114,17 @@ class AppSnapshot {
|
||||
throw const FormatException('保存课表无效');
|
||||
}
|
||||
final s = Map<String, dynamic>.from(json['settings'] as Map);
|
||||
final minutes = s['reminderMinutes'] as int;
|
||||
if (![5, 10, 15, 30, 60].contains(minutes)) {
|
||||
final rawOffsets = s.containsKey('reminderOffsets')
|
||||
? s['reminderOffsets']
|
||||
: [s['reminderMinutes']];
|
||||
if (rawOffsets is! List ||
|
||||
rawOffsets.isEmpty ||
|
||||
rawOffsets.any(
|
||||
(v) => v is! int || !AppSettings.allowedReminderMinutes.contains(v),
|
||||
)) {
|
||||
throw const FormatException('提醒时间无效');
|
||||
}
|
||||
final offsets = rawOffsets.cast<int>();
|
||||
final color = s['singleColorArgb'] as int;
|
||||
if (color < 0 || color > 0xFFFFFFFF) throw const FormatException('颜色无效');
|
||||
final rawHeight = s.containsKey('courseHeightScale')
|
||||
@@ -152,7 +161,7 @@ class AppSnapshot {
|
||||
settings: AppSettings(
|
||||
semester: term,
|
||||
remindersEnabled: s['remindersEnabled'] as bool,
|
||||
reminderMinutes: minutes,
|
||||
reminderOffsets: offsets,
|
||||
colorMode: ColorMode.values.byName(s['colorMode'] as String),
|
||||
singleColorArgb: color,
|
||||
calendarEnabled: s['calendarEnabled'] as bool,
|
||||
|
||||
Reference in New Issue
Block a user