Browse Source

Merge pull request #111 from ente-io/empty_trash

Vishnu Mohandas 3 years ago
parent
commit
c2037942d1

+ 20 - 0
lib/services/trash_sync_service.dart

@@ -129,4 +129,24 @@ class TrashSyncService {
       rethrow;
     }
   }
+
+  Future<void> emptyTrash() async {
+    final params = <String, dynamic>{};
+    params["lastUpdatedAt"] = _getSyncTime();
+    try {
+      await _dio.post(
+        Configuration.instance.getHttpEndpoint() + "/trash/empty",
+        options: Options(
+          headers: {
+            "X-Auth-Token": Configuration.instance.getToken(),
+          },
+        ),
+        data: params,
+      );
+      await _trashDB.clearTable();
+    } catch (e, s) {
+      _logger.severe("failed to empty trash", e, s);
+      rethrow;
+    }
+  }
 }

+ 13 - 0
lib/ui/gallery_app_bar_widget.dart

@@ -192,6 +192,19 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
         },
       ));
     }
+    if(widget.type == GalleryAppBarType.trash) {
+      actions.add(
+        Tooltip(
+          message: "empty trash",
+          child: IconButton(
+            icon: Icon(Icons.delete_forever),
+            onPressed: () async {
+              await emptyTrash(context);
+            },
+          ),
+        ),
+      );
+    }
     return actions;
   }
 

+ 24 - 0
lib/utils/delete_file_util.dart

@@ -225,6 +225,30 @@ Future<bool> deleteFromTrash(
   }
 }
 
+
+Future<bool> emptyTrash(BuildContext context) async {
+  final result = await showChoiceDialog(context, "empty trash?",
+      "all files will be permanently removed from your ente account",
+      firstAction: "yes", actionType: ActionType.critical);
+  if (result != DialogUserChoice.firstChoice) {
+    return false;
+  }
+  final dialog = createProgressDialog(context, "please wait...");
+  await dialog.show();
+  try {
+    await TrashSyncService.instance.emptyTrash();
+    showToast("done");
+    await dialog.hide();
+    Bus.instance.fire(FilesUpdatedEvent((List<File>.empty()), type: EventType.deleted));
+    return true;
+  } catch (e, s) {
+    _logger.info("failed empty trash", e, s);
+    await dialog.hide();
+    await showGenericErrorDialog(context);
+    return false;
+  }
+}
+
 Future<bool> deleteLocalFiles(
     BuildContext context, List<String> localIDs) async {
   final List<String> deletedIDs = [];