Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use Locker bottom sheet helpers for delete flows

aman-pilotc43fb39cb541
diff --git a/mobile/apps/locker/lib/ui/components/delete_confirmation_sheet.dart b/mobile/apps/locker/lib/ui/components/delete_confirmation_sheet.dart
index eb2890f7dc..85e5fd5b30 100644
--- a/mobile/apps/locker/lib/ui/components/delete_confirmation_sheet.dart
+++ b/mobile/apps/locker/lib/ui/components/delete_confirmation_sheet.dart
@@ -19,7 +19,7 @@ Future<DeleteConfirmationResult?> showDeleteConfirmationSheet(
required String title,
required String body,
required String deleteButtonLabel,
- required String assetPath,
+ required Widget illustration,
bool showDeleteFromAllCollectionsOption = false,
}) {
return showBottomSheetComponent<DeleteConfirmationResult>(
@@ -28,7 +28,7 @@ Future<DeleteConfirmationResult?> showDeleteConfirmationSheet(
title: title,
body: body,
deleteButtonLabel: deleteButtonLabel,
- assetPath: assetPath,
+ illustration: illustration,
showDeleteFromAllCollectionsOption: showDeleteFromAllCollectionsOption,
),
);
@@ -38,7 +38,7 @@ class DeleteConfirmationSheet extends StatefulWidget {
final String title;
final String body;
final String deleteButtonLabel;
- final String assetPath;
+ final Widget illustration;
final bool showDeleteFromAllCollectionsOption;
const DeleteConfirmationSheet({
@@ -46,7 +46,7 @@ class DeleteConfirmationSheet extends StatefulWidget {
required this.title,
required this.body,
required this.deleteButtonLabel,
- required this.assetPath,
+ required this.illustration,
required this.showDeleteFromAllCollectionsOption,
});
@@ -63,7 +63,7 @@ class _DeleteConfirmationSheetState extends State<DeleteConfirmationSheet> {
final colors = context.componentColors;
return BottomSheetComponent(
- illustration: Image.asset(widget.assetPath),
+ illustration: widget.illustration,
title: widget.title,
content: Column(
mainAxisSize: MainAxisSize.min,
diff --git a/mobile/apps/locker/lib/ui/pages/collection_page.dart b/mobile/apps/locker/lib/ui/pages/collection_page.dart
index 72d269eea7..4aee29ca21 100644
--- a/mobile/apps/locker/lib/ui/pages/collection_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/collection_page.dart
@@ -2,7 +2,6 @@ import "dart:async";
import 'package:ente_components/ente_components.dart';
import 'package:ente_events/event_bus.dart';
-import "package:ente_ui/utils/dialog_util.dart";
import 'package:flutter/material.dart';
import "package:hugeicons/hugeicons.dart";
import 'package:locker/events/collections_updated_event.dart';
@@ -23,6 +22,7 @@ import 'package:locker/ui/pages/home_page.dart';
import 'package:locker/ui/pages/uploader_page.dart';
import "package:locker/ui/sharing/share_collection_bottom_sheet.dart";
import "package:locker/ui/viewer/actions/file_selection_overlay_bar.dart";
+import "package:locker/utils/error_sheet.dart";
import "package:logging/logging.dart";
class CollectionPage extends UploaderPage {
@@ -178,7 +178,7 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
}
} catch (e, s) {
_logger.severe(e, s);
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
diff --git a/mobile/apps/locker/lib/ui/pages/trash_page.dart b/mobile/apps/locker/lib/ui/pages/trash_page.dart
index 5eaca54e69..2c3dc90102 100644
--- a/mobile/apps/locker/lib/ui/pages/trash_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/trash_page.dart
@@ -16,6 +16,8 @@ import 'package:locker/services/trash/trash_service.dart';
import "package:locker/ui/components/delete_confirmation_sheet.dart";
import 'package:locker/ui/components/item_list_view.dart';
import "package:locker/ui/viewer/actions/file_selection_overlay_bar.dart";
+import "package:locker/utils/bottom_sheet_illustration.dart";
+import "package:locker/utils/error_sheet.dart";
class TrashPage extends StatefulWidget {
final List<TrashFile> trashFiles;
@@ -67,7 +69,7 @@ class _TrashPageState extends State<TrashPage> {
title: context.l10n.emptyTrash,
body: context.l10n.emptyTrashConfirmation,
deleteButtonLabel: context.l10n.emptyTrash,
- assetPath: "assets/collection_delete_icon.png",
+ illustration: LockerBottomSheetIllustration.collectionDelete,
);
if (result?.buttonResult.action == ButtonAction.first && mounted) {
@@ -99,7 +101,7 @@ class _TrashPageState extends State<TrashPage> {
} catch (error) {
await dialog.hide();
if (mounted) {
- await showGenericErrorBottomSheet(context: context, error: error);
+ await showLockerErrorSheet(context, error);
}
}
}
diff --git a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
index 33600a6c24..f75ccf89b3 100644
--- a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
+++ b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
@@ -22,7 +22,9 @@ import "package:locker/services/trash/trash_service.dart";
import "package:locker/ui/components/add_to_collection_sheet.dart";
import "package:locker/ui/components/delete_confirmation_sheet.dart";
import "package:locker/ui/components/selection_action_button_widget.dart";
+import "package:locker/utils/bottom_sheet_illustration.dart";
import "package:locker/utils/collection_list_util.dart";
+import "package:locker/utils/error_sheet.dart";
import "package:locker/utils/file_actions.dart";
import "package:locker/utils/file_util.dart";
import "package:logging/logging.dart";
@@ -552,7 +554,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
} catch (e, stackTrace) {
_logger.severe("Failed to download file: $e", e, stackTrace);
if (context.mounted) {
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}
@@ -573,7 +575,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
} catch (e, stackTrace) {
_logger.severe("Failed to download files: $e", e, stackTrace);
if (context.mounted) {
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}
@@ -699,7 +701,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
await dialog.hide();
_logger.severe('Failed add-to operation: $e');
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}
@@ -734,7 +736,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
title: context.l10n.areYouSure,
body: context.l10n.deleteMultipleFilesDialogBody(ownedFiles.length),
deleteButtonLabel: context.l10n.yesDeleteFiles(ownedFiles.length),
- assetPath: "assets/file_delete_icon.png",
+ illustration: LockerBottomSheetIllustration.fileDelete,
);
if (confirmation?.buttonResult.action != ButtonAction.first) {
@@ -775,7 +777,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
if (!context.mounted) {
return;
}
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
@@ -861,7 +863,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
_logger.severe('Failed to restore files: $e', e, stackTrace);
if (context.mounted) {
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}
@@ -875,7 +877,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
title: context.l10n.permanentlyDelete,
body: context.l10n.permanentlyDeleteFilesBody(files.length),
deleteButtonLabel: context.l10n.yesDelete,
- assetPath: "assets/collection_delete_icon.png",
+ illustration: LockerBottomSheetIllustration.collectionDelete,
);
if (confirmation?.buttonResult.action != ButtonAction.first) {
@@ -907,7 +909,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
_logger.severe('Failed to delete files from trash: $e', e, stackTrace);
if (context.mounted) {
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}
diff --git a/mobile/apps/locker/lib/utils/bottom_sheet_illustration.dart b/mobile/apps/locker/lib/utils/bottom_sheet_illustration.dart
new file mode 100644
index 0000000000..8d660731ae
--- /dev/null
+++ b/mobile/apps/locker/lib/utils/bottom_sheet_illustration.dart
@@ -0,0 +1,27 @@
+import "package:flutter/material.dart";
+
+/// Standard Locker illustrations shown at the top of bottom sheets.
+class LockerBottomSheetIllustration extends StatelessWidget {
+ const LockerBottomSheetIllustration._(this.assetPath);
+
+ static const warningGrey = LockerBottomSheetIllustration._(
+ "assets/warning-grey.png",
+ );
+ static const warningBlue = LockerBottomSheetIllustration._(
+ "assets/warning-blue.png",
+ );
+ static const warningRed = LockerBottomSheetIllustration._(
+ "assets/warning-red.png",
+ );
+ static const fileDelete = LockerBottomSheetIllustration._(
+ "assets/file_delete_icon.png",
+ );
+ static const collectionDelete = LockerBottomSheetIllustration._(
+ "assets/collection_delete_icon.png",
+ );
+
+ final String assetPath;
+
+ @override
+ Widget build(BuildContext context) => Image.asset(assetPath);
+}
diff --git a/mobile/apps/locker/lib/utils/error_sheet.dart b/mobile/apps/locker/lib/utils/error_sheet.dart
new file mode 100644
index 0000000000..f4b47bbeaf
--- /dev/null
+++ b/mobile/apps/locker/lib/utils/error_sheet.dart
@@ -0,0 +1,26 @@
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/utils/dialog_util.dart";
+import "package:ente_utils/email_util.dart" show sendLogs;
+import "package:flutter/material.dart";
+import "package:locker/utils/bottom_sheet_illustration.dart";
+
+/// Shows Locker's standard generic-error bottom sheet.
+///
+/// Parses [error] into a user-facing message via [parseErrorForUI] and offers a
+/// "contact support" action that ships logs. Kept as a single helper so every
+/// catch block stays a one-liner instead of re-inlining the same sheet config.
+Future<void> showLockerErrorSheet(BuildContext context, Object? error) {
+ return showErrorBottomSheetComponent<void>(
+ context: context,
+ title: context.strings.error,
+ message: parseErrorForUI(
+ context,
+ context.strings.itLooksLikeSomethingWentWrongPleaseRetryAfterSome,
+ error: error,
+ ),
+ illustration: LockerBottomSheetIllustration.warningGrey,
+ actionLabel: context.strings.contactSupport,
+ onActionTap: () => sendLogs(context, "[email protected]", postShare: () {}),
+ );
+}
diff --git a/mobile/apps/locker/lib/utils/file_actions.dart b/mobile/apps/locker/lib/utils/file_actions.dart
index 1ab1a4d9fa..eb13eb8c9b 100644
--- a/mobile/apps/locker/lib/utils/file_actions.dart
+++ b/mobile/apps/locker/lib/utils/file_actions.dart
@@ -22,6 +22,8 @@ import "package:locker/ui/pages/base_info_page.dart";
import "package:locker/ui/pages/emergency_contact_page.dart";
import "package:locker/ui/pages/personal_note_page.dart";
import "package:locker/ui/pages/physical_records_page.dart";
+import "package:locker/utils/bottom_sheet_illustration.dart";
+import "package:locker/utils/error_sheet.dart";
import "package:logging/logging.dart";
/// Utility class for common file actions like edit, share, delete, and favorites
@@ -199,7 +201,7 @@ class FileActions {
if (!context.mounted) {
return;
}
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
@@ -270,7 +272,7 @@ class FileActions {
if (e is SharingNotPermittedForFreeAccountsError) {
await showSubscriptionRequiredSheet(context);
} else {
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}
@@ -287,7 +289,7 @@ class FileActions {
title: context.l10n.areYouSure,
body: context.l10n.deleteMultipleFilesDialogBody(1),
deleteButtonLabel: context.l10n.yesDeleteFiles(1),
- assetPath: "assets/file_delete_icon.png",
+ illustration: LockerBottomSheetIllustration.fileDelete,
);
if (confirmation?.buttonResult.action != ButtonAction.first) {
@@ -320,7 +322,7 @@ class FileActions {
await dialog.hide();
if (context.mounted) {
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}
@@ -340,7 +342,7 @@ class FileActions {
title: context.l10n.areYouSure,
body: context.l10n.deleteMultipleFilesDialogBody(files.length),
deleteButtonLabel: context.l10n.yesDeleteFiles(files.length),
- assetPath: "assets/file_delete_icon.png",
+ illustration: LockerBottomSheetIllustration.fileDelete,
);
if (confirmation?.buttonResult.action != ButtonAction.first) {
@@ -386,7 +388,7 @@ class FileActions {
if (!context.mounted) {
return;
}
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
@@ -436,7 +438,7 @@ class FileActions {
await dialog.hide();
if (context.mounted) {
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}
@@ -493,7 +495,7 @@ class FileActions {
await dialog.hide();
if (context.mounted) {
- await showGenericErrorBottomSheet(context: context, error: e);
+ await showLockerErrorSheet(context, e);
}
}
}