Support for empty trash

This commit is contained in:
Neeraj Gupta 2021-10-25 20:27:41 +05:30
parent 86de134cb5
commit 138501388d
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
3 changed files with 57 additions and 0 deletions

View file

@ -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;
}
}
}

View file

@ -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;
}

View file

@ -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 = [];