Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add single selection mode to collection selection widget in file dialogs

AmanRajSinghMouryafb405f2bb2c4
diff --git a/mobile/apps/locker/lib/ui/components/collection_selection_widget.dart b/mobile/apps/locker/lib/ui/components/collection_selection_widget.dart
index eff1735768..26d910d35a 100644
--- a/mobile/apps/locker/lib/ui/components/collection_selection_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/collection_selection_widget.dart
@@ -12,6 +12,7 @@ class CollectionSelectionWidget extends StatefulWidget {
final Function(int) onToggleCollection;
final Function(List<Collection>)? onCollectionsUpdated;
final Widget? titleWidget;
+ final bool singleSelectionMode;
const CollectionSelectionWidget({
super.key,
@@ -20,6 +21,7 @@ class CollectionSelectionWidget extends StatefulWidget {
required this.onToggleCollection,
this.onCollectionsUpdated,
this.titleWidget,
+ this.singleSelectionMode = false,
});
@override
@@ -52,6 +54,14 @@ class _CollectionSelectionWidgetState extends State<CollectionSelectionWidget> {
_availableCollections.add(newCollection);
});
+ // In single selection mode, clear other selections before selecting the new one
+ if (widget.singleSelectionMode) {
+ final collectionIdsCopy = Set<int>.from(widget.selectedCollectionIds);
+ for (final id in collectionIdsCopy) {
+ widget.onToggleCollection(id);
+ }
+ }
+
widget.onToggleCollection(newCollection.id);
widget.onCollectionsUpdated?.call(_availableCollections);
@@ -66,6 +76,19 @@ class _CollectionSelectionWidgetState extends State<CollectionSelectionWidget> {
}
}
+ void _onCollectionTap(int collectionId) {
+ if (widget.singleSelectionMode) {
+ // In single selection mode, clear other selections first
+ final collectionIdsCopy = Set<int>.from(widget.selectedCollectionIds);
+ for (final id in collectionIdsCopy) {
+ if (id != collectionId) {
+ widget.onToggleCollection(id);
+ }
+ }
+ }
+ widget.onToggleCollection(collectionId);
+ }
+
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
@@ -95,7 +118,7 @@ class _CollectionSelectionWidgetState extends State<CollectionSelectionWidget> {
collection: collection,
isSelected:
widget.selectedCollectionIds.contains(collection.id),
- onTap: () => widget.onToggleCollection(collection.id),
+ onTap: () => _onCollectionTap(collection.id),
colorScheme: colorScheme,
textTheme: textTheme,
),
diff --git a/mobile/apps/locker/lib/ui/components/file_edit_dialog.dart b/mobile/apps/locker/lib/ui/components/file_edit_dialog.dart
index 6c08894b85..f1fa72e1fb 100644
--- a/mobile/apps/locker/lib/ui/components/file_edit_dialog.dart
+++ b/mobile/apps/locker/lib/ui/components/file_edit_dialog.dart
@@ -205,6 +205,7 @@ class _FileEditDialogState extends State<FileEditDialog> {
selectedCollectionIds: _selectedCollectionIds,
onToggleCollection: _toggleCollection,
onCollectionsUpdated: _onCollectionsUpdated,
+ singleSelectionMode: true,
titleWidget: Text(
"Move to collection",
style: textTheme.largeBold,
diff --git a/mobile/apps/locker/lib/ui/components/file_restore_dialog.dart b/mobile/apps/locker/lib/ui/components/file_restore_dialog.dart
index 068c5cfe55..2d0240cdb4 100644
--- a/mobile/apps/locker/lib/ui/components/file_restore_dialog.dart
+++ b/mobile/apps/locker/lib/ui/components/file_restore_dialog.dart
@@ -152,6 +152,7 @@ class _FileRestoreDialogState extends State<FileRestoreDialog> {
selectedCollectionIds: _selectedCollectionIds,
onToggleCollection: _toggleCollection,
onCollectionsUpdated: _onCollectionsUpdated,
+ singleSelectionMode: true,
titleWidget: Text(
"Move to collection",
style: textTheme.largeBold,