瀏覽代碼

Add confirmation dialog while deleting shared albums

Neeraj Gupta 2 年之前
父節點
當前提交
80db5af7b8

+ 39 - 0
lib/ui/actions/collection/collection_sharing_actions.dart

@@ -279,6 +279,7 @@ class CollectionActions {
     }
   }
 
+  // deleteCollectionSheet returns true if the album is successfully deleted
   Future<bool> deleteCollectionSheet(
     BuildContext bContext,
     Collection collection,
@@ -288,6 +289,13 @@ class CollectionActions {
     if (collection.owner!.id != currentUserID) {
       throw AssertionError("Can not delete album owned by others");
     }
+    if (collection.hasSharees) {
+      final bool confirmDelete =
+          await _confirmSharedAlbumDeletion(bContext, collection);
+      if (!confirmDelete) {
+        return false;
+      }
+    }
     final actionResult = await showActionSheet(
       context: bContext,
       buttons: [
@@ -368,6 +376,37 @@ class CollectionActions {
     return false;
   }
 
+  // _confirmSharedAlbumDeletion should be shown when user tries to delete an
+  // album shared with other ente users.
+  Future<bool> _confirmSharedAlbumDeletion(
+    BuildContext context,
+    Collection collection,
+  ) async {
+    final ButtonAction? result = await showActionSheet(
+      context: context,
+      buttons: [
+        const ButtonWidget(
+          buttonType: ButtonType.critical,
+          isInAlert: true,
+          shouldStickToDarkTheme: true,
+          buttonAction: ButtonAction.first,
+          labelText: "Delete album",
+        ),
+        const ButtonWidget(
+          buttonType: ButtonType.secondary,
+          buttonAction: ButtonAction.cancel,
+          isInAlert: true,
+          shouldStickToDarkTheme: true,
+          labelText: "Cancel",
+        )
+      ],
+      title: "Delete shared album?",
+      body: "The album will be deleted for everyone\n\nYou will lose access to "
+          "shared photos in this album that are owned by others",
+    );
+    return result != null && result == ButtonAction.first;
+  }
+
   /*
   _moveFilesFromCurrentCollection removes the file from the current
   collection. Based on the file and collection ownership, files will be

+ 1 - 1
lib/ui/viewer/gallery/gallery_app_bar_widget.dart

@@ -161,7 +161,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
           labelText: "Cancel",
         )
       ],
-      title: "Leave shared album??",
+      title: "Leave shared album?",
       body: "Photos added by you will be removed from the album",
     );
     if (result != null && mounted) {