π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
integrate SelectedCollections model into CollectionRowWidget, ItemListView, AllCollectionsPage, and HomePage for improved user interaction and selection management.
AmanRajSinghMouryae58193d545bc
diff --git a/mobile/apps/locker/lib/ui/components/collection_row_widget.dart b/mobile/apps/locker/lib/ui/components/collection_row_widget.dartindex e5d97b9ca2..d1e16d93af 100644--- a/mobile/apps/locker/lib/ui/components/collection_row_widget.dart+++ b/mobile/apps/locker/lib/ui/components/collection_row_widget.dart@@ -1,8 +1,10 @@import "package:ente_events/event_bus.dart";+import "package:ente_ui/components/buttons/icon_button_widget.dart";import "package:ente_ui/theme/ente_theme.dart";import "package:flutter/material.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/services/collections/collections_service.dart";import "package:locker/services/collections/models/collection.dart";import "package:locker/services/collections/models/collection_view_type.dart";@@ -16,12 +18,18 @@ class CollectionRowWidget extends StatelessWidget {final Collection collection;final List<OverflowMenuAction>? overflowActions;final bool isLastItem;+ final SelectedCollections? selectedCollections;+ final void Function(Collection)? onTapCallback;+ final void Function(Collection)? onLongPressCallback;const CollectionRowWidget({super.key,required this.collection,this.overflowActions,this.isLastItem = false,+ this.selectedCollections,+ this.onTapCallback,+ this.onLongPressCallback,});@override@@ -91,34 +99,69 @@ class CollectionRowWidget extends StatelessWidget {);return GestureDetector(- onTap: () => _openCollection(context),+ onTap: () {+ if (onTapCallback != null) {+ onTapCallback!(collection);+ } else {+ _openCollection(context);+ }+ },+ onLongPress: () {+ if (onLongPressCallback != null) {+ onLongPressCallback!(collection);+ }+ },behavior: HitTestBehavior.opaque,- child: Container(- decoration: BoxDecoration(- border: Border.all(- color: colorScheme.strokeFaint,- ),- borderRadius: const BorderRadius.all(Radius.circular(6)),- ),- child: Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- collectionRowWidget,- Flexible(- flex: 1,- 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: selectedCollections ?? ValueNotifier(false),+ builder: (context, _) {+ final bool isSelected =+ selectedCollections?.isCollectionSelected(collection) ?? 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: [+ collectionRowWidget,+ 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.dartindex cc68a8f4a4..0ed14382df 100644--- a/mobile/apps/locker/lib/ui/components/item_list_view.dart+++ b/mobile/apps/locker/lib/ui/components/item_list_view.dart@@ -1,10 +1,14 @@import 'package:ente_ui/theme/ente_theme.dart';+import "package:ente_utils/ente_utils.dart";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/services/collections/models/collection.dart';import 'package:locker/services/files/sync/models/file.dart';import "package:locker/ui/components/collection_row_widget.dart";import "package:locker/ui/components/file_row_widget.dart";+import 'package:locker/ui/pages/collection_page.dart';import 'package:locker/utils/collection_sort_util.dart';class OverflowMenuAction {@@ -32,6 +36,7 @@ class ItemListView extends StatefulWidget {final Widget? emptyStateWidget;final List<OverflowMenuAction>? fileOverflowActions;final List<OverflowMenuAction>? collectionOverflowActions;+ final SelectedCollections? selectedCollections;const ItemListView({super.key,@@ -41,6 +46,7 @@ class ItemListView extends StatefulWidget {this.emptyStateWidget,this.fileOverflowActions,this.collectionOverflowActions,+ this.selectedCollections,});@override@@ -51,6 +57,7 @@ class _ItemListViewState extends State<ItemListView> {List<_ListItem> _sortedItems = [];int _sortColumnIndex = 1;bool _sortAscending = false;+ bool isAnyCollectionSelected = false;@overridevoid initState() {@@ -128,6 +135,19 @@ class _ItemListViewState extends State<ItemListView> {});}+ Future<void> _navigateToCollectionPage(Collection collection) async {+ await routeToPage(context, CollectionPage(collection: collection));+ }++ Future<void> _toggleCollectionSelection(Collection collection) async {+ await HapticFeedback.lightImpact();+ widget.selectedCollections!.toggleSelection(collection);+ setState(() {+ isAnyCollectionSelected =+ widget.selectedCollections!.collections.isNotEmpty;+ });+ }+@overrideWidget build(BuildContext context) {if (_sortedItems.isEmpty && widget.emptyStateWidget != null) {@@ -158,6 +178,17 @@ class _ItemListViewState extends State<ItemListView> {fileOverflowActions: widget.fileOverflowActions,collectionOverflowActions: widget.collectionOverflowActions,isLastItem: isLastItem,+ selectedCollections: widget.selectedCollections,+ onCollectionTap: (c) {+ isAnyCollectionSelected+ ? _toggleCollectionSelection(c)+ : _navigateToCollectionPage(c);+ },+ onCollectionLongPress: (c) {+ isAnyCollectionSelected+ ? _navigateToCollectionPage(c)+ : _toggleCollectionSelection(c);+ },);},),@@ -339,6 +370,9 @@ class ListItemWidget extends StatelessWidget {final List<OverflowMenuAction>? fileOverflowActions;final List<OverflowMenuAction>? collectionOverflowActions;final bool isLastItem;+ final SelectedCollections? selectedCollections;+ final Function(Collection)? onCollectionTap;+ final Function(Collection)? onCollectionLongPress;const ListItemWidget({super.key,@@ -348,15 +382,22 @@ class ListItemWidget extends StatelessWidget {this.fileOverflowActions,this.collectionOverflowActions,this.isLastItem = false,+ this.selectedCollections,+ this.onCollectionTap,+ this.onCollectionLongPress,});@overrideWidget build(BuildContext context) {if (item.isCollection && item.collection != null) {+ final collection = item.collection!;return CollectionRowWidget(- collection: item.collection!,+ collection: collection,overflowActions: collectionOverflowActions,isLastItem: isLastItem,+ selectedCollections: selectedCollections,+ onTapCallback: onCollectionTap,+ onLongPressCallback: onCollectionLongPress,);} else if (!item.isCollection && item.file != null) {return FileRowWidget(diff --git a/mobile/apps/locker/lib/ui/pages/all_collections_page.dart b/mobile/apps/locker/lib/ui/pages/all_collections_page.dartindex 5219137a7d..6a24498081 100644--- a/mobile/apps/locker/lib/ui/pages/all_collections_page.dart+++ b/mobile/apps/locker/lib/ui/pages/all_collections_page.dart@@ -5,6 +5,7 @@ import 'package:ente_ui/theme/ente_theme.dart';import 'package:flutter/material.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/services/collections/collections_service.dart';import 'package:locker/services/collections/models/collection.dart';import 'package:locker/services/files/sync/models/file.dart';@@ -26,10 +27,12 @@ enum UISectionType {class AllCollectionsPage extends StatefulWidget {final UISectionType viewType;+ final SelectedCollections? selectedCollections;const AllCollectionsPage({super.key,this.viewType = UISectionType.homeCollections,+ this.selectedCollections,});@override@@ -165,6 +168,16 @@ class _AllCollectionsPageState extends State<AllCollectionsPage>],),body: _buildBody(),+ bottomNavigationBar: widget.selectedCollections != null+ ? ListenableBuilder(+ listenable: widget.selectedCollections!,+ builder: (context, _) {+ return widget.selectedCollections!.hasSelections+ ? _buildSelectionActionBar()+ : const SizedBox.shrink();+ },+ )+ : null,),);}@@ -268,6 +281,7 @@ class _AllCollectionsPageState extends State<AllCollectionsPage>child: ItemListView(collections: _sortedCollections,enableSorting: true,+ selectedCollections: widget.selectedCollections,),),if (!isSearchActive &&@@ -435,6 +449,309 @@ class _AllCollectionsPageState extends State<AllCollectionsPage>);}+ Widget _buildSelectionActionBar() {+ final bottomPadding = MediaQuery.of(context).padding.bottom;+ final colorScheme = getEnteColorScheme(context);+ final isDarkMode = Theme.of(context).brightness == Brightness.dark;++ return ConstrainedBox(+ constraints: BoxConstraints(+ maxHeight: MediaQuery.of(context).size.height * 0.4,+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ mainAxisAlignment: MainAxisAlignment.end,+ children: [+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16.0),+ child: Row(+ children: [+ ListenableBuilder(+ listenable: widget.selectedCollections!,+ builder: (context, child) {+ final isAllSelected = widget.selectedCollections!.count ==+ _sortedCollections.length;+ final buttonText =+ isAllSelected ? 'Deselect all' : 'Select all';+ final iconData = isAllSelected+ ? Icons.remove_circle_outline+ : Icons.check_circle_outline_outlined;++ return Material(+ shape: StadiumBorder(+ side: BorderSide(+ color: colorScheme.strokeMuted,+ width: 0.5,+ ),+ ),+ color: colorScheme.backgroundElevated2,+ clipBehavior: Clip.antiAlias,+ child: InkWell(+ onTap: () {+ if (isAllSelected) {+ widget.selectedCollections!.clearAll();+ } else {+ widget.selectedCollections!+ .select(_sortedCollections.toSet());+ }+ },+ child: Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 12.0,+ vertical: 8.0,+ ),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ buttonText,+ ),+ const SizedBox(width: 6),+ Icon(+ iconData,+ color: Colors.grey,+ size: 15,+ ),+ ],+ ),+ ),+ ),+ );+ },+ ),+ const Spacer(),+ ListenableBuilder(+ listenable: widget.selectedCollections!,+ builder: (context, child) {+ final count = widget.selectedCollections!.count;+ final countText =+ count == 1 ? '1 selected' : '$count selected';++ return Material(+ shape: StadiumBorder(+ side: BorderSide(+ color: colorScheme.strokeMuted,+ width: 0.5,+ ),+ ),+ color: colorScheme.backgroundElevated2,+ clipBehavior: Clip.antiAlias,+ child: InkWell(+ onTap: () {+ widget.selectedCollections!.clearAll();+ setState(() {});+ },+ child: Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 12.0,+ vertical: 8.0,+ ),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ countText,+ ),+ const SizedBox(width: 6),+ const Icon(+ Icons.close,+ size: 15,+ color: Colors.grey,+ ),+ ],+ ),+ ),+ ),+ );+ },+ ),+ ],+ ),+ ),+ const SizedBox(height: 10),+ Card(+ margin: EdgeInsets.zero,+ shape: RoundedRectangleBorder(+ borderRadius: const BorderRadius.only(+ topLeft: Radius.circular(16),+ topRight: Radius.circular(16),+ ),+ side: BorderSide(+ color: colorScheme.strokeMuted.withValues(alpha: 0.1),+ width: 1,+ ),+ ),+ shadowColor: isDarkMode+ ? Colors.black.withValues(alpha: 0.7)+ : Colors.grey.withValues(alpha: 0.5),+ elevation: 4,+ color: isDarkMode+ ? colorScheme.fillFaint+ : colorScheme.backgroundElevated2,+ child: Padding(+ padding: EdgeInsets.fromLTRB(16, 16, 16, 28 + bottomPadding),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ _buildActionButtons(),+ ],+ ),+ ),+ ),+ ],+ ),+ );+ }++ Widget _buildActionButtons() {+ return ListenableBuilder(+ listenable: widget.selectedCollections!,+ builder: (context, child) {+ final selectedCollections = widget.selectedCollections!.collections;+ if (selectedCollections.isEmpty) {+ return const SizedBox.shrink();+ }++ final actions = _getActionsForSelection(selectedCollections);++ return AnimatedContainer(+ duration: const Duration(milliseconds: 200),+ curve: Curves.easeInOut,+ decoration: BoxDecoration(+ color: Theme.of(context).brightness == Brightness.dark+ ? getEnteColorScheme(context).backgroundElevated2+ : const Color(0xFFF7F7F7),+ borderRadius: BorderRadius.circular(12),+ ),+ child: Padding(+ padding: const EdgeInsets.symmetric(vertical: 4.0),+ child: Row(+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,+ children: actions,+ ),+ ),+ );+ },+ );+ }++ List<Widget> _getActionsForSelection(+ Set<Collection> selectedCollections,+ ) {+ final isSingleSelection = selectedCollections.length == 1;+ final collection = isSingleSelection ? selectedCollections.first : null;+ final actions = <Widget>[];++ if (isSingleSelection) {+ actions.addAll([+ _buildActionButton(+ icon: Icons.share_outlined,+ label: context.l10n.share,+ onTap: () {+ ScaffoldMessenger.of(context).showSnackBar(+ SnackBar(+ content: Text('Share ${collection?.name ?? 'Collection'}'),+ ),+ );+ },+ ),+ _buildActionButton(+ icon: Icons.edit_outlined,+ label: context.l10n.edit,+ onTap: () {+ ScaffoldMessenger.of(context).showSnackBar(+ SnackBar(+ content: Text('Rename ${collection?.name ?? 'Collection'}'),+ ),+ );+ },+ ),+ _buildActionButton(+ icon: Icons.delete_outline,+ label: context.l10n.delete,+ onTap: () {+ ScaffoldMessenger.of(context).showSnackBar(+ SnackBar(+ content: Text('Delete ${collection?.name ?? 'Collection'}'),+ ),+ );+ },+ isDestructive: true,+ ),+ ]);+ } else {+ actions.addAll([+ _buildActionButton(+ icon: Icons.share_outlined,+ label: 'Share All',+ onTap: () {+ ScaffoldMessenger.of(context).showSnackBar(+ SnackBar(+ content:+ Text('Share ${selectedCollections.length} collections'),+ ),+ );+ },+ ),+ _buildActionButton(+ icon: Icons.delete_outline,+ label: 'Delete All',+ onTap: () {+ ScaffoldMessenger.of(context).showSnackBar(+ SnackBar(+ content:+ Text('Delete ${selectedCollections.length} collections'),+ ),+ );+ },+ isDestructive: true,+ ),+ ]);+ }+ return actions;+ }++ Widget _buildActionButton({+ required IconData icon,+ required String label,+ required VoidCallback onTap,+ bool isDestructive = false,+ }) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);+ final color = isDestructive ? Colors.red : colorScheme.textBase;++ return InkWell(+ onTap: onTap,+ borderRadius: BorderRadius.circular(12),+ highlightColor: color.withValues(alpha: 0.1),+ splashColor: color.withValues(alpha: 0.1),+ child: Padding(+ padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 8.0),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Icon(+ icon,+ color: color,+ size: 22,+ ),+ const SizedBox(height: 6),+ Text(+ label,+ style: textTheme.small.copyWith(+ color: color,+ ),+ textAlign: TextAlign.center,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ ),+ ],+ ),+ ),+ );+ }+String _getTitle(BuildContext context) {switch (widget.viewType) {case UISectionType.homeCollections:diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dartindex 46ef115230..98ef53c3f5 100644--- a/mobile/apps/locker/lib/ui/pages/home_page.dart+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart@@ -12,6 +12,7 @@ import 'package:flutter/material.dart';import 'package:listen_sharing_intent/listen_sharing_intent.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/services/collections/collections_service.dart';import 'package:locker/services/collections/models/collection.dart';import 'package:locker/services/files/sync/models/file.dart';@@ -48,6 +49,7 @@ class _HomePageState extends UploaderPageState<HomePage>bool _isSettingsOpen = false;List<Collection> _collections = [];+ late final SelectedCollections _selectedCollections;List<Collection> _filteredCollections = [];List<EnteFile> _recentFiles = [];List<EnteFile> _filteredFiles = [];@@ -126,6 +128,7 @@ class _HomePageState extends UploaderPageState<HomePage>@overridevoid initState() {super.initState();+ _selectedCollections = SelectedCollections();_animationController = AnimationController(duration: const Duration(milliseconds: 300),vsync: this,@@ -745,6 +748,7 @@ class _HomePageState extends UploaderPageState<HomePage>MaterialPageRoute(builder: (context) => AllCollectionsPage(viewType: viewType,+ selectedCollections: _selectedCollections,),),);