Browse Source

Add unhide option in overflow menu

Neeraj Gupta 2 years ago
parent
commit
66e7fc0560

+ 4 - 4
lib/services/collections_service.dart

@@ -826,17 +826,17 @@ class CollectionsService {
     List<File> files,
     List<File> files,
   ) {
   ) {
     if (toCollectionID == fromCollectionID) {
     if (toCollectionID == fromCollectionID) {
-      throw AssertionError("can't move to same album");
+      throw AssertionError("Can't move to same album");
     }
     }
     for (final file in files) {
     for (final file in files) {
       if (file.uploadedFileID == null) {
       if (file.uploadedFileID == null) {
-        throw AssertionError("can only move uploaded memories");
+        throw AssertionError("Can only move uploaded memories");
       }
       }
       if (file.collectionID != fromCollectionID) {
       if (file.collectionID != fromCollectionID) {
-        throw AssertionError("all memories should belong to the same album");
+        throw AssertionError("All memories should belong to the same album");
       }
       }
       if (file.ownerID != Configuration.instance.getUserID()) {
       if (file.ownerID != Configuration.instance.getUserID()) {
-        throw AssertionError("can only move memories uploaded by you");
+        throw AssertionError("Can only move memories uploaded by you");
       }
       }
     }
     }
   }
   }

+ 1 - 1
lib/ui/create_collection_page.dart

@@ -293,7 +293,7 @@ class _CreateCollectionPageState extends State<CreateCollectionPage> {
   Future<bool> _moveFilesToCollection(int toCollectionID) async {
   Future<bool> _moveFilesToCollection(int toCollectionID) async {
     final String message = widget.actionType == CollectionActionType.moveFiles
     final String message = widget.actionType == CollectionActionType.moveFiles
         ? "Moving files to album..."
         ? "Moving files to album..."
-        : "Un hide files to album";
+        : "Unhiding files to album";
     final dialog = createProgressDialog(context, message);
     final dialog = createProgressDialog(context, message);
     await dialog.show();
     await dialog.show();
     try {
     try {

+ 64 - 16
lib/ui/viewer/file/fading_app_bar.dart

@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
 import 'package:like_button/like_button.dart';
 import 'package:like_button/like_button.dart';
 import 'package:logging/logging.dart';
 import 'package:logging/logging.dart';
 import 'package:media_extension/media_extension.dart';
 import 'package:media_extension/media_extension.dart';
+import 'package:page_transition/page_transition.dart';
 import 'package:path/path.dart' as file_path;
 import 'package:path/path.dart' as file_path;
 import 'package:photo_manager/photo_manager.dart';
 import 'package:photo_manager/photo_manager.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/core/event_bus.dart';
@@ -16,6 +17,7 @@ import 'package:photos/events/local_photos_updated_event.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/models/ignored_file.dart';
 import 'package:photos/models/ignored_file.dart';
+import 'package:photos/models/selected_files.dart';
 import 'package:photos/models/trash_file.dart';
 import 'package:photos/models/trash_file.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/favorites_service.dart';
 import 'package:photos/services/favorites_service.dart';
@@ -23,6 +25,7 @@ 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/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';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/dialog_util.dart';
@@ -101,6 +104,8 @@ class FadingAppBarState extends State<FadingAppBar> {
 
 
   AppBar _buildAppBar() {
   AppBar _buildAppBar() {
     debugPrint("building app bar");
     debugPrint("building app bar");
+    Set<int> hiddenCollections =
+        CollectionsService.instance.getHiddenCollections();
     final List<Widget> actions = [];
     final List<Widget> actions = [];
     final isTrashedFile = widget.file is TrashFile;
     final isTrashedFile = widget.file is TrashFile;
     final shouldShowActions = widget.shouldShowActions && !isTrashedFile;
     final shouldShowActions = widget.shouldShowActions && !isTrashedFile;
@@ -179,23 +184,45 @@ class FadingAppBarState extends State<FadingAppBar> {
           }
           }
           if (widget.file.ownerID != null &&
           if (widget.file.ownerID != null &&
               widget.file.ownerID == widget.userID) {
               widget.file.ownerID == widget.userID) {
-            items.add(
-              PopupMenuItem(
-                value: 4,
-                child: Row(
-                  children: [
-                    Icon(
-                      Icons.visibility_off,
-                      color: Theme.of(context).iconTheme.color,
-                    ),
-                    const Padding(
-                      padding: EdgeInsets.all(8),
-                    ),
-                    const Text("Hide"),
-                  ],
+            final bool isAlreadyHidden =
+                hiddenCollections.contains(widget.file.collectionID);
+            if (!isAlreadyHidden) {
+              items.add(
+                PopupMenuItem(
+                  value: 4,
+                  child: Row(
+                    children: [
+                      Icon(
+                        Icons.visibility_off,
+                        color: Theme.of(context).iconTheme.color,
+                      ),
+                      const Padding(
+                        padding: EdgeInsets.all(8),
+                      ),
+                      const Text("Hide"),
+                    ],
+                  ),
                 ),
                 ),
-              ),
-            );
+              );
+            } else {
+              items.add(
+                PopupMenuItem(
+                  value: 5,
+                  child: Row(
+                    children: [
+                      Icon(
+                        Icons.visibility,
+                        color: Theme.of(context).iconTheme.color,
+                      ),
+                      const Padding(
+                        padding: EdgeInsets.all(8),
+                      ),
+                      const Text("Unhide"),
+                    ],
+                  ),
+                ),
+              );
+            }
           }
           }
           return items;
           return items;
         },
         },
@@ -208,6 +235,8 @@ class FadingAppBarState extends State<FadingAppBar> {
             _setAs(widget.file);
             _setAs(widget.file);
           } else if (value == 4) {
           } else if (value == 4) {
             _handleHideRequest(context);
             _handleHideRequest(context);
+          } else if (value == 5) {
+            _handleUnHideRequest(context);
           }
           }
         },
         },
       ),
       ),
@@ -225,12 +254,31 @@ class FadingAppBarState extends State<FadingAppBar> {
     try {
     try {
       final hideResult =
       final hideResult =
           await CollectionsService.instance.hideFiles(context, [widget.file]);
           await CollectionsService.instance.hideFiles(context, [widget.file]);
+      if (hideResult) {
+        // Navigator.of(context, rootNavigator: true).pop();
+      }
     } catch (e, s) {
     } catch (e, s) {
       _logger.severe("failed to update file visibility", e, s);
       _logger.severe("failed to update file visibility", e, s);
       await showGenericErrorDialog(context);
       await showGenericErrorDialog(context);
     }
     }
   }
   }
 
 
+  Future<void> _handleUnHideRequest(BuildContext context) async {
+    final s = SelectedFiles();
+    s.files.add(widget.file);
+    Navigator.push(
+      context,
+      PageTransition(
+        type: PageTransitionType.bottomToTop,
+        child: CreateCollectionPage(
+          s,
+          null,
+          actionType: CollectionActionType.unHide,
+        ),
+      ),
+    );
+  }
+
   Widget _getFavoriteButton() {
   Widget _getFavoriteButton() {
     return FutureBuilder(
     return FutureBuilder(
       future: FavoritesService.instance.isFavorite(widget.file),
       future: FavoritesService.instance.isFavorite(widget.file),