Browse Source

[archive]add progress dialog & try catch block

Neeraj Gupta 3 years ago
parent
commit
ab17ad0cea
1 changed files with 25 additions and 8 deletions
  1. 25 8
      lib/ui/gallery_app_bar_widget.dart

+ 25 - 8
lib/ui/gallery_app_bar_widget.dart

@@ -267,14 +267,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
         },
         onSelected: (value) async {
           if (value == 1) {
-            if (showArchive) {
-              await changeVisibility(widget.selectedFiles.files.toList(), 1);
-              showToast("successfully archived", toastLength: Toast.LENGTH_SHORT);
-            } else {
-              await changeVisibility(widget.selectedFiles.files.toList(), 0);
-              showToast("successfully unarchived", toastLength: Toast.LENGTH_SHORT);
-            }
-            _clearSelectedFiles();
+            await _handleVisibilityChangeRequest(context, showArchive);
           }
         },
       ));
@@ -282,6 +275,30 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
     return actions;
   }
 
+  Future<void> _handleVisibilityChangeRequest(BuildContext context, bool showArchive) async {
+    final dialog = createProgressDialog(context, "please wait...");
+    await dialog.show();
+    try {
+      if (showArchive) {
+        await changeVisibility(widget.selectedFiles.files.toList(), 1);
+        showToast("successfully archived",
+            toastLength: Toast.LENGTH_SHORT);
+      } else {
+        await changeVisibility(widget.selectedFiles.files.toList(), 0);
+        showToast("successfully unarchived",
+            toastLength: Toast.LENGTH_SHORT);
+      }
+      await dialog.hide();
+    } catch (e, s) {
+      _logger.severe("archive/unarchive failed", e, s);
+      await dialog.hide();
+      await showGenericErrorDialog(context);
+
+    } finally {
+      _clearSelectedFiles();
+    }
+  }
+
   void _shareSelected(BuildContext context) {
     share(context, widget.selectedFiles.files.toList());
   }