Przeglądaj źródła

hook more options on file selections

Neeraj Gupta 2 lat temu
rodzic
commit
ff4611b192

+ 9 - 1
lib/models/gallery_type.dart

@@ -19,10 +19,10 @@ extension GalleyTypeExtension on GalleryType {
       case GalleryType.localFolder:
       case GalleryType.localFolder:
       case GalleryType.ownedCollection:
       case GalleryType.ownedCollection:
       case GalleryType.searchResults:
       case GalleryType.searchResults:
+      case GalleryType.favorite:
         return true;
         return true;
 
 
       case GalleryType.hidden:
       case GalleryType.hidden:
-      case GalleryType.favorite:
       case GalleryType.trash:
       case GalleryType.trash:
       case GalleryType.sharedCollection:
       case GalleryType.sharedCollection:
         return false;
         return false;
@@ -95,6 +95,10 @@ extension GalleyTypeExtension on GalleryType {
     }
     }
   }
   }
 
 
+  bool showUnArchiveOption() {
+    return this == GalleryType.archive;
+  }
+
   bool showHideOption() {
   bool showHideOption() {
     switch (this) {
     switch (this) {
       case GalleryType.ownedCollection:
       case GalleryType.ownedCollection:
@@ -112,6 +116,10 @@ extension GalleyTypeExtension on GalleryType {
     }
     }
   }
   }
 
 
+  bool showUnHideOption() {
+    return this == GalleryType.hidden;
+  }
+
   bool showFavoriteOption() {
   bool showFavoriteOption() {
     switch (this) {
     switch (this) {
       case GalleryType.ownedCollection:
       case GalleryType.ownedCollection:

+ 11 - 1
lib/ui/collections/collection_item_widget.dart

@@ -1,6 +1,8 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/db/files_db.dart';
+import 'package:photos/models/collection.dart';
 import 'package:photos/models/collection_items.dart';
 import 'package:photos/models/collection_items.dart';
+import 'package:photos/models/gallery_type.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/ui/viewer/file/no_thumbnail_widget.dart';
 import 'package:photos/ui/viewer/file/no_thumbnail_widget.dart';
 import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
 import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
@@ -83,7 +85,15 @@ class CollectionItem extends StatelessWidget {
         ],
         ],
       ),
       ),
       onTap: () {
       onTap: () {
-        routeToPage(context, CollectionPage(c));
+        routeToPage(
+          context,
+          CollectionPage(
+            c,
+            appBarType: (c.collection.type == CollectionType.favorites
+                ? GalleryType.favorite
+                : GalleryType.ownedCollection),
+          ),
+        );
       },
       },
     );
     );
   }
   }

+ 86 - 0
lib/ui/viewer/actions/file_selection_actions_widget.dart

@@ -5,15 +5,19 @@ import 'package:photos/core/configuration.dart';
 import 'package:photos/models/collection.dart';
 import 'package:photos/models/collection.dart';
 import 'package:photos/models/device_collection.dart';
 import 'package:photos/models/device_collection.dart';
 import 'package:photos/models/gallery_type.dart';
 import 'package:photos/models/gallery_type.dart';
+import 'package:photos/models/magic_metadata.dart';
 import 'package:photos/models/selected_file_breakup.dart';
 import 'package:photos/models/selected_file_breakup.dart';
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/collections_service.dart';
+import 'package:photos/services/hidden_service.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/ui/actions/collection/collection_file_actions.dart';
 import 'package:photos/ui/actions/collection/collection_file_actions.dart';
 import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
 import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
 import 'package:photos/ui/components/blur_menu_item_widget.dart';
 import 'package:photos/ui/components/blur_menu_item_widget.dart';
 import 'package:photos/ui/components/bottom_action_bar/expanded_menu_widget.dart';
 import 'package:photos/ui/components/bottom_action_bar/expanded_menu_widget.dart';
 import 'package:photos/ui/create_collection_page.dart';
 import 'package:photos/ui/create_collection_page.dart';
+import 'package:photos/utils/delete_file_util.dart';
+import 'package:photos/utils/magic_util.dart';
 
 
 class FileSelectionActionWidget extends StatefulWidget {
 class FileSelectionActionWidget extends StatefulWidget {
   final GalleryType type;
   final GalleryType type;
@@ -111,6 +115,7 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
           leadingIcon: Icons.delete_outline,
           leadingIcon: Icons.delete_outline,
           labelText: "Delete$suffix",
           labelText: "Delete$suffix",
           menuItemColor: colorScheme.fillFaint,
           menuItemColor: colorScheme.fillFaint,
+          onTap: _onDeleteClick,
         ),
         ),
       );
       );
     }
     }
@@ -121,6 +126,16 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
           leadingIcon: Icons.visibility_off_outlined,
           leadingIcon: Icons.visibility_off_outlined,
           labelText: "Hide$suffix",
           labelText: "Hide$suffix",
           menuItemColor: colorScheme.fillFaint,
           menuItemColor: colorScheme.fillFaint,
