π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[locker] Add collection multiselect with ownership checks and animation fixes
AmanRajSinghMouryac08c35506878
diff --git a/mobile/apps/locker/lib/l10n/app_en.arb b/mobile/apps/locker/lib/l10n/app_en.arbindex 77df05fd29..15f3c88736 100644--- a/mobile/apps/locker/lib/l10n/app_en.arb+++ b/mobile/apps/locker/lib/l10n/app_en.arb@@ -95,6 +95,8 @@}},"collectionCannotBeDeleted": "This collection cannot be deleted",+ "collectionCannotBeEdited": "This collection cannot be edited",+ "collectionCannotBeShared": "This collection cannot be shared","deleteCollection": "Delete collection","deleteCollectionConfirmation": "Are you sure you want to delete \"{collectionName}\"?","@deleteCollectionConfirmation": {diff --git a/mobile/apps/locker/lib/l10n/app_localizations.dart b/mobile/apps/locker/lib/l10n/app_localizations.dartindex 6f740efdc6..27d3b27c34 100644--- a/mobile/apps/locker/lib/l10n/app_localizations.dart+++ b/mobile/apps/locker/lib/l10n/app_localizations.dart@@ -292,6 +292,18 @@ abstract class AppLocalizations {/// **'This collection cannot be deleted'**String get collectionCannotBeDeleted;+ /// No description provided for @collectionCannotBeEdited.+ ///+ /// In en, this message translates to:+ /// **'This collection cannot be edited'**+ String get collectionCannotBeEdited;++ /// No description provided for @collectionCannotBeShared.+ ///+ /// In en, this message translates to:+ /// **'This collection cannot be shared'**+ String get collectionCannotBeShared;+/// No description provided for @deleteCollection.////// In en, this message translates to:diff --git a/mobile/apps/locker/lib/l10n/app_localizations_en.dart b/mobile/apps/locker/lib/l10n/app_localizations_en.dartindex eb79ba17b1..f1588928b3 100644--- a/mobile/apps/locker/lib/l10n/app_localizations_en.dart+++ b/mobile/apps/locker/lib/l10n/app_localizations_en.dart@@ -123,6 +123,12 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get collectionCannotBeDeleted => 'This collection cannot be deleted';+ @override+ String get collectionCannotBeEdited => 'This collection cannot be edited';++ @override+ String get collectionCannotBeShared => 'This collection cannot be shared';+@overrideString get deleteCollection => 'Delete collection';diff --git a/mobile/apps/locker/lib/services/collections/models/collection.dart b/mobile/apps/locker/lib/services/collections/models/collection.dartindex 3146a71da5..92515fac7e 100644--- a/mobile/apps/locker/lib/services/collections/models/collection.dart+++ b/mobile/apps/locker/lib/services/collections/models/collection.dart@@ -297,6 +297,12 @@ String typeToString(CollectionType type) {extension CollectionTypeExtn on CollectionType {bool get canDelete =>this != CollectionType.favorites && this != CollectionType.uncategorized;++ bool get canEdit =>+ this != CollectionType.favorites && this != CollectionType.uncategorized;++ bool get canShare =>+ this != CollectionType.favorites && this != CollectionType.uncategorized;}enum CollectionParticipantRole {diff --git a/mobile/apps/locker/lib/ui/components/collection_list_widget.dart b/mobile/apps/locker/lib/ui/components/collection_list_widget.dartindex 3c15573ac1..6c5cc5f79c 100644--- a/mobile/apps/locker/lib/ui/components/collection_list_widget.dart+++ b/mobile/apps/locker/lib/ui/components/collection_list_widget.dart@@ -166,9 +166,17 @@ class CollectionListWidget extends StatelessWidget {mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [collectionRowWidget,- isFavourite- ? const SizedBox.shrink()- : AnimatedSwitcher(+ if (isFavourite)+ const SizedBox.shrink()+ else+ Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (showSharingIndicator && hasSharees)+ _buildShareesAvatars(+ collection.sharees.whereType<User>().toList(),+ ),+ AnimatedSwitcher(duration: const Duration(milliseconds: 200),switchInCurve: Curves.easeOut,switchOutCurve: Curves.easeIn,@@ -179,45 +187,21 @@ class CollectionListWidget extends StatelessWidget {iconButtonType: IconButtonType.secondary,iconColor: colorScheme.primary700,)- : showSharingIndicator- ? Row(- key: const ValueKey("shared"),- mainAxisSize: MainAxisSize.min,- children: [- if (hasSharees)- _buildShareesAvatars(- collection.sharees- .whereType<User>()- .toList(),- ),- CollectionPopupMenuWidget(- collection: collection,- overflowActions: overflowActions,- child: Padding(- padding: const EdgeInsets.all(12.0),- child: HugeIcon(- icon: HugeIcons- .strokeRoundedMoreVertical,- color: colorScheme.textBase,- ),- ),- ),- ],- )- : CollectionPopupMenuWidget(- key: const ValueKey("menu"),- collection: collection,- overflowActions: overflowActions,- child: Padding(- padding: const EdgeInsets.all(12.0),- child: HugeIcon(- icon:- HugeIcons.strokeRoundedMoreVertical,- color: colorScheme.textBase,- ),- ),+ : CollectionPopupMenuWidget(+ key: const ValueKey("menu"),+ collection: collection,+ overflowActions: overflowActions,+ child: Padding(+ padding: const EdgeInsets.all(12.0),+ child: HugeIcon(+ icon: HugeIcons.strokeRoundedMoreVertical,+ color: colorScheme.textBase,),+ ),+ ),),+ ],+ ),],),);diff --git a/mobile/apps/locker/lib/ui/components/item_list_view.dart b/mobile/apps/locker/lib/ui/components/item_list_view.dartindex 3d75e6e1dc..5539024cfd 100644--- a/mobile/apps/locker/lib/ui/components/item_list_view.dart+++ b/mobile/apps/locker/lib/ui/components/item_list_view.dart@@ -102,15 +102,13 @@ class _ItemListViewState extends State<ItemListView> {}void _toggleCollectionSelection(Collection collection) {- // TODO(aman): Re-enable collection multi-select when bulk actions return.- return;- // HapticFeedback.lightImpact();- // widget.selectedCollections!.toggleSelection(collection);+ HapticFeedback.lightImpact();+ widget.selectedCollections!.toggleSelection(collection);}void _toggleFileSelection(EnteFile file) {if (!widget.selectionEnabled) {- showToast(context, "Multi-select for shared albums coming soon");+ showToast(context, "Multi-select for shared files coming soon");return;}HapticFeedback.lightImpact();@@ -127,10 +125,12 @@ class _ItemListViewState extends State<ItemListView> {return _buildDefaultEmptyState(context);}- final bottomPadding =- (widget.selectedFiles != null && widget.selectionEnabled)- ? ItemListView._selectionOverlayPadding- : 0.0;+ final hasFileSelection =+ widget.selectedFiles != null && widget.selectionEnabled;+ final hasCollectionSelection = widget.selectedCollections != null;+ final bottomPadding = (hasFileSelection || hasCollectionSelection)+ ? ItemListView._selectionOverlayPadding+ : 0.0;return _buildListView(bottomPadding: bottomPadding);}diff --git a/mobile/apps/locker/lib/ui/pages/all_collections_page.dart b/mobile/apps/locker/lib/ui/pages/all_collections_page.dartindex 22f222cc33..0cbd0d638e 100644--- a/mobile/apps/locker/lib/ui/pages/all_collections_page.dart+++ b/mobile/apps/locker/lib/ui/pages/all_collections_page.dart@@ -14,17 +14,16 @@ import 'package:locker/services/collections/models/collection.dart';import "package:locker/ui/components/empty_state_widget.dart";import 'package:locker/ui/components/item_list_view.dart';import 'package:locker/ui/pages/collection_page.dart';+import "package:locker/ui/viewer/actions/collection_selection_overlay_bar.dart";import 'package:locker/utils/collection_sort_util.dart';import 'package:logging/logging.dart';class AllCollectionsPage extends StatefulWidget {final UISectionType viewType;- final SelectedCollections? selectedCollections;const AllCollectionsPage({super.key,this.viewType = UISectionType.homeCollections,- this.selectedCollections,});@override@@ -41,6 +40,9 @@ class _AllCollectionsPageState extends State<AllCollectionsPage> {final _logger = Logger("AllCollectionsPage");StreamSubscription<CollectionsUpdatedEvent>? _collectionsUpdatedSub;+ final _selectedCollections = SelectedCollections();+ final _scrollController = ScrollController();+@overridevoid initState() {super.initState();@@ -58,6 +60,7 @@ class _AllCollectionsPageState extends State<AllCollectionsPage> {@overridevoid dispose() {_collectionsUpdatedSub?.cancel();+ _scrollController.dispose();super.dispose();}@@ -153,12 +156,10 @@ class _AllCollectionsPageState extends State<AllCollectionsPage> {body: Stack(children: [_buildBody(context),- // TODO(aman): Uncomment when multi-select actions are restored.- // CollectionSelectionOverlayBar(- // collection: _sortedCollections,- // selectedCollections: widget.selectedCollections!,- // viewType: widget.viewType,- // ),+ CollectionSelectionOverlayBar(+ collections: _sortedCollections,+ selectedCollections: _selectedCollections,+ ),],),);@@ -245,8 +246,8 @@ class _AllCollectionsPageState extends State<AllCollectionsPage> {Expanded(child: ItemListView(collections: _sortedCollections,- // TODO(aman): pass selectedCollections when multi-select returns.- selectedCollections: null,+ selectedCollections: _selectedCollections,+ scrollController: _scrollController,physics: const BouncingScrollPhysics(),),),diff --git a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dartindex 83d44881eb..f3dfc261b6 100644--- a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart+++ b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart@@ -1,14 +1,11 @@-import "package:ente_events/event_bus.dart";import "package:ente_ui/theme/ente_theme.dart";import "package:ente_ui/utils/dialog_util.dart";+import "package:ente_ui/utils/toast_util.dart";import "package:flutter/material.dart";import "package:hugeicons/hugeicons.dart";-import "package:locker/events/collections_updated_event.dart";import "package:locker/l10n/l10n.dart";import "package:locker/models/selected_collections.dart";-import "package:locker/models/ui_section_type.dart";import "package:locker/services/collections/models/collection.dart";-import "package:locker/services/collections/models/collection_view_type.dart";import "package:locker/services/configuration.dart";import "package:locker/ui/components/selection_action_button_widget.dart";import "package:locker/ui/sharing/share_collection_bottom_sheet.dart";@@ -17,12 +14,11 @@ import "package:logging/logging.dart";class CollectionSelectionOverlayBar extends StatefulWidget {final SelectedCollections selectedCollections;- final List<Collection> collection;- final UISectionType viewType;+ final List<Collection> collections;+const CollectionSelectionOverlayBar({required this.selectedCollections,- required this.collection,- this.viewType = UISectionType.homeCollections,+ required this.collections,super.key,});@@ -35,6 +31,22 @@ class _CollectionSelectionOverlayBarStateextends State<CollectionSelectionOverlayBar> {static final _logger = Logger('CollectionSelectionOverlayBar');+ List<Collection> _getOwnedCollections(List<Collection> collections) {+ final currentUserID = Configuration.instance.getUserID()!;+ final ownedCollections =+ collections.where((c) => c.isOwner(currentUserID)).toList();++ final sharedCount = collections.length - ownedCollections.length;+ if (sharedCount > 0 && mounted) {+ showToast(+ context,+ "Skipped $sharedCount shared collection${sharedCount > 1 ? 's' : ''} - you can only leave shared collections",+ );+ }++ return ownedCollections;+ }+@overridevoid initState() {super.initState();@@ -48,9 +60,8 @@ class _CollectionSelectionOverlayBarState}void _onSelectionChanged() {- if (mounted) {- setState(() {});- }+ if (!mounted) return;+ setState(() {});}@override@@ -86,7 +97,7 @@ class _CollectionSelectionOverlayBarState),child: Padding(padding:- EdgeInsets.fromLTRB(16, 16, 16, 28 + bottomPadding),+ EdgeInsets.fromLTRB(16, 16, 16, 16 + bottomPadding),child: Column(mainAxisSize: MainAxisSize.min,children: [@@ -97,7 +108,7 @@ class _CollectionSelectionOverlayBarStatebuilder: (context, child) {final isAllSelected =widget.selectedCollections.count ==- widget.collection.length;+ widget.collections.length;final buttonText = isAllSelected? context.l10n.deselectAll: context.l10n.selectAll;@@ -111,7 +122,7 @@ class _CollectionSelectionOverlayBarStatewidget.selectedCollections.clearAll();} else {widget.selectedCollections.select(- widget.collection.toSet(),+ widget.collections.toSet(),);}},@@ -134,8 +145,7 @@ class _CollectionSelectionOverlayBarStateconst SizedBox(width: 6),Icon(iconData,- color: getEnteColorScheme(context)- .textBase,+ color: colorScheme.textBase,size: 20,),],@@ -177,8 +187,7 @@ class _CollectionSelectionOverlayBarStateconst SizedBox(width: 6),Icon(Icons.close,- color: getEnteColorScheme(context)- .textBase,+ color: colorScheme.textBase,size: 20,),],@@ -190,7 +199,7 @@ class _CollectionSelectionOverlayBarState],),const SizedBox(height: 20),- _buildActionButtons(),+ _buildPrimaryActionButtons(),],),),@@ -202,41 +211,52 @@ class _CollectionSelectionOverlayBarState);}- Widget _buildActionButtons() {- return ListenableBuilder(- listenable: widget.selectedCollections,- builder: (context, child) {- final selectedCollections = widget.selectedCollections.collections;- if (selectedCollections.isEmpty) {- return const SizedBox.shrink();- }+ Widget _buildPrimaryActionButtons() {+ final colorScheme = getEnteColorScheme(context);+ final selectedCollections = widget.selectedCollections.collections;+ if (selectedCollections.isEmpty) {+ return const SizedBox.shrink();+ }- final actions = _getActionsForSelection(selectedCollections);+ final isSingleSelection = selectedCollections.length == 1;+ final collection = isSingleSelection ? selectedCollections.first : null;- return AnimatedSwitcher(- duration: const Duration(milliseconds: 300),- switchInCurve: Curves.easeInOut,- switchOutCurve: Curves.easeInOut,- transitionBuilder: (Widget child, Animation<double> animation) {- return FadeTransition(- opacity: animation,- child: SizeTransition(- sizeFactor: animation,- child: child,- ),- );- },- child: actions.length > 1- ? Row(- key: const ValueKey('multi_action'),- children: _buildActionRow(actions),- )- : Row(- key: const ValueKey('single_action'),- children: [Expanded(child: actions.first)],- ),- );- },+ final primaryActions = <Widget>[+ if (isSingleSelection)+ SelectionActionButton(+ hugeIcon: const HugeIcon(+ icon: HugeIcons.strokeRoundedNavigation06,+ ),+ label: context.l10n.share,+ onTap: () => _shareCollection(collection!),+ ),+ if (isSingleSelection)+ SelectionActionButton(+ hugeIcon: const HugeIcon(+ icon: HugeIcons.strokeRoundedPencilEdit02,+ ),+ label: context.l10n.edit,+ onTap: () => _editCollection(collection!),+ ),+ SelectionActionButton(+ hugeIcon: HugeIcon(+ icon: HugeIcons.strokeRoundedDelete02,+ color: colorScheme.warning500,+ ),+ label: context.l10n.delete,+ onTap: () {+ if (isSingleSelection) {+ _deleteCollection(collection!);+ } else {+ _deleteMultipleCollections(selectedCollections);+ }+ },+ isDestructive: true,+ ),+ ];++ return Row(+ children: _buildActionRow(primaryActions),);}@@ -251,159 +271,76 @@ class _CollectionSelectionOverlayBarStatereturn children;}- List<Widget> _getActionsForSelection(- Set<Collection> selectedCollections,- ) {- final colorScheme = getEnteColorScheme(context);- final isSingleSelection = selectedCollections.length == 1;- final collection = isSingleSelection ? selectedCollections.first : null;- final actions = <Widget>[];- final viewType = widget.viewType;-- if (viewType == UISectionType.homeCollections ||- viewType == UISectionType.outgoingCollections) {- if (isSingleSelection) {- actions.addAll([- SelectionActionButton(- hugeIcon: const HugeIcon(- icon: HugeIcons.strokeRoundedNavigation06,- ),- label: context.l10n.share,- onTap: () => _shareCollection(collection!),- ),- SelectionActionButton(- hugeIcon: const HugeIcon(- icon: HugeIcons.strokeRoundedPencilEdit02,- ),- label: context.l10n.edit,- onTap: () {- _editCollection(collection!);- },- ),- SelectionActionButton(- hugeIcon: HugeIcon(- icon: HugeIcons.strokeRoundedDelete02,- color: colorScheme.warning500,- ),- label: context.l10n.delete,- onTap: () {- _deleteCollection(collection!);- },- isDestructive: true,- ),- ]);- } else {- actions.addAll([- SelectionActionButton(- hugeIcon: HugeIcon(- icon: HugeIcons.strokeRoundedDelete02,- color: colorScheme.warning500,- ),- label: context.l10n.delete,- onTap: () {- _deleteMultipleCollections(- widget.selectedCollections.collections,- );- },- isDestructive: true,- ),- ]);- }- } else {- actions.add(- SelectionActionButton(- hugeIcon: const HugeIcon(- icon: HugeIcons.strokeRoundedNavigation06,- ),- label: context.l10n.share,- onTap: _leaveCollection,- ),- );+ Future<void> _editCollection(Collection collection) async {+ final ownedCollections = _getOwnedCollections([collection]);+ if (ownedCollections.isEmpty) {+ widget.selectedCollections.clearAll();+ return;}- return actions;- }-- Future<void> _editCollection(Collection collection) async {try {- await CollectionActions.editCollection(- context,- collection,- );- widget.selectedCollections.clearAll();+ await CollectionActions.editCollection(context, collection);} catch (e, s) {_logger.severe(e, s);await showGenericErrorDialog(context: context, error: e);}-widget.selectedCollections.clearAll();}Future<void> _deleteCollection(Collection collection) async {+ final ownedCollections = _getOwnedCollections([collection]);+ if (ownedCollections.isEmpty) {+ widget.selectedCollections.clearAll();+ return;+ }+try {await CollectionActions.deleteCollection(context, collection);- widget.selectedCollections.clearAll();} catch (e, s) {_logger.severe(e, s);await showGenericErrorDialog(context: context, error: e);}-widget.selectedCollections.clearAll();}- Future<void> _deleteMultipleCollections(- Set<Collection> collections,- ) async {+ Future<void> _deleteMultipleCollections(Set<Collection> collections) async {+ final ownedCollections = _getOwnedCollections(collections.toList());+ if (ownedCollections.isEmpty) {+ widget.selectedCollections.clearAll();+ return;+ }+try {await CollectionActions.deleteMultipleCollections(context,- collections.toList(),+ ownedCollections,);- widget.selectedCollections.clearAll();} catch (e, s) {_logger.severe(e, s);await showGenericErrorDialog(context: context, error: e);}-widget.selectedCollections.clearAll();}Future<void> _shareCollection(Collection collection) async {- final collectionViewType = getCollectionViewType(- collection,- Configuration.instance.getUserID()!,- );- try {- if ((collectionViewType != CollectionViewType.ownedCollection &&- collectionViewType != CollectionViewType.sharedCollectionViewer &&- collectionViewType !=- CollectionViewType.sharedCollectionCollaborator &&- collectionViewType != CollectionViewType.hiddenOwnedCollection &&- collectionViewType != CollectionViewType.favorite)) {- throw Exception(- "Cannot share collection of type $collectionViewType",- );- }+ final ownedCollections = _getOwnedCollections([collection]);+ if (ownedCollections.isEmpty) {+ widget.selectedCollections.clearAll();+ return;+ }+ if (!collection.type.canShare) {+ showToast(context, context.l10n.collectionCannotBeShared);+ widget.selectedCollections.clearAll();+ return;+ }++ try {await showShareCollectionSheet(context, collection: collection);} catch (e, s) {_logger.severe(e, s);await showGenericErrorDialog(context: context, error: e);}-- widget.selectedCollections.clearAll();- }-- Future<void> _leaveCollection() async {- await CollectionActions.leaveMultipleCollection(- context,- widget.selectedCollections.collections.toList(),- onSuccess: () {- Bus.instance.fire(- CollectionsUpdatedEvent("leave_collection"),- );- },- );widget.selectedCollections.clearAll();}}diff --git a/mobile/apps/locker/lib/utils/collection_actions.dart b/mobile/apps/locker/lib/utils/collection_actions.dartindex 7ee898c59e..a67bba9614 100644--- a/mobile/apps/locker/lib/utils/collection_actions.dart+++ b/mobile/apps/locker/lib/utils/collection_actions.dart@@ -77,6 +77,11 @@ class CollectionActions {Collection collection, {VoidCallback? onSuccess,}) async {+ if (!collection.type.canEdit) {+ showToast(context, context.l10n.collectionCannotBeEdited);+ return;+ }+await showInputDialogSheet(context,title: context.l10n.renameCollection,