Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add selection functionality and action buttons to collection action sheet

Aman Raj Singh Mouryaafcc7b1e46f6
diff --git a/mobile/lib/ui/collections/collection_action_sheet.dart b/mobile/lib/ui/collections/collection_action_sheet.dart
index 370982c8a6..854f72f50a 100644
--- a/mobile/lib/ui/collections/collection_action_sheet.dart
+++ b/mobile/lib/ui/collections/collection_action_sheet.dart
@@ -11,6 +11,8 @@ import 'package:photos/models/selected_files.dart';
import 'package:photos/services/collections_service.dart';
import 'package:photos/theme/colors.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/album/vertical_list.dart';
import 'package:photos/ui/common/loading_widget.dart';
import 'package:photos/ui/components/bottom_of_title_bar_widget.dart';
@@ -18,6 +20,8 @@ import 'package:photos/ui/components/buttons/button_widget.dart';
import 'package:photos/ui/components/models/button_type.dart';
import "package:photos/ui/components/text_input_widget.dart";
import 'package:photos/ui/components/title_bar_title_widget.dart';
+import "package:photos/ui/notification/toast.dart";
+import "package:photos/utils/separators_util.dart";
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
enum CollectionActionType {
@@ -55,8 +59,10 @@ String _actionName(
break;
case CollectionActionType.collectPhotos:
text = S.of(context).share;
+ break;
case CollectionActionType.addToHiddenAlbum:
text = S.of(context).addToHiddenAlbum;
+ break;
case CollectionActionType.moveToHiddenCollection:
text = S.of(context).moveToHiddenAlbum;
break;
@@ -113,8 +119,11 @@ class CollectionActionSheet extends StatefulWidget {
class _CollectionActionSheetState extends State<CollectionActionSheet> {
late final bool _showOnlyHiddenCollections;
+ late final bool _enableSelection;
static const int cancelButtonSize = 80;
+ static const int okButtonSize = 60;
String _searchQuery = "";
+ List<Collection> _selectedCollections = [];
@override
void initState() {
@@ -122,6 +131,9 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
_showOnlyHiddenCollections =
widget.actionType == CollectionActionType.moveToHiddenCollection ||
widget.actionType == CollectionActionType.addToHiddenAlbum;
+ _enableSelection = (widget.actionType == CollectionActionType.addFiles ||
+ widget.actionType == CollectionActionType.addToHiddenAlbum) &&
+ (widget.sharedFiles == null || widget.sharedFiles!.isEmpty);
}
@override
@@ -131,9 +143,13 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
: widget.selectedFiles?.files.length ?? 0;
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
final isKeyboardUp = bottomInset > 100;
+ final double bottomPadding = max(
+ 0,
+ bottomInset - cancelButtonSize - (_enableSelection ? okButtonSize : 0),
+ );
return Padding(
padding: EdgeInsets.only(
- bottom: isKeyboardUp ? bottomInset - cancelButtonSize : 0,
+ bottom: isKeyboardUp ? bottomPadding : 0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
@@ -196,11 +212,10 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
),
),
),
- child: ButtonWidget(
- buttonType: ButtonType.secondary,
- buttonAction: ButtonAction.cancel,
- isInAlert: true,
- labelText: S.of(context).cancel,
+ child: Column(
+ children: [
+ ..._actionButtons(),
+ ],
),
),
),
@@ -213,6 +228,61 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
);
}
+ List<Widget> _actionButtons() {
+ final List<Widget> widgets = [];
+ if (_enableSelection) {
+ widgets.add(
+ AnimatedSwitcher(
+ duration: const Duration(milliseconds: 300),
+ switchInCurve: Curves.easeOutBack,
+ switchOutCurve: Curves.easeIn,
+ child: _selectedCollections.isNotEmpty
+ ? ButtonWidget(
+ key: const ValueKey('add_button'),
+ buttonType: ButtonType.primary,
+ isInAlert: true,
+ labelText: S.of(context).add,
+ shouldSurfaceExecutionStates: false,
+ onTap: () async {
+ final CollectionActions collectionActions =
+ CollectionActions(CollectionsService.instance);
+ final result =
+ await collectionActions.addToMultipleCollections(
+ context,
+ _selectedCollections,
+ true,
+ selectedFiles: widget.selectedFiles?.files.toList(),
+ );
+ if (result) {
+ showShortToast(
+ context,
+ "Added successfully to " +
+ _selectedCollections.length.toString() +
+ " albums",
+ );
+ widget.selectedFiles?.clearAll();
+ }
+ },
+ )
+ : const SizedBox.shrink(),
+ ),
+ );
+ }
+ widgets.add(
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ buttonAction: ButtonAction.cancel,
+ isInAlert: true,
+ labelText: S.of(context).cancel,
+ ),
+ );
+ final widgetsWithSpaceBetween = addSeparators(
+ widgets,
+ const SizedBox(height: 8),
+ );
+ return widgetsWithSpaceBetween;
+ }
+
Flexible _getCollectionItems() {
return Flexible(
child: Padding(
@@ -249,6 +319,10 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
widget.sharedFiles,
_searchQuery,
shouldShowCreateAlbum,
+ enableSelection: _enableSelection,
+ onSelectionChanged: (c) {
+ _updateSelectedCollections(c);
+ },
),
),
);
@@ -261,6 +335,12 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
);
}
+ void _updateSelectedCollections(List<Collection> collections) {
+ setState(() {
+ _selectedCollections = collections;
+ });
+ }
+
Future<List<Collection>> _getCollections() async {
if (_showOnlyHiddenCollections) {
final hiddenCollections = CollectionsService.instance