Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Delete ritual confirmation sheet

laurenspriem5b3cc96513a6
diff --git a/mobile/apps/photos/assets/rituals/trash_rituals.png b/mobile/apps/photos/assets/rituals/trash_rituals.png
new file mode 100644
index 0000000000..c9e62af6c0
Binary files /dev/null and b/mobile/apps/photos/assets/rituals/trash_rituals.png differ
diff --git a/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart b/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
index 9703c60717..2b79370f82 100644
--- a/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
+++ b/mobile/apps/photos/lib/ui/rituals/all_rituals_screen.dart
@@ -4,6 +4,7 @@ import "package:photos/l10n/l10n.dart";
import "package:photos/models/rituals/ritual_models.dart";
import "package:photos/service_locator.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/rituals/delete_ritual_confirmation_sheet.dart";
import "package:photos/ui/rituals/ritual_camera_page.dart";
import "package:photos/ui/rituals/ritual_day_thumbnail.dart";
import "package:photos/ui/rituals/ritual_editor_dialog.dart";
@@ -203,6 +204,9 @@ class _RitualOverviewCard extends StatelessWidget {
await showRitualEditor(context, ritual: ritual);
break;
case "delete":
+ if (!context.mounted) return;
+ final confirmed = await showDeleteRitualConfirmationSheet(context);
+ if (!context.mounted || !confirmed) return;
await ritualsService.deleteRitual(ritual.id);
break;
}
diff --git a/mobile/apps/photos/lib/ui/rituals/delete_ritual_confirmation_sheet.dart b/mobile/apps/photos/lib/ui/rituals/delete_ritual_confirmation_sheet.dart
new file mode 100644
index 0000000000..336b6d2a2a
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/rituals/delete_ritual_confirmation_sheet.dart
@@ -0,0 +1,161 @@
+import "package:flutter/material.dart";
+import "package:photos/theme/ente_theme.dart";
+
+const _tightTextHeightBehavior = TextHeightBehavior(
+ applyHeightToFirstAscent: false,
+ applyHeightToLastDescent: false,
+);
+
+Future<bool> showDeleteRitualConfirmationSheet(BuildContext context) async {
+ // Ensure any transient routes (like popup menus) have fully dismissed before
+ // we attempt to show another modal route.
+ await WidgetsBinding.instance.endOfFrame;
+ if (!context.mounted) return false;
+
+ final shouldDelete = await showModalBottomSheet<bool>(
+ context: context,
+ useRootNavigator: true,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ barrierColor: Colors.black.withValues(alpha: 0.55),
+ builder: (_) => const _DeleteRitualConfirmationSheet(),
+ );
+
+ return shouldDelete == true;
+}
+
+class _DeleteRitualConfirmationSheet extends StatelessWidget {
+ const _DeleteRitualConfirmationSheet();
+
+ @override
+ Widget build(BuildContext context) {
+ final mediaQuery = MediaQuery.of(context);
+ final isDark = Theme.of(context).brightness == Brightness.dark;
+ final colorScheme = getEnteColorScheme(context, inverse: isDark);
+ final textTheme = getEnteTextTheme(context, inverse: isDark);
+
+ final double bottomPadding =
+ 16 + mediaQuery.padding.bottom.clamp(0.0, 16.0).toDouble();
+
+ return SafeArea(
+ top: false,
+ bottom: false,
+ child: Padding(
+ padding: EdgeInsets.only(
+ left: 16,
+ right: 16,
+ bottom: bottomPadding,
+ ),
+ child: Align(
+ alignment: Alignment.bottomCenter,
+ child: Container(
+ constraints: const BoxConstraints(maxWidth: 480),
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated,
+ borderRadius: BorderRadius.circular(22),
+ border: Border.all(color: colorScheme.strokeFaint, width: 1),
+ boxShadow: [
+ BoxShadow(
+ color: Colors.black.withValues(alpha: 0.12),
+ blurRadius: 24,
+ offset: const Offset(0, -6),
+ ),
+ ],
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: Stack(
+ children: [
+ Positioned(
+ top: 6,
+ right: 6,
+ child: IconButton(
+ style: IconButton.styleFrom(
+ backgroundColor: colorScheme.fillFaint,
+ padding: const EdgeInsets.all(8),
+ shape: const CircleBorder(),
+ minimumSize: const Size(40, 40),
+ ),
+ onPressed: () => Navigator.of(context).pop(false),
+ icon: Icon(
+ Icons.close_rounded,
+ color: colorScheme.textBase,
+ ),
+ tooltip:
+ MaterialLocalizations.of(context).closeButtonTooltip,
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(20, 24, 20, 20),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ const SizedBox(height: 6),
+ Image.asset(
+ "assets/rituals/trash_rituals.png",
+ width: 170,
+ height: 170,
+ fit: BoxFit.contain,
+ filterQuality: FilterQuality.high,
+ errorBuilder: (context, error, stackTrace) => Icon(
+ Icons.delete_outline_rounded,
+ size: 96,
+ color: colorScheme.textFaint,
+ ),
+ excludeFromSemantics: true,
+ ),
+ const SizedBox(height: 18),
+ Text(
+ "Are you sure?",
+ textAlign: TextAlign.center,
+ style: const TextStyle(
+ fontFamily: "Nunito",
+ fontStyle: FontStyle.normal,
+ fontSize: 24,
+ fontWeight: FontWeight.w900,
+ letterSpacing: -0.72,
+ height: 1.15,
+ decoration: TextDecoration.none,
+ ).copyWith(color: colorScheme.textBase),
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ const SizedBox(height: 10),
+ Text(
+ "Deleting the ritual will not delete the album.",
+ textAlign: TextAlign.center,
+ style: textTheme.bodyMuted.copyWith(height: 1.4),
+ textHeightBehavior: _tightTextHeightBehavior,
+ ),
+ const SizedBox(height: 26),
+ SizedBox(
+ width: double.infinity,
+ child: ElevatedButton(
+ style: ElevatedButton.styleFrom(
+ backgroundColor: const Color(0xFFFF3B30),
+ foregroundColor: Colors.white,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(18),
+ ),
+ padding: const EdgeInsets.symmetric(
+ vertical: 16,
+ horizontal: 12,
+ ),
+ ),
+ onPressed: () => Navigator.of(context).pop(true),
+ child: Text(
+ "Delete ritual",
+ style: textTheme.bodyBold
+ .copyWith(color: Colors.white),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/rituals/ritual_page.dart b/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
index 59916fd1e7..babaa69c02 100644
--- a/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
+++ b/mobile/apps/photos/lib/ui/rituals/ritual_page.dart
@@ -17,6 +17,7 @@ import "package:photos/models/rituals/ritual_models.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/rituals/delete_ritual_confirmation_sheet.dart";
import "package:photos/ui/rituals/ritual_camera_page.dart";
import "package:photos/ui/rituals/ritual_day_thumbnail.dart";
import "package:photos/ui/rituals/ritual_editor_dialog.dart";
@@ -46,6 +47,28 @@ class _RitualPageState extends State<RitualPage> {
final GlobalKey _shareButtonKey = GlobalKey();
bool _sharing = false;
+ Future<void> _confirmAndDeleteRitual(Ritual ritual) async {
+ final shouldDelete = await showDeleteRitualConfirmationSheet(context);
+ if (!shouldDelete) return;
+
+ try {
+ await ritualsService.deleteRitual(ritual.id);
+ } catch (e, s) {
+ _logger.warning("Failed to delete ritual", e, s);
+ if (mounted) {
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: Text(context.l10n.somethingWentWrongPleaseTryAgain),
+ ),
+ );
+ }
+ return;
+ }
+
+ if (!mounted) return;
+ await Navigator.of(context).maybePop();
+ }
+
@override
void initState() {
super.initState();
@@ -219,10 +242,7 @@ class _RitualPageState extends State<RitualPage> {
await showRitualEditor(context, ritual: currentRitual);
},
onDelete: () async {
- await ritualsService.deleteRitual(currentRitual.id);
- if (context.mounted) {
- await Navigator.of(context).maybePop();
- }
+ await _confirmAndDeleteRitual(currentRitual);
},
),
const SizedBox(width: 16),
diff --git a/mobile/apps/photos/lib/ui/rituals/rituals_section.dart b/mobile/apps/photos/lib/ui/rituals/rituals_section.dart
index c134bd1e07..3006271ad2 100644
--- a/mobile/apps/photos/lib/ui/rituals/rituals_section.dart
+++ b/mobile/apps/photos/lib/ui/rituals/rituals_section.dart
@@ -5,6 +5,7 @@ import "package:photos/models/rituals/ritual_models.dart";
import "package:photos/service_locator.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/rituals/all_rituals_screen.dart";
+import "package:photos/ui/rituals/delete_ritual_confirmation_sheet.dart";
import "package:photos/ui/rituals/ritual_camera_page.dart";
import "package:photos/ui/rituals/ritual_editor_dialog.dart";
import "package:photos/utils/navigation_util.dart";
@@ -295,6 +296,9 @@ class _RitualCard extends StatelessWidget {
await showRitualEditor(context, ritual: ritual);
break;
case "delete":
+ final confirmed =
+ await showDeleteRitualConfirmationSheet(context);
+ if (!context.mounted || !confirmed) return;
await ritualsService.deleteRitual(ritual.id);
break;
}