Skip to content

Commit

Permalink
[Presentation] In the notif. list item, hide the stop button if the n…
Browse files Browse the repository at this point in the history
…otif. is already completed.

Show a dialog before deleting a notif.
  • Loading branch information
Wolfteam committed Nov 2, 2022
1 parent acc781b commit c5b6c5a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/domain/extensions/duration_extensions.dart
Expand Up @@ -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');
Expand Down
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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<NotificationsBloc>().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<NotificationsBloc>().add(NotificationsEvent.stop(id: itemKey, type: type)),
),
SlidableAction(
label: s.delete,
backgroundColor: Colors.red,
icon: Icons.delete,
onPressed: (_) => context.read<NotificationsBloc>().add(NotificationsEvent.delete(id: itemKey, type: type)),
onPressed: (_) => showDialog(
context: context,
builder: (_) => ConfirmDialog(
title: s.delete,
content: s.confirmQuestion,
onOk: () => context.read<NotificationsBloc>().add(NotificationsEvent.delete(id: itemKey, type: type)),
),
),
),
],
),
Expand Down

0 comments on commit c5b6c5a

Please sign in to comment.