浏览代码

FileSelection: Show various actions based on gallery type

Neeraj Gupta 2 年之前
父节点
当前提交
8ec8944fbd

+ 94 - 0
lib/models/gallery_type.dart

@@ -26,4 +26,98 @@ extension GalleyTypeExtension on GalleryType {
         return false;
         return false;
     }
     }
   }
   }
+
+  bool showMoveToAlbum() {
+    switch (this) {
+      case GalleryType.ownedCollection:
+        return true;
+
+      case GalleryType.hidden:
+      case GalleryType.searchResults:
+      case GalleryType.archive:
+      case GalleryType.localFolder:
+      case GalleryType.homepage:
+      case GalleryType.trash:
+      case GalleryType.sharedCollection:
+        return false;
+    }
+  }
+
+  bool showDeleteOption() {
+    switch (this) {
+      case GalleryType.ownedCollection:
+      case GalleryType.searchResults:
+      case GalleryType.homepage:
+        return true;
+      case GalleryType.hidden:
+      case GalleryType.archive:
+      case GalleryType.localFolder:
+      case GalleryType.trash:
+      case GalleryType.sharedCollection:
+        return false;
+    }
+  }
+
+  bool showRemoveFromAlbum() {
+    switch (this) {
+      case GalleryType.ownedCollection:
+      case GalleryType.sharedCollection:
+        return true;
+      case GalleryType.hidden:
+      case GalleryType.searchResults:
+      case GalleryType.homepage:
+      case GalleryType.archive:
+      case GalleryType.localFolder:
+      case GalleryType.trash:
+        return false;
+    }
+  }
+
+  bool showArchiveOption() {
+    switch (this) {
+      case GalleryType.ownedCollection:
+      case GalleryType.homepage:
+        return true;
+
+      case GalleryType.hidden:
+      case GalleryType.searchResults:
+      case GalleryType.archive:
+      case GalleryType.localFolder:
+      case GalleryType.trash:
+      case GalleryType.sharedCollection:
+        return false;
+    }
+  }
+
+  bool showHideOption() {
+    switch (this) {
+      case GalleryType.ownedCollection:
+      case GalleryType.homepage:
+      case GalleryType.searchResults:
+        return true;
+
+      case GalleryType.hidden:
+      case GalleryType.archive:
+      case GalleryType.localFolder:
+      case GalleryType.trash:
+      case GalleryType.sharedCollection:
+        return false;
+    }
+  }
+
+  bool showFavoriteOption() {
+    switch (this) {
+      case GalleryType.ownedCollection:
+      case GalleryType.homepage:
+      case GalleryType.searchResults:
+        return true;
+
+      case GalleryType.hidden:
+      case GalleryType.archive:
+      case GalleryType.localFolder:
+      case GalleryType.trash:
+      case GalleryType.sharedCollection:
+        return false;
+    }
+  }
 }
 }

+ 4 - 0
lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dart

@@ -3,6 +3,7 @@ import 'dart:ui';
 import 'package:expandable/expandable.dart';
 import 'package:expandable/expandable.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:photos/core/constants.dart';
 import 'package:photos/core/constants.dart';
+import 'package:photos/models/gallery_type.dart';
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/theme/effects.dart';
 import 'package:photos/theme/effects.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/theme/ente_theme.dart';
