Skip to content

armgit / ente

Public Imported from GitHub
0

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

[locker] Improve multiselect UX and refactor scroll logic

AmanRajSinghMourya59c7f9f4a362
diff --git a/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart b/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
index a133adecdc..8ffd297682 100644
--- a/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
@@ -178,7 +178,7 @@ class FilePopupMenuWidget extends StatelessWidget {
_editFile(context);
break;
case 'toggle_important':
- _toggleImportant(context);
+ _markImportant(context);
break;
case 'download':
_downloadFile(context);
@@ -214,8 +214,8 @@ class FilePopupMenuWidget extends StatelessWidget {
await FileActions.editFile(context, file);
}
- Future<void> _toggleImportant(BuildContext context) async {
- await FileActions.toggleImportant(
+ Future<void> _markImportant(BuildContext context) async {
+ await FileActions.markImportant(
context,
file,
);
diff --git a/mobile/apps/locker/lib/ui/components/item_list_view.dart b/mobile/apps/locker/lib/ui/components/item_list_view.dart
index d545a4288d..6ad70ddb4b 100644
--- a/mobile/apps/locker/lib/ui/components/item_list_view.dart
+++ b/mobile/apps/locker/lib/ui/components/item_list_view.dart
@@ -1,9 +1,10 @@
-import 'package:ente_ui/theme/ente_theme.dart';
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_ui/utils/toast_util.dart";
import "package:ente_utils/ente_utils.dart";
-import 'package:flutter/material.dart';
+import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:locker/extensions/collection_extension.dart";
-import 'package:locker/l10n/l10n.dart';
+import "package:locker/l10n/l10n.dart";
import 'package:locker/models/file_type.dart';
import 'package:locker/models/selected_collections.dart';
import 'package:locker/models/selected_files.dart';
@@ -37,6 +38,8 @@ class OverflowMenuAction {
}
class ItemListView extends StatefulWidget {
+ static const double _selectionOverlayPadding = 270.0;
+
final List<EnteFile> files;
final List<Collection> collections;
final Widget? emptyStateWidget;
@@ -45,6 +48,8 @@ class ItemListView extends StatefulWidget {
final SelectedCollections? selectedCollections;
final SelectedFiles? selectedFiles;
final ScrollPhysics? physics;
+ final ScrollController? scrollController;
+ final bool selectionEnabled;
const ItemListView({
super.key,
@@ -56,6 +61,8 @@ class ItemListView extends StatefulWidget {
this.selectedCollections,
this.selectedFiles,
this.physics = const NeverScrollableScrollPhysics(),
+ this.scrollController,
+ this.selectionEnabled = true,
});
@override
@@ -102,6 +109,10 @@ class _ItemListViewState extends State<ItemListView> {
}
void _toggleFileSelection(EnteFile file) {
+ if (!widget.selectionEnabled) {
+ showToast(context, "Multi-select for shared albums coming soon");
+ return;
+ }
HapticFeedback.lightImpact();
widget.selectedFiles!.toggleSelection(file);
}
@@ -116,10 +127,28 @@ class _ItemListViewState extends State<ItemListView> {
return _buildDefaultEmptyState(context);
}
+ if (widget.selectedFiles != null && widget.selectionEnabled) {
+ return ListenableBuilder(
+ listenable: widget.selectedFiles!,
+ builder: (context, _) {
+ final hasSelection = widget.selectedFiles!.hasSelections;
+ final bottomPadding =
+ hasSelection ? ItemListView._selectionOverlayPadding : 0.0;
+ return _buildListView(bottomPadding: bottomPadding);
+ },
+ );
+ }
+
+ return _buildListView();
+ }
+
+ Widget _buildListView({double bottomPadding = 0}) {
return ListView.separated(
+ controller: widget.scrollController,
separatorBuilder: (context, index) => const SizedBox(height: 8),
shrinkWrap: true,
physics: widget.physics,
+ padding: EdgeInsets.only(bottom: bottomPadding),
itemCount: _sortedItems.length,
itemBuilder: (context, index) => _buildItem(index),
);
diff --git a/mobile/apps/locker/lib/ui/components/selection_action_button_widget.dart b/mobile/apps/locker/lib/ui/components/selection_action_button_widget.dart
index aefc028828..d264c569b9 100644
--- a/mobile/apps/locker/lib/ui/components/selection_action_button_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/selection_action_button_widget.dart
@@ -33,10 +33,7 @@ class SelectionActionButton extends StatelessWidget {
color: colorScheme.backgroundElevated2,
borderRadius: BorderRadius.circular(24.0),
),
- padding: const EdgeInsets.symmetric(
- vertical: 18.0,
- horizontal: 12.0,
- ),
+ padding: const EdgeInsets.symmetric(vertical: 18.0),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
diff --git a/mobile/apps/locker/lib/ui/pages/collection_page.dart b/mobile/apps/locker/lib/ui/pages/collection_page.dart
index 664ab0b345..3ec7c521b6 100644
--- a/mobile/apps/locker/lib/ui/pages/collection_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/collection_page.dart
@@ -25,6 +25,7 @@ import 'package:locker/ui/mixins/search_mixin.dart';
import 'package:locker/ui/pages/home_page.dart';
import 'package:locker/ui/pages/uploader_page.dart';
import "package:locker/ui/sharing/share_collection_bottom_sheet.dart";
+import "package:locker/ui/viewer/actions/file_selection_overlay_bar.dart";
import 'package:locker/utils/collection_actions.dart';
import "package:logging/logging.dart";
@@ -59,6 +60,7 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
bool isFavorite = false;
final _selectedFiles = SelectedFiles();
+ final _scrollController = ScrollController();
@override
void onFileUploadComplete() {
@@ -103,12 +105,19 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
@override
void dispose() {
_collectionUpdateSubscription.cancel();
+ _scrollController.dispose();
super.dispose();
}
List<EnteFile> get _displayedFiles =>
isSearchActive ? _filteredFiles : _files;
+ bool get _isSelectionEnabled =>
+ collectionViewType != CollectionViewType.sharedCollectionViewer &&
+ collectionViewType != CollectionViewType.sharedCollectionCollaborator &&
+ collectionViewType != CollectionViewType.quickLink &&
+ collectionViewType != CollectionViewType.favorite;
+
@override
void initState() {
super.initState();
@@ -256,11 +265,12 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
alignment: Alignment.bottomCenter,
children: [
_buildBody(colorScheme, textTheme),
- // TODO(aman): Re-enable file multi-select overlay when bulk actions return.
- // FileSelectionOverlayBar(
- // files: _displayedFiles,
- // selectedFiles: _selectedFiles,
- // ),
+ FileSelectionOverlayBar(
+ files: _displayedFiles,
+ selectedFiles: _selectedFiles,
+ collectionViewType: collectionViewType,
+ scrollController: _scrollController,
+ ),
],
),
),
@@ -476,9 +486,10 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
: ItemListView(
key: ValueKey(_displayedFiles.length),
files: _displayedFiles,
- // TODO(aman): pass selectedFiles when multi-select returns.
- selectedFiles: null,
+ selectedFiles: _selectedFiles,
+ scrollController: _scrollController,
physics: const BouncingScrollPhysics(),
+ selectionEnabled: _isSelectionEnabled,
),
),
),
diff --git a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
index d4e85f853d..1a80f65129 100644
--- a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
+++ b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
@@ -10,6 +10,8 @@ import "package:locker/l10n/l10n.dart";
import "package:locker/models/selected_files.dart";
import "package:locker/services/collections/collections_service.dart";
import "package:locker/services/collections/models/collection.dart";
+import "package:locker/services/collections/models/collection_view_type.dart";
+import "package:locker/services/favorites_service.dart";
import "package:locker/services/files/sync/models/file.dart";
import "package:locker/ui/components/add_to_collection_dialog.dart";
import "package:locker/ui/components/delete_confirmation_sheet.dart";
@@ -22,9 +24,14 @@ import "package:logging/logging.dart";
class FileSelectionOverlayBar extends StatefulWidget {
final SelectedFiles selectedFiles;
final List<EnteFile> files;
+ final CollectionViewType? collectionViewType;
+ final ScrollController? scrollController;
+
const FileSelectionOverlayBar({
required this.selectedFiles,
required this.files,
+ this.collectionViewType,
+ this.scrollController,
super.key,
});
@@ -36,22 +43,73 @@ class FileSelectionOverlayBar extends StatefulWidget {
class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
static final Logger _logger = Logger("FileSelectionOverlayBar");
+ static const double _scrollThreshold = 10.0;
+
+ bool _isExpanded = true;
+ double _lastScrollPosition = 0;
+ int _previousSelectionCount = 0;
+
+ bool get _hasSelection => widget.selectedFiles.files.isNotEmpty;
+
@override
void initState() {
super.initState();
widget.selectedFiles.addListener(_onSelectionChanged);
+ widget.scrollController?.addListener(_onScroll);
}
@override
void dispose() {
widget.selectedFiles.removeListener(_onSelectionChanged);
+ widget.scrollController?.removeListener(_onScroll);
super.dispose();
}
void _onSelectionChanged() {
- if (mounted) {
+ if (!mounted) return;
+
+ final currentCount = widget.selectedFiles.files.length;
+ final isFirstSelection = _previousSelectionCount == 0 && currentCount > 0;
+
+ if (isFirstSelection) {
+ setState(() => _isExpanded = true);
+ } else {
setState(() {});
}
+
+ _previousSelectionCount = currentCount;
+ }
+
+ void _onScroll() {
+ final controller = widget.scrollController;
+ if (!mounted || controller == null || !_hasSelection) return;
+
+ final position = controller.position;
+ final current = position.pixels;
+
+ if (current < 0 || current > position.maxScrollExtent) return;
+
+ final delta = current - _lastScrollPosition;
+ if (delta.abs() < _scrollThreshold) return;
+
+ _lastScrollPosition = current;
+
+ final shouldCollapse = delta > 0 && _isExpanded;
+ final shouldExpand = delta < 0 && !_isExpanded;
+
+ if (shouldCollapse || shouldExpand) {
+ setState(() => _isExpanded = !_isExpanded);
+ }
+ }
+
+ bool get showFileSelectionOverlayBar {
+ final viewType = widget.collectionViewType;
+ if (viewType == null) return true;
+
+ return viewType != CollectionViewType.sharedCollectionViewer &&
+ viewType != CollectionViewType.sharedCollectionCollaborator &&
+ viewType != CollectionViewType.quickLink &&
+ viewType != CollectionViewType.favorite;
}
@override
@@ -76,7 +134,15 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
child: hasSelection
? GestureDetector(
behavior: HitTestBehavior.opaque,
- onVerticalDragUpdate: (_) {},
+ onVerticalDragUpdate: (details) {
+ if (details.primaryDelta != null) {
+ if (details.primaryDelta! < -5 && !_isExpanded) {
+ setState(() => _isExpanded = true);
+ } else if (details.primaryDelta! > 5 && _isExpanded) {
+ setState(() => _isExpanded = false);
+ }
+ }
+ },
child: Container(
decoration: BoxDecoration(
color: colorScheme.backdropBase,
@@ -91,7 +157,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
margin: EdgeInsets.zero,
child: Padding(
padding:
- EdgeInsets.fromLTRB(16, 16, 16, 28 + bottomPadding),
+ EdgeInsets.fromLTRB(16, 16, 16, 16 + bottomPadding),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
@@ -140,8 +206,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
const SizedBox(width: 6),
Icon(
iconData,
- color: getEnteColorScheme(context)
- .textBase,
+ color: colorScheme.textBase,
size: 20,
),
],
@@ -184,8 +249,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
const SizedBox(width: 6),
Icon(
Icons.close,
- color: getEnteColorScheme(context)
- .textBase,
+ color: colorScheme.textBase,
size: 20,
),
],
@@ -226,8 +290,19 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
mainAxisSize: MainAxisSize.min,
children: [
_buildPrimaryActionRow(selectedFiles),
- const SizedBox(height: 12),
- _buildSecondaryActionRow(selectedFiles),
+ AnimatedCrossFade(
+ duration: const Duration(milliseconds: 250),
+ crossFadeState: _isExpanded
+ ? CrossFadeState.showFirst
+ : CrossFadeState.showSecond,
+ firstChild: Column(
+ children: [
+ const SizedBox(height: 12),
+ _buildSecondaryActionRow(selectedFiles),
+ ],
+ ),
+ secondChild: const SizedBox.shrink(),
+ ),
],
),
);
@@ -248,7 +323,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
hugeIcon: const HugeIcon(
icon: HugeIcons.strokeRoundedDownload01,
),
- label: "Download",
+ label: context.l10n.save,
onTap: () => isSingleSelection
? _downloadFile(context, file!)
: _downloadMultipleFiles(context, files),
@@ -276,7 +351,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
label: context.l10n.delete,
onTap: () => isSingleSelection
? _deleteFile(context, file!)
- : _deleteMultipleFile(context, files),
+ : _deleteMultipleFiles(context, files),
isDestructive: true,
),
),
@@ -293,29 +368,8 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
color: colorScheme.backgroundElevated2,
borderRadius: BorderRadius.circular(24),
),
- child: AnimatedSwitcher(
- duration: const Duration(milliseconds: 300),
- switchInCurve: Curves.easeInOut,
- switchOutCurve: Curves.easeInOut,
- layoutBuilder: (Widget? currentChild, List<Widget> previousChildren) {
- return Stack(
- alignment: Alignment.center,
- children: <Widget>[
- ...previousChildren,
- if (currentChild != null) currentChild,
- ],
- );
- },
- transitionBuilder: (Widget child, Animation<double> animation) {
- return FadeTransition(
- opacity: animation,
- child: child,
- );
- },
- child: Row(
- key: ValueKey('secondary_${selectedFiles.length}'),
- children: _buildActionRow(actions),
- ),
+ child: Row(
+ children: _buildActionRow(actions),
),
);
}
@@ -349,6 +403,18 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
);
}
+ final isImportant =
+ isSingleSelection && FavoritesService.instance.isFavoriteCache(file!);
+ actions.add(
+ SelectionActionButton(
+ icon: isImportant ? Icons.star_rounded : Icons.star_border_rounded,
+ label: isImportant ? context.l10n.unimportant : context.l10n.important,
+ onTap: () => isSingleSelection
+ ? _markImportant(context, file!)
+ : _markMultipleImportant(context, files),
+ ),
+ );
+
actions.add(
SelectionActionButton(
hugeIcon: const HugeIcon(
@@ -362,6 +428,23 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
return actions;
}
+ Future<void> _downloadFile(BuildContext context, EnteFile file) async {
+ try {
+ final success = await FileUtil.downloadFile(context, file);
+ if (success) {
+ widget.selectedFiles.clearAll();
+ }
+ } catch (e, stackTrace) {
+ _logger.severe("Failed to download file: $e", e, stackTrace);
+ if (context.mounted) {
+ showToast(
+ context,
+ context.l10n.failedToDownloadOrDecrypt,
+ );
+ }
+ }
+ }
+
Future<void> _downloadMultipleFiles(
BuildContext context,
List<EnteFile> files,
@@ -395,6 +478,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
Future<void> _editFile(BuildContext context, EnteFile file) async {
await FileActions.editFile(context, file);
+ widget.selectedFiles.clearAll();
}
Future<void> _showAddToDialog(
@@ -523,7 +607,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
);
}
- Future<void> _deleteMultipleFile(
+ Future<void> _deleteMultipleFiles(
BuildContext context,
List<EnteFile> files,
) async {
@@ -587,20 +671,28 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
}
}
- Future<void> _downloadFile(BuildContext context, EnteFile file) async {
- try {
- final success = await FileUtil.downloadFile(context, file);
- if (success) {
+ Future<void> _markImportant(BuildContext context, EnteFile file) async {
+ await FileActions.markImportant(
+ context,
+ file,
+ onSuccess: () {
widget.selectedFiles.clearAll();
- }
- } catch (e, stackTrace) {
- _logger.severe("Failed to download file: $e", e, stackTrace);
- if (context.mounted) {
- showToast(
- context,
- context.l10n.failedToDownloadOrDecrypt,
- );
- }
- }
+ Bus.instance.fire(CollectionsUpdatedEvent('file_important_toggled'));
+ },
+ );
+ }
+
+ Future<void> _markMultipleImportant(
+ BuildContext context,
+ List<EnteFile> files,
+ ) async {
+ await FileActions.markMultipleImportant(
+ context,
+ files,
+ onSuccess: () {
+ widget.selectedFiles.clearAll();
+ Bus.instance.fire(CollectionsUpdatedEvent('files_marked_important'));
+ },
+ );
}
}
diff --git a/mobile/apps/locker/lib/utils/file_actions.dart b/mobile/apps/locker/lib/utils/file_actions.dart
index 400e428ce5..e39651d037 100644
--- a/mobile/apps/locker/lib/utils/file_actions.dart
+++ b/mobile/apps/locker/lib/utils/file_actions.dart
@@ -417,7 +417,7 @@ class FileActions {
}
/// Toggles important status of a single file
- static Future<void> toggleImportant(
+ static Future<void> markImportant(
BuildContext context,
EnteFile file, {
VoidCallback? onSuccess,
@@ -466,7 +466,7 @@ class FileActions {
}
/// Marks multiple files as important
- static Future<void> markMultipleAsImportant(
+ static Future<void> markMultipleImportant(
BuildContext context,
List<EnteFile> files, {
VoidCallback? onSuccess,
@@ -480,7 +480,6 @@ class FileActions {
try {
await dialog.show();
- // Use sync cache for better performance
final filesToMark = files
.where((file) => !FavoritesService.instance.isFavoriteCache(file))
.toList();