+          onTap: _onHideClick,
+        ),
+      );
+    } else if (widget.type.showUnHideOption()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.visibility_off_outlined,
+          labelText: "Unhide$suffix",
+          menuItemColor: colorScheme.fillFaint,
+          onTap: _onUnhideClick,
         ),
         ),
       );
       );
     }
     }
@@ -130,6 +145,16 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
           leadingIcon: Icons.archive_outlined,
           leadingIcon: Icons.archive_outlined,
           labelText: "Archive$suffix",
           labelText: "Archive$suffix",
           menuItemColor: colorScheme.fillFaint,
           menuItemColor: colorScheme.fillFaint,
+          onTap: _onArchiveClick,
+        ),
+      );
+    } else if (widget.type.showUnArchiveOption()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.unarchive_outlined,
+          labelText: "Unarchive$suffix",
+          menuItemColor: colorScheme.fillFaint,
+          onTap: _onUnArchiveClick,
         ),
         ),
       );
       );
     }
     }
@@ -143,6 +168,15 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
           onTap: _onFavoriteClick,
           onTap: _onFavoriteClick,
         ),
         ),
       );
       );
+    } else if (widget.type.showUnFavoriteOption()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.favorite,
+          labelText: "Remove from favorite$suffix",
+          menuItemColor: colorScheme.fillFaint,
+          onTap: _onUnFavoriteClick,
+        ),
+      );
     }
     }
 
 
     if (firstList.isNotEmpty) {
     if (firstList.isNotEmpty) {
@@ -171,6 +205,10 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
     await _selectionCollectionForAction(CollectionActionType.addFiles);
     await _selectionCollectionForAction(CollectionActionType.addFiles);
   }
   }
 
 
+  Future<void> _onDeleteClick() async {
+    showDeleteSheet(context, widget.selectedFiles);
+  }
+
   Future<void> _removeFilesFromAlbum() async {
   Future<void> _removeFilesFromAlbum() async {
     await collectionActions.showRemoveFromCollectionSheet(
     await collectionActions.showRemoveFromCollectionSheet(
       context,
       context,
@@ -190,6 +228,54 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
     }
     }
   }
   }
 
 
+  Future<void> _onUnFavoriteClick() async {
+    final result = await collectionActions.updateFavorites(
+      context,
+      split.ownedByCurrentUser,
+      false,
+    );
+    if (result) {
+      widget.selectedFiles.clearAll();
+    }
+  }
+
+  Future<void> _onArchiveClick() async {
+    await changeVisibility(
+      context,
+      split.ownedByCurrentUser,
+      visibilityArchive,
+    );
+    widget.selectedFiles.clearAll();
+  }
+
+  Future<void> _onUnArchiveClick() async {
+    await changeVisibility(
+      context,
+      split.ownedByCurrentUser,
+      visibilityVisible,
+    );
+    widget.selectedFiles.clearAll();
+  }
+
+  Future<void> _onHideClick() async {
+    await CollectionsService.instance.hideFiles(
+      context,
+      split.ownedByCurrentUser,
+    );
+
+    widget.selectedFiles.clearAll();
+  }
+
+  Future<void> _onUnhideClick() async {
+    if (split.pendingUploads.isNotEmpty || split.ownedByOtherUsers.isNotEmpty) {
+      widget.selectedFiles
+          .unSelectAll(split.pendingUploads.toSet(), skipNotify: true);
+      widget.selectedFiles
+          .unSelectAll(split.ownedByOtherUsers.toSet(), skipNotify: true);
+    }
+    await _selectionCollectionForAction(CollectionActionType.unHide);
+  }
+
   Future<Object?> _selectionCollectionForAction(
   Future<Object?> _selectionCollectionForAction(
     CollectionActionType type,
     CollectionActionType type,
   ) async {
   ) async {

+ 0 - 3
lib/ui/viewer/gallery/collection_page.dart

@@ -1,7 +1,6 @@
 // @dart=2.9
 // @dart=2.9
 
 
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
-import 'package:photos/core/configuration.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/events/collection_updated_event.dart';
 import 'package:photos/events/collection_updated_event.dart';
@@ -60,8 +59,6 @@ class _CollectionPageState extends State<CollectionPage> {
     if (widget.hasVerifiedLock == false && widget.c.collection.isHidden()) {
     if (widget.hasVerifiedLock == false && widget.c.collection.isHidden()) {
       return const EmptyState();
       return const EmptyState();
     }
     }
-    final int ownerID = Configuration.instance.getUserID();
-    final int collectionOwner = widget.c.collection.owner.id;
     final initialFiles =
     final initialFiles =
         widget.c.thumbnail != null ? [widget.c.thumbnail] : null;
         widget.c.thumbnail != null ? [widget.c.thumbnail] : null;
     final gallery = Gallery(
     final gallery = Gallery(