Selaa lähdekoodia

Use existing logic to show relevant selection actions upon selection

ashilkn 2 vuotta sitten
vanhempi
commit
1fbc25c394

+ 10 - 37
lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dart

@@ -7,13 +7,13 @@ import 'package:photos/ui/components/bottom_action_bar/action_bar_widget.dart';
 import "package:photos/ui/components/divider_widget.dart";
 
 class BottomActionBarWidget extends StatelessWidget {
-  final Widget expandedMenu;
+  final Widget fileSelectionActionsWidget;
   final SelectedFiles? selectedFiles;
   final VoidCallback? onCancel;
   final Color? backgroundColor;
 
   const BottomActionBarWidget({
-    required this.expandedMenu,
+    required this.fileSelectionActionsWidget,
     this.selectedFiles,
     this.onCancel,
     this.backgroundColor,
@@ -47,38 +47,7 @@ class BottomActionBarWidget extends StatelessWidget {
         mainAxisSize: MainAxisSize.min,
         children: [
           const SizedBox(height: 12),
-          SingleChildScrollView(
-            physics: const BouncingScrollPhysics(),
-            scrollDirection: Axis.horizontal,
-            child: Row(
-              crossAxisAlignment: CrossAxisAlignment.start,
-              children: const [
-                SizedBox(width: 8),
-                SelectionOptionButton(
-                  name: "Share link",
-                  icon: Icons.link_outlined,
-                ),
-                SelectionOptionButton(name: "Add to album", icon: Icons.add),
-                SelectionOptionButton(
-                  name: "Delete",
-                  icon: Icons.delete_outline,
-                ),
-                SelectionOptionButton(
-                  name: "Hide",
-                  icon: Icons.visibility_off_outlined,
-                ),
-                SelectionOptionButton(
-                  name: "Archive",
-                  icon: Icons.archive_outlined,
-                ),
-                SelectionOptionButton(
-                  name: "Favorite",
-                  icon: Icons.favorite_border_outlined,
-                ),
-                SizedBox(width: 8),
-              ],
-            ),
-          ),
+          fileSelectionActionsWidget,
           const SizedBox(height: 20),
           const DividerWidget(dividerType: DividerType.bottomBar),
           ActionBarWidget(
@@ -93,11 +62,14 @@ class BottomActionBarWidget extends StatelessWidget {
 }
 
 class SelectionOptionButton extends StatefulWidget {
-  final String name;
+  final String labelText;
   final IconData icon;
+  final VoidCallback? onTap;
+
   const SelectionOptionButton({
-    required this.name,
+    required this.labelText,
     required this.icon,
+    required this.onTap,
     super.key,
   });
 
@@ -111,6 +83,7 @@ class _SelectionOptionButtonState extends State<SelectionOptionButton> {
   Widget build(BuildContext context) {
     final colorScheme = getEnteColorScheme(context);
     return GestureDetector(
+      onTap: widget.onTap,
       onTapDown: (details) {
         setState(() {
           backgroundColor = colorScheme.fillFaintPressed;
@@ -146,7 +119,7 @@ class _SelectionOptionButtonState extends State<SelectionOptionButton> {
                 ),
                 const SizedBox(height: 4),
                 Text(
-                  widget.name,
+                  widget.labelText,
                   textAlign: TextAlign.center,
                   style: getEnteTextTheme(context).miniMuted,
                 ),

+ 65 - 79
lib/ui/viewer/actions/file_selection_actions_widget.dart

@@ -13,13 +13,11 @@ import "package:photos/models/metadata/common_keys.dart";
 import 'package:photos/models/selected_files.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/ui/actions/collection/collection_file_actions.dart';
 import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
 import 'package:photos/ui/collections/collection_action_sheet.dart';
 import 'package:photos/ui/components/action_sheet_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/bottom_action_bar_widget.dart";
 import 'package:photos/ui/components/buttons/button_widget.dart';
 import 'package:photos/ui/components/models/button_type.dart';
 import 'package:photos/ui/sharing/manage_links_widget.dart';
@@ -29,13 +27,13 @@ import 'package:photos/utils/magic_util.dart';
 import 'package:photos/utils/navigation_util.dart';
 import 'package:photos/utils/toast_util.dart';
 
-class FileSelectionActionWidget extends StatefulWidget {
+class FileSelectionActionsWidget extends StatefulWidget {
   final GalleryType type;
   final Collection? collection;
   final DeviceCollection? deviceCollection;
   final SelectedFiles selectedFiles;
 
-  const FileSelectionActionWidget(
+  const FileSelectionActionsWidget(
     this.type,
     this.selectedFiles, {
     Key? key,
@@ -44,11 +42,12 @@ class FileSelectionActionWidget extends StatefulWidget {
   }) : super(key: key);
 
   @override
-  State<FileSelectionActionWidget> createState() =>
-      _FileSelectionActionWidgetState();
+  State<FileSelectionActionsWidget> createState() =>
+      _FileSelectionActionsWidgetState();
 }
 
-class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
+class _FileSelectionActionsWidgetState
+    extends State<FileSelectionActionsWidget> {
   late int currentUserID;
   late FilesSplit split;
   late CollectionActions collectionActions;
@@ -110,27 +109,22 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
     final bool anyUploadedFiles = split.ownedByCurrentUser.isNotEmpty;
     final bool showRemoveOption = widget.type.showRemoveFromAlbum();
     debugPrint('$runtimeType building  $mounted');
-    final colorScheme = getEnteColorScheme(context);
-    final List<List<BlurMenuItemWidget>> items = [];
-    final List<BlurMenuItemWidget> firstList = [];
-    final List<BlurMenuItemWidget> secondList = [];
+    final List<SelectionOptionButton> items = [];
 
     if (widget.type.showCreateLink()) {
       if (_cachedCollectionForSharedLink != null && anyUploadedFiles) {
-        firstList.add(
-          BlurMenuItemWidget(
-            leadingIcon: Icons.copy_outlined,
+        items.add(
+          SelectionOptionButton(
+            icon: Icons.copy_outlined,
             labelText: S.of(context).copyLink,
-            menuItemColor: colorScheme.fillFaint,
             onTap: anyUploadedFiles ? _copyLink : null,
           ),
         );
       } else {
-        firstList.add(
-          BlurMenuItemWidget(
-            leadingIcon: Icons.link_outlined,
+        items.add(
+          SelectionOptionButton(
+            icon: Icons.link_outlined,
             labelText: S.of(context).shareLink + suffix,
-            menuItemColor: colorScheme.fillFaint,
             onTap: anyUploadedFiles ? _onCreatedSharedLinkClicked : null,
           ),
         );
@@ -149,11 +143,10 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
             CollageCreatorPage.collageItemsMin &&
         widget.selectedFiles.files.length <=
             CollageCreatorPage.collageItemsMax) {
-      firstList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.grid_view_outlined,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.grid_view_outlined,
           labelText: S.of(context).createCollage,
-          menuItemColor: colorScheme.fillFaint,
           onTap: _onCreateCollageClicked,
         ),
       );
@@ -162,139 +155,132 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
     final showUploadIcon = widget.type == GalleryType.localFolder &&
         split.ownedByCurrentUser.isEmpty;
     if (widget.type.showAddToAlbum()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon:
+      items.add(
+        SelectionOptionButton(
+          icon:
               showUploadIcon ? Icons.cloud_upload_outlined : Icons.add_outlined,
           labelText: showUploadIcon
               ? S.of(context).addToEnte
               : S.of(context).addToAlbum + suffixInPending,
-          menuItemColor: colorScheme.fillFaint,
           onTap: anyOwnedFiles ? _addToAlbum : null,
         ),
       );
     }
     if (widget.type.showMoveToAlbum()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.arrow_forward_outlined,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.arrow_forward_outlined,
           labelText: S.of(context).moveToAlbum + suffix,
-          menuItemColor: colorScheme.fillFaint,
           onTap: anyUploadedFiles ? _moveFiles : null,
         ),
       );
     }
 
     if (showRemoveOption) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.remove_outlined,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.remove_outlined,
           labelText: "${S.of(context).removeFromAlbum}$removeSuffix",
-          menuItemColor: colorScheme.fillFaint,
           onTap: removeCount > 0 ? _removeFilesFromAlbum : null,
         ),
       );
     }
 
     if (widget.type.showDeleteOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.delete_outline,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.delete_outline,
           labelText: S.of(context).delete + suffixInPending,
-          menuItemColor: colorScheme.fillFaint,
           onTap: anyOwnedFiles ? _onDeleteClick : null,
         ),
       );
     }
 
     if (widget.type.showHideOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.visibility_off_outlined,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.visibility_off_outlined,
           labelText: S.of(context).hide + suffix,
-          menuItemColor: colorScheme.fillFaint,
           onTap: anyUploadedFiles ? _onHideClick : null,
         ),
       );
     } else if (widget.type.showUnHideOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.visibility_off_outlined,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.visibility_off_outlined,
           labelText: S.of(context).unhide + suffix,
-          menuItemColor: colorScheme.fillFaint,
           onTap: _onUnhideClick,
         ),
       );
     }
     if (widget.type.showArchiveOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.archive_outlined,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.archive_outlined,
           labelText: S.of(context).archive + suffix,
-          menuItemColor: colorScheme.fillFaint,
           onTap: anyUploadedFiles ? _onArchiveClick : null,
         ),
       );
     } else if (widget.type.showUnArchiveOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.unarchive,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.unarchive,
           labelText: S.of(context).unarchive + suffix,
-          menuItemColor: colorScheme.fillFaint,
           onTap: _onUnArchiveClick,
         ),
       );
     }
 
     if (widget.type.showFavoriteOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.favorite_border_rounded,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.favorite_border_rounded,
           labelText: S.of(context).favorite + suffix,
-          menuItemColor: colorScheme.fillFaint,
           onTap: anyUploadedFiles ? _onFavoriteClick : null,
         ),
       );
     } else if (widget.type.showUnFavoriteOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.favorite,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.favorite,
           labelText: S.of(context).removeFromFavorite + suffix,
-          menuItemColor: colorScheme.fillFaint,
           onTap: _onUnFavoriteClick,
         ),
       );
     }
 
     if (widget.type.showRestoreOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.restore_outlined,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.restore_outlined,
           labelText: S.of(context).restore,
-          menuItemColor: colorScheme.fillFaint,
           onTap: _restore,
         ),
       );
     }
 
     if (widget.type.showPermanentlyDeleteOption()) {
-      secondList.add(
-        BlurMenuItemWidget(
-          leadingIcon: Icons.delete_forever_outlined,
+      items.add(
+        SelectionOptionButton(
+          icon: Icons.delete_forever_outlined,
           labelText: S.of(context).permanentlyDelete,
-          menuItemColor: colorScheme.fillFaint,
           onTap: _permanentlyDelete,
         ),
       );
     }
 
-    if (firstList.isNotEmpty || secondList.isNotEmpty) {
-      if (firstList.isNotEmpty) {
-        items.add(firstList);
-      }
-      items.add(secondList);
-      return ExpandedMenuWidget(
-        items: items,
+    if (items.isNotEmpty) {
+      return SingleChildScrollView(
+        physics: const BouncingScrollPhysics(),
+        scrollDirection: Axis.horizontal,
+        child: Row(
+          crossAxisAlignment: CrossAxisAlignment.start,
+          children: [
+            const SizedBox(width: 8),
+            ...items,
+            const SizedBox(width: 8),
+          ],
+        ),
       );
     } else {
       // TODO: Return "Select All" here

+ 1 - 1
lib/ui/viewer/actions/file_selection_overlay_bar.dart

@@ -60,7 +60,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
           duration: const Duration(milliseconds: 400),
           firstChild: BottomActionBarWidget(
             selectedFiles: widget.selectedFiles,
-            expandedMenu: FileSelectionActionWidget(
+            fileSelectionActionsWidget: FileSelectionActionsWidget(
               widget.galleryType,
               widget.selectedFiles,
               collection: widget.collection,