Skip to content

armgit / ente

Public Imported from GitHub
0

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

Enhance file selection functionality in FileRowWidget and ItemListView by integrating SelectedFiles model and adding onTap/onLongPress callbacks.

AmanRajSinghMourya58ee0a7de50a
diff --git a/mobile/apps/locker/lib/ui/components/file_row_widget.dart b/mobile/apps/locker/lib/ui/components/file_row_widget.dart
index e34af3e121..69cf9d6647 100644
--- a/mobile/apps/locker/lib/ui/components/file_row_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/file_row_widget.dart
@@ -1,12 +1,14 @@
import "dart:io";
import "package:ente_ui/components/buttons/button_widget.dart";
+import "package:ente_ui/components/buttons/icon_button_widget.dart";
import "package:ente_ui/components/buttons/models/button_type.dart";
import "package:ente_ui/theme/ente_theme.dart";
import "package:ente_ui/utils/dialog_util.dart";
import "package:ente_utils/share_utils.dart";
import "package:flutter/material.dart";
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/configuration.dart";
@@ -28,6 +30,9 @@ class FileRowWidget extends StatelessWidget {
final List<Collection> collections;
final List<OverflowMenuAction>? overflowActions;
final bool isLastItem;
+ final SelectedFiles? selectedFiles;
+ final void Function(EnteFile)? onTapCallback;
+ final void Function(EnteFile)? onLongPressCallback;
const FileRowWidget({
super.key,
@@ -35,6 +40,9 @@ class FileRowWidget extends StatelessWidget {
required this.collections,
this.overflowActions,
this.isLastItem = false,
+ this.selectedFiles,
+ this.onTapCallback,
+ this.onLongPressCallback,
});
@override
@@ -106,32 +114,70 @@ class FileRowWidget extends StatelessWidget {
);
return GestureDetector(
- onTap: () => _openFile(context),
+ onTap: () {
+ if (onTapCallback != null) {
+ onTapCallback!(file);
+ } else {
+ _openFile(context);
+ }
+ },
+ onLongPress: () {
+ if (onLongPressCallback != null) {
+ onLongPressCallback!(file);
+ } else {
+ _openFile(context);
+ }
+ },
behavior: HitTestBehavior.opaque,
- child: Container(
- decoration: BoxDecoration(
- border: Border.all(
- color: colorScheme.strokeFaint,
- ),
- borderRadius: const BorderRadius.all(Radius.circular(6)),
- ),
- child: Row(
- children: [
- fileRowWidget,
- Flexible(
- child: PopupMenuButton<String>(
- onSelected: (value) => _handleMenuAction(context, value),
- icon: const Icon(
- Icons.more_vert,
- size: 20,
- ),
- itemBuilder: (BuildContext context) {
- return _buildPopupMenuItems(context);
- },
+ child: ListenableBuilder(
+ listenable: selectedFiles ?? ValueNotifier(false),
+ builder: (context, _) {
+ final bool isSelected = selectedFiles?.isFileSelected(file) ?? false;
+ return AnimatedContainer(
+ duration: const Duration(milliseconds: 200),
+ curve: Curves.easeOut,
+ decoration: BoxDecoration(
+ border: Border.all(
+ color: isSelected
+ ? colorScheme.strokeMuted
+ : colorScheme.strokeFainter,
),
+ borderRadius: const BorderRadius.all(Radius.circular(6)),
),
- ],
- ),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ fileRowWidget,
+ Flexible(
+ flex: 1,
+ child: AnimatedSwitcher(
+ duration: const Duration(milliseconds: 200),
+ switchInCurve: Curves.easeOut,
+ switchOutCurve: Curves.easeIn,
+ child: isSelected
+ ? IconButtonWidget(
+ key: const ValueKey("selected"),
+ icon: Icons.check_circle_rounded,
+ iconButtonType: IconButtonType.secondary,
+ iconColor: colorScheme.blurStrokeBase,
+ )
+ : PopupMenuButton<String>(
+ onSelected: (value) =>
+ _handleMenuAction(context, value),
+ icon: const Icon(
+ Icons.more_vert,
+ size: 20,
+ ),
+ itemBuilder: (BuildContext context) {
+ return _buildPopupMenuItems(context);
+ },
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ },
),
);
}
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 778ddcf878..c64b4ea775 100644
--- a/mobile/apps/locker/lib/ui/components/item_list_view.dart
+++ b/mobile/apps/locker/lib/ui/components/item_list_view.dart
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import "package:flutter/services.dart";
import 'package:locker/l10n/l10n.dart';
import 'package:locker/models/selected_collections.dart';
+import 'package:locker/models/selected_files.dart';
import 'package:locker/services/collections/models/collection.dart';
import 'package:locker/services/files/sync/models/file.dart';
import "package:locker/ui/components/collection_row_widget.dart";
@@ -37,6 +38,7 @@ class ItemListView extends StatefulWidget {
final List<OverflowMenuAction>? fileOverflowActions;
final List<OverflowMenuAction>? collectionOverflowActions;
final SelectedCollections? selectedCollections;
+ final SelectedFiles? selectedFiles;
const ItemListView({
super.key,
@@ -47,6 +49,7 @@ class ItemListView extends StatefulWidget {
this.fileOverflowActions,
this.collectionOverflowActions,
this.selectedCollections,
+ this.selectedFiles,
});
@override
@@ -143,6 +146,11 @@ class _ItemListViewState extends State<ItemListView> {
widget.selectedCollections!.toggleSelection(collection);
}
+ void _toggleFileSelection(EnteFile file) {
+ HapticFeedback.lightImpact();
+ widget.selectedFiles!.toggleSelection(file);
+ }
+
@override
Widget build(BuildContext context) {
if (_sortedItems.isEmpty && widget.emptyStateWidget != null) {
@@ -168,12 +176,15 @@ class _ItemListViewState extends State<ItemListView> {
final item = _sortedItems[index];
final isLastItem = index == _sortedItems.length - 1;
- if (widget.selectedCollections != null) {
+ final hasCollectionSelection = widget.selectedCollections != null;
+ final hasFileSelection = widget.selectedFiles != null;
+
+ if (hasCollectionSelection && item.isCollection) {
return ListenableBuilder(
listenable: widget.selectedCollections!,
builder: (context, child) {
final isAnyCollectionSelected =
- widget.selectedCollections!.hasSelections;
+ widget.selectedCollections?.hasSelections ?? false;
return ListItemWidget(
item: item,
@@ -182,6 +193,7 @@ class _ItemListViewState extends State<ItemListView> {
collectionOverflowActions: widget.collectionOverflowActions,
isLastItem: isLastItem,
selectedCollections: widget.selectedCollections,
+ selectedFiles: widget.selectedFiles,
onCollectionTap: (c) {
isAnyCollectionSelected
? _toggleCollectionSelection(c)
@@ -195,6 +207,33 @@ class _ItemListViewState extends State<ItemListView> {
);
},
);
+ } else if (hasFileSelection && !item.isCollection) {
+ return ListenableBuilder(
+ listenable: widget.selectedFiles!,
+ builder: (context, child) {
+ final isAnyFileSelected =
+ widget.selectedFiles?.hasSelections ?? false;
+ return ListItemWidget(
+ item: item,
+ collections: widget.collections,
+ fileOverflowActions: widget.fileOverflowActions,
+ collectionOverflowActions: widget.collectionOverflowActions,
+ isLastItem: isLastItem,
+ selectedCollections: widget.selectedCollections,
+ selectedFiles: widget.selectedFiles,
+ onFileTap: isAnyFileSelected
+ ? (file) {
+ _toggleFileSelection(file);
+ }
+ : null,
+ onFileLongPress: isAnyFileSelected
+ ? null
+ : (file) {
+ _toggleFileSelection(file);
+ },
+ );
+ },
+ );
} else {
return ListItemWidget(
item: item,
@@ -203,8 +242,7 @@ class _ItemListViewState extends State<ItemListView> {
collectionOverflowActions: widget.collectionOverflowActions,
isLastItem: isLastItem,
selectedCollections: widget.selectedCollections,
- onCollectionTap: (c) => _navigateToCollectionPage(c),
- onCollectionLongPress: (c) => _toggleCollectionSelection(c),
+ selectedFiles: widget.selectedFiles,
);
}
},
@@ -388,8 +426,11 @@ class ListItemWidget extends StatelessWidget {
final List<OverflowMenuAction>? collectionOverflowActions;
final bool isLastItem;
final SelectedCollections? selectedCollections;
+ final SelectedFiles? selectedFiles;
final Function(Collection)? onCollectionTap;
final Function(Collection)? onCollectionLongPress;
+ final Function(EnteFile)? onFileTap;
+ final Function(EnteFile)? onFileLongPress;
const ListItemWidget({
super.key,
@@ -400,8 +441,11 @@ class ListItemWidget extends StatelessWidget {
this.collectionOverflowActions,
this.isLastItem = false,
this.selectedCollections,
+ this.selectedFiles,
this.onCollectionTap,
this.onCollectionLongPress,
+ this.onFileTap,
+ this.onFileLongPress,
});
@override
@@ -422,6 +466,9 @@ class ListItemWidget extends StatelessWidget {
collections: collections,
overflowActions: fileOverflowActions,
isLastItem: isLastItem,
+ selectedFiles: selectedFiles,
+ onTapCallback: onFileTap,
+ onLongPressCallback: onFileLongPress,
);
} else {
return Container(