浏览代码

Switch to new action sheet while deleting single file

Neeraj Gupta 2 年之前
父节点
当前提交
a39a422b22
共有 1 个文件被更改,包括 77 次插入50 次删除
  1. 77 50
      lib/ui/viewer/file/fading_app_bar.dart

+ 77 - 50
lib/ui/viewer/file/fading_app_bar.dart

@@ -23,6 +23,9 @@ import 'package:photos/services/hidden_service.dart';
 import 'package:photos/services/ignored_files_service.dart';
 import 'package:photos/services/ignored_files_service.dart';
 import 'package:photos/services/local_sync_service.dart';
 import 'package:photos/services/local_sync_service.dart';
 import 'package:photos/ui/common/progress_dialog.dart';
 import 'package:photos/ui/common/progress_dialog.dart';
+import 'package:photos/ui/components/action_sheet_widget.dart';
+import 'package:photos/ui/components/button_widget.dart';
+import 'package:photos/ui/components/models/button_type.dart';
 import 'package:photos/ui/create_collection_page.dart';
 import 'package:photos/ui/create_collection_page.dart';
 import 'package:photos/ui/viewer/file/custom_app_bar.dart';
 import 'package:photos/ui/viewer/file/custom_app_bar.dart';
 import 'package:photos/utils/delete_file_util.dart';
 import 'package:photos/utils/delete_file_util.dart';
@@ -229,11 +232,11 @@ class FadingAppBarState extends State<FadingAppBar> {
           }
           }
           return items;
           return items;
         },
         },