@@ -16,10 +17,12 @@ class BottomActionBarWidget extends StatelessWidget {
   final SelectedFiles? selectedFiles;
   final SelectedFiles? selectedFiles;
   final VoidCallback? onCancel;
   final VoidCallback? onCancel;
   final bool hasSmallerBottomPadding;
   final bool hasSmallerBottomPadding;
+  final GalleryType type;
 
 
   BottomActionBarWidget({
   BottomActionBarWidget({
     required this.expandedMenu,
     required this.expandedMenu,
     required this.hasSmallerBottomPadding,
     required this.hasSmallerBottomPadding,
+    required this.type,
     this.selectedFiles,
     this.selectedFiles,
     this.text,
     this.text,
     this.iconButtons,
     this.iconButtons,
@@ -62,6 +65,7 @@ class BottomActionBarWidget extends StatelessWidget {
                     ),
                     ),
                     child: ActionBarWidget(
                     child: ActionBarWidget(
                       selectedFiles: selectedFiles,
                       selectedFiles: selectedFiles,
+                      galleryType: type,
                       text: text,
                       text: text,
                       iconButtons: _iconButtons(context),
                       iconButtons: _iconButtons(context),
                     ),
                     ),

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

@@ -0,0 +1,109 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'package:photos/models/collection.dart';
+import 'package:photos/models/device_collection.dart';
+import 'package:photos/models/gallery_type.dart';
+import 'package:photos/theme/ente_theme.dart';
+import 'package:photos/ui/components/blur_menu_item_widget.dart';
+import 'package:photos/ui/components/bottom_action_bar/expanded_menu_widget.dart';
+
+class FileSelectionActionWidget extends StatefulWidget {
+  final GalleryType type;
+  final Collection? collection;
+  final DeviceCollection? deviceCollection;
+
+  const FileSelectionActionWidget(
+    this.type, {
+    Key? key,
+    this.collection,
+    this.deviceCollection,
+  }) : super(key: key);
+
+  @override
+  State<FileSelectionActionWidget> createState() =>
+      _FileSelectionActionWidgetState();
+}
+
+class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
+  @override
+  Widget build(BuildContext context) {
+    debugPrint('$runtimeType building  $mounted');
+    final colorScheme = getEnteColorScheme(context);
+    final List<List<BlurMenuItemWidget>> items = [];
+    final List<BlurMenuItemWidget> firstList = [];
+    if (widget.type.showAddToAlbum()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.add_outlined,
+          labelText: "Add to album",
+          menuItemColor: colorScheme.fillFaint,
+        ),
+      );
+    }
+    if (widget.type.showMoveToAlbum()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.arrow_forward_outlined,
+          labelText: "Move to album",
+          menuItemColor: colorScheme.fillFaint,
+        ),
+      );
+    }
+
+    if (widget.type.showRemoveFromAlbum()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.remove_outlined,
+          labelText: "Remove from album",
+          menuItemColor: colorScheme.fillFaint,
+        ),
+      );
+    }
+
+    if (widget.type.showDeleteOption()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.delete_outline,
+          labelText: "Delete",
+          menuItemColor: colorScheme.fillFaint,
+        ),
+      );
+    }
+
+    if (widget.type.showHideOption()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.visibility_off_outlined,
+          labelText: "Hide",
+          menuItemColor: colorScheme.fillFaint,
+        ),
+      );
+    }
+    if (widget.type.showArchiveOption()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.archive_outlined,
+          labelText: "Archive",
+          menuItemColor: colorScheme.fillFaint,
+        ),
+      );
+    }
+
+    if (widget.type.showFavoriteOption()) {
+      firstList.add(
+        BlurMenuItemWidget(
+          leadingIcon: Icons.favorite_border_rounded,
+          labelText: "Favorite",
+          menuItemColor: colorScheme.fillFaint,
+        ),
+      );
+    }
+
+    if (firstList.isNotEmpty) {
+      items.add(firstList);
+    }
+    return ExpandedMenuWidget(
+      items: items,
+    );
+  }
+}

+ 4 - 12
lib/ui/viewer/gallery/collection_page.dart

@@ -12,10 +12,9 @@ import 'package:photos/models/gallery_type.dart';
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/services/ignored_files_service.dart';
 import 'package:photos/services/ignored_files_service.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/theme/ente_theme.dart';
-import 'package:photos/ui/components/blur_menu_item_widget.dart';
 import 'package:photos/ui/components/bottom_action_bar/bottom_action_bar_widget.dart';
 import 'package:photos/ui/components/bottom_action_bar/bottom_action_bar_widget.dart';
-import 'package:photos/ui/components/bottom_action_bar/expanded_menu_widget.dart';
 import 'package:photos/ui/components/icon_button_widget.dart';
 import 'package:photos/ui/components/icon_button_widget.dart';
+import 'package:photos/ui/viewer/actions/file_selection_actions_widget.dart';
 import 'package:photos/ui/viewer/gallery/empty_state.dart';
 import 'package:photos/ui/viewer/gallery/empty_state.dart';
 import 'package:photos/ui/viewer/gallery/gallery.dart';
 import 'package:photos/ui/viewer/gallery/gallery.dart';
 import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';
 import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';
@@ -126,16 +125,9 @@ class _CollectionPageState extends State<CollectionPage> {
                   selectedFiles: _selectedFiles,
                   selectedFiles: _selectedFiles,
                   hasSmallerBottomPadding: true,
                   hasSmallerBottomPadding: true,
                   type: widget.appBarType,
                   type: widget.appBarType,
-                  expandedMenu: ExpandedMenuWidget(
-                    items: [
-                      [
-                        BlurMenuItemWidget(
-                          leadingIcon: Icons.add_outlined,
-                          labelText: "One",
-                          menuItemColor: colorScheme.fillFaint,
-                        ),
-                      ],
-                    ],
+                  expandedMenu: FileSelectionActionWidget(
+                    widget.appBarType,
+                    collection: widget.c.collection,
                   ),
                   ),
                   text: _selectedFiles.files.length.toString() + ' selected',
                   text: _selectedFiles.files.length.toString() + ' selected',
                   onCancel: () {
                   onCancel: () {