From c5b6c5ab3352c86f90a3774a2cf5ebc76adbe751 Mon Sep 17 00:00:00 2001 From: Efrain Bastidas Date: Tue, 1 Nov 2022 21:19:24 -0500 Subject: [PATCH] [Presentation] In the notif. list item, hide the stop button if the notif. is already completed. Show a dialog before deleting a notif. --- .../extensions/duration_extensions.dart | 2 +- .../widgets/items/notification_list_tile.dart | 30 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/domain/extensions/duration_extensions.dart b/lib/domain/extensions/duration_extensions.dart index 746ba7916..9bcc64c35 100644 --- a/lib/domain/extensions/duration_extensions.dart +++ b/lib/domain/extensions/duration_extensions.dart @@ -2,7 +2,7 @@ import 'package:shiori/domain/extensions/string_extensions.dart'; extension DurationExtensions on Duration { String formatDuration({String? negativeText}) { - if (isNegative) { + if (isNegative || inSeconds == 0) { return negativeText.isNotNullEmptyOrWhitespace ? negativeText! : '∞'; } String twoDigits(num n) => n.toString().padLeft(2, '0'); diff --git a/lib/presentation/notifications/widgets/items/notification_list_tile.dart b/lib/presentation/notifications/widgets/items/notification_list_tile.dart index 017affc3a..b4e640412 100644 --- a/lib/presentation/notifications/widgets/items/notification_list_tile.dart +++ b/lib/presentation/notifications/widgets/items/notification_list_tile.dart @@ -8,6 +8,7 @@ import 'package:shiori/domain/models/models.dart' as models; import 'package:shiori/generated/l10n.dart'; import 'package:shiori/injection.dart'; import 'package:shiori/presentation/notifications/widgets/add_edit_notification_bottom_sheet.dart'; +import 'package:shiori/presentation/shared/dialogs/confirm_dialog.dart'; import 'package:shiori/presentation/shared/dialogs/number_picker_dialog.dart'; import 'package:shiori/presentation/shared/images/circle_item.dart'; import 'package:shiori/presentation/shared/styles.dart'; @@ -26,6 +27,11 @@ class NotificationListTitle extends StatelessWidget { final Widget subtitle; + bool get isCompleted { + final diff = completesAt.difference(DateTime.now()); + return diff.inSeconds <= 0; + } + NotificationListTitle({ Key? key, required models.NotificationItem item, @@ -56,18 +62,26 @@ class NotificationListTitle extends StatelessWidget { extentRatio: extentRatio, motion: const ScrollMotion(), children: [ - SlidableAction( - label: s.stop, - backgroundColor: Colors.deepOrange, - icon: Icons.stop, - foregroundColor: Colors.white, - onPressed: (_) => context.read().add(NotificationsEvent.stop(id: itemKey, type: type)), - ), + if (!isCompleted) + SlidableAction( + label: s.stop, + backgroundColor: Colors.deepOrange, + icon: Icons.stop, + foregroundColor: Colors.white, + onPressed: (_) => context.read().add(NotificationsEvent.stop(id: itemKey, type: type)), + ), SlidableAction( label: s.delete, backgroundColor: Colors.red, icon: Icons.delete, - onPressed: (_) => context.read().add(NotificationsEvent.delete(id: itemKey, type: type)), + onPressed: (_) => showDialog( + context: context, + builder: (_) => ConfirmDialog( + title: s.delete, + content: s.confirmQuestion, + onOk: () => context.read().add(NotificationsEvent.delete(id: itemKey, type: type)), + ), + ), ), ], ),