-        onSelected: (dynamic value) {
+        onSelected: (dynamic value) async {
           if (value == 1) {
           if (value == 1) {
             _download(widget.file);
             _download(widget.file);
           } else if (value == 2) {
           } else if (value == 2) {
-            _showDeleteSheet(widget.file);
+            await _showSingleFileDeleteSheet(widget.file);
           } else if (value == 3) {
           } else if (value == 3) {
             _setAs(widget.file);
             _setAs(widget.file);
           } else if (value == 4) {
           } else if (value == 4) {
@@ -341,71 +344,95 @@ class FadingAppBarState extends State<FadingAppBar> {
     );
     );
   }
   }
 
 
-  void _showDeleteSheet(File file) {
-    final List<Widget> actions = [];
-    if (file.uploadedFileID == null || file.localID == null) {
-      actions.add(
-        CupertinoActionSheetAction(
-          isDestructiveAction: true,
-          onPressed: () async {
-            await deleteFilesFromEverywhere(context, [file]);
-            Navigator.of(context, rootNavigator: true).pop();
-            widget.onFileRemoved(file);
+  Future<void> _showSingleFileDeleteSheet(File file) async {
+    final List<ButtonWidget> buttons = [];
+    final String fileType = file.fileType == FileType.video ? "video" : "photo";
+    final bool isBothLocalAndRemote =
+        file.uploadedFileID != null && file.localID != null;
+    final bool isLocalOnly =
+        file.uploadedFileID == null && file.localID != null;
+    final bool isRemoteOnly =
+        file.uploadedFileID != null && file.localID == null;
+    final String title = "Delete $fileType${isBothLocalAndRemote ? '' : '?'}";
+    const String bodyHighlight = "It will be deleted from all albums.";
+    String body = "";
+    if (isBothLocalAndRemote) {
+      body = "This photo is in both ente and your device.";
+    } else if (isRemoteOnly) {
+      body = "This photo will be deleted from ente.";
+    } else if (isLocalOnly) {
+      body = "This photo will be deleted from your device.";
+    } else {
+      throw AssertionError("Unexpected state");
+    }
+    // Add option to delete from ente
+    if (isBothLocalAndRemote || isRemoteOnly) {
+      buttons.add(
+        ButtonWidget(
+          labelText: isBothLocalAndRemote ? "Delete from ente" : "Yes, delete",
+          buttonType: ButtonType.neutral,
+          buttonSize: ButtonSize.large,
+          shouldStickToDarkTheme: true,
+          buttonAction: ButtonAction.first,
+          shouldSurfaceExecutionStates: true,
+          isInAlert: true,
+          onTap: () async {
+            await deleteFilesFromRemoteOnly(context, [file]);
+            showShortToast(context, "Moved to trash");
+            // Navigator.of(context, rootNavigator: true).pop();
+            // TODO: Fix behavior when inside a collection
           },
           },
-          child: const Text("Everywhere"),
         ),
         ),
       );
       );
-    } else {
-      // uploaded file which is present locally too
-      actions.add(
-        CupertinoActionSheetAction(
-          isDestructiveAction: true,
-          onPressed: () async {
+    }
+    // Add option to delete from local
+    if (isBothLocalAndRemote || isLocalOnly) {
+      buttons.add(
+        ButtonWidget(
+          labelText:
+              isBothLocalAndRemote ? "Delete from device" : "Yes, delete",
+          buttonType: ButtonType.neutral,
+          buttonSize: ButtonSize.large,
+          shouldStickToDarkTheme: true,
+          buttonAction: ButtonAction.second,
+          shouldSurfaceExecutionStates: false,
+          isInAlert: true,
+          onTap: () async {
             await deleteFilesOnDeviceOnly(context, [file]);
             await deleteFilesOnDeviceOnly(context, [file]);
-            showShortToast(context, "File deleted from device");
-            Navigator.of(context, rootNavigator: true).pop();
+            // showShortToast(context, "File deleted from device");
+            // Navigator.of(context, rootNavigator: true).pop();
             // TODO: Fix behavior when inside a device folder
             // TODO: Fix behavior when inside a device folder
           },
           },
-          child: const Text("Device"),
-        ),
-      );
-
-      actions.add(
-        CupertinoActionSheetAction(
-          isDestructiveAction: true,
-          onPressed: () async {
-            await deleteFilesFromRemoteOnly(context, [file]);
-            showShortToast(context, "Moved to trash");
-            Navigator.of(context, rootNavigator: true).pop();
-            // TODO: Fix behavior when inside a collection
-          },
-          child: const Text("ente"),
         ),
         ),
       );
       );
+    }
 
 
-      actions.add(
-        CupertinoActionSheetAction(
-          isDestructiveAction: true,
-          onPressed: () async {
+    if (isBothLocalAndRemote) {
+      buttons.add(
+        ButtonWidget(
+          labelText: "Delete from both",
+          buttonType: ButtonType.neutral,
+          buttonSize: ButtonSize.large,
+          shouldStickToDarkTheme: true,
+          buttonAction: ButtonAction.third,
+          shouldSurfaceExecutionStates: true,
+          isInAlert: true,
+          onTap: () async {
             await deleteFilesFromEverywhere(context, [file]);
             await deleteFilesFromEverywhere(context, [file]);
             Navigator.of(context, rootNavigator: true).pop();
             Navigator.of(context, rootNavigator: true).pop();
             widget.onFileRemoved(file);
             widget.onFileRemoved(file);
           },
           },
-          child: const Text("Everywhere"),
         ),
         ),
       );
       );
     }
     }
-    final action = CupertinoActionSheet(
-      title: const Text("Delete file?"),
-      actions: actions,
-      cancelButton: CupertinoActionSheetAction(
-        child: const Text("Cancel"),
-        onPressed: () {
-          Navigator.of(context, rootNavigator: true).pop();
-        },
-      ),
+    final ButtonAction? result = await showActionSheet(
+      context: context,
+      buttons: buttons,
+      actionSheetType: ActionSheetType.defaultActionSheet,
+      title: title,
+      body: body,
+      bodyHighlight: bodyHighlight,
     );
     );
-    showCupertinoModalPopup(context: context, builder: (_) => action);
   }
   }
 
 
   Future<void> _download(File file) async {
   Future<void> _download(File file) async {