refactor: 重构提醒通知系统
This commit is contained in:
@@ -718,32 +718,57 @@ class _CalendarDayWeekScreenState extends State<CalendarDayWeekScreen>
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: eventColor, width: 1),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: eventColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (!isCompact) const SizedBox(width: 4),
|
||||
if (!isCompact)
|
||||
Expanded(
|
||||
child: Text(
|
||||
layout.event.title,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: eventColor,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
const markerSize = 6.0;
|
||||
const markerTitleGap = 4.0;
|
||||
final canShowMarker = constraints.maxWidth >= markerSize;
|
||||
final canShowTitle =
|
||||
!isCompact &&
|
||||
constraints.maxWidth >= markerSize + markerTitleGap + 8;
|
||||
|
||||
if (!canShowMarker) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: SizedBox(
|
||||
width: markerSize,
|
||||
height: markerSize,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: eventColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (canShowTitle)
|
||||
Positioned(
|
||||
left: markerSize + markerTitleGap,
|
||||
right: 0,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
layout.event.title,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: eventColor,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -58,7 +58,9 @@ class _CalendarMonthScreenState extends State<CalendarMonthScreen>
|
||||
return;
|
||||
}
|
||||
_eventsByDay.clear();
|
||||
for (final event in events) {
|
||||
for (final event in events.where(
|
||||
(e) => e.status != ScheduleStatus.archived,
|
||||
)) {
|
||||
final key = formatYmd(event.startAt);
|
||||
_eventsByDay[key] = [...(_eventsByDay[key] ?? const []), event];
|
||||
}
|
||||
|
||||
+23
-15
@@ -28,12 +28,18 @@ class CalendarReminderAlarmScreen extends StatefulWidget {
|
||||
class _CalendarReminderAlarmScreenState
|
||||
extends State<CalendarReminderAlarmScreen> {
|
||||
late final Future<ScheduleItemModel> _eventFuture;
|
||||
bool _isSubmitting = false;
|
||||
bool _isArchiving = false;
|
||||
bool _isSnoozing = false;
|
||||
|
||||
bool get _isProcessing => _isArchiving || _isSnoozing;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_eventFuture = sl<CalendarService>().getEventById(widget.eventId);
|
||||
_eventFuture = sl<CalendarService>().getEventById(
|
||||
widget.eventId,
|
||||
reconcileReminder: false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -78,8 +84,8 @@ class _CalendarReminderAlarmScreenState
|
||||
child: AppButton(
|
||||
text: context.l10n.notificationSnoozeLater,
|
||||
isOutlined: true,
|
||||
isLoading: _isSubmitting,
|
||||
onPressed: _isSubmitting
|
||||
isLoading: _isSnoozing,
|
||||
onPressed: _isProcessing
|
||||
? null
|
||||
: () => _snoozeEvent(event),
|
||||
),
|
||||
@@ -88,8 +94,8 @@ class _CalendarReminderAlarmScreenState
|
||||
Expanded(
|
||||
child: AppButton(
|
||||
text: context.l10n.calendarDetailArchiveConfirm,
|
||||
isLoading: _isSubmitting,
|
||||
onPressed: _isSubmitting
|
||||
isLoading: _isArchiving,
|
||||
onPressed: _isProcessing
|
||||
? null
|
||||
: () => _archiveEvent(event),
|
||||
),
|
||||
@@ -107,15 +113,16 @@ class _CalendarReminderAlarmScreenState
|
||||
|
||||
Future<void> _archiveEvent(ScheduleItemModel event) async {
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
_isArchiving = true;
|
||||
});
|
||||
try {
|
||||
await sl<CalendarService>().archiveEvent(event.id);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
context.go(AppRoutes.calendarEventDetail(event.id));
|
||||
} catch (_) {
|
||||
context.go(AppRoutes.homeMain);
|
||||
} catch (e, st) {
|
||||
debugPrint('[_archiveEvent] error: $e\n$st');
|
||||
if (mounted) {
|
||||
Toast.show(
|
||||
context,
|
||||
@@ -126,7 +133,7 @@ class _CalendarReminderAlarmScreenState
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_isArchiving = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -134,7 +141,7 @@ class _CalendarReminderAlarmScreenState
|
||||
|
||||
Future<void> _snoozeEvent(ScheduleItemModel event) async {
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
_isSnoozing = true;
|
||||
});
|
||||
try {
|
||||
await sl<ReminderReconcileService>().snooze10m(_snapshotFromEvent(event));
|
||||
@@ -142,19 +149,20 @@ class _CalendarReminderAlarmScreenState
|
||||
return;
|
||||
}
|
||||
Toast.show(context, context.l10n.notificationSnoozeMinutes(10));
|
||||
context.go(AppRoutes.calendarEventDetail(event.id));
|
||||
} catch (_) {
|
||||
context.go(AppRoutes.homeMain);
|
||||
} catch (e, st) {
|
||||
debugPrint('[_snoozeEvent] error: $e\n$st');
|
||||
if (mounted) {
|
||||
Toast.show(
|
||||
context,
|
||||
context.l10n.todoSaveFailed('snooze failed'),
|
||||
context.l10n.todoSaveFailed(e.toString()),
|
||||
type: ToastType.error,
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_isSnoozing = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user