π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Make selection work on the new group header widget
ashilkn4d8d0d1b0736
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_sections.dart b/mobile/apps/photos/lib/models/gallery/gallery_sections.dartindex 365acbeea2..9438fe685e 100644--- a/mobile/apps/photos/lib/models/gallery/gallery_sections.dart+++ b/mobile/apps/photos/lib/models/gallery/gallery_sections.dart@@ -19,6 +19,7 @@ class GalleryGroups {final SelectedFiles? selectedFiles;final bool limitSelectionToOne;final String tagPrefix;+ final bool showSelectAllByDefault;final _logger = Logger("GalleryGroups");//TODO: Add support for sort order@@ -33,6 +34,7 @@ class GalleryGroups {required this.tagPrefix,this.sortOrderAsc = true,required this.headerExtent,+ required this.showSelectAllByDefault,this.limitSelectionToOne = false,}) {init();@@ -109,6 +111,9 @@ class GalleryGroups {.groupType.getTitle(context, groupIDToFilesMap[groupID]!.first),gridSize: crossAxisCount,+ filesInGroup: groupIDToFilesMap[groupID]!,+ selectedFiles: selectedFiles,+ showSelectAllByDefault: showSelectAllByDefault,);} else {final gridRowChildren = <Widget>[];diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dartindex 6785494eeb..15574d6cf6 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart@@ -1,49 +1,143 @@-import "package:flutter/widgets.dart";+import "package:flutter/material.dart";import 'package:photos/core/constants.dart';import "package:photos/generated/l10n.dart";+import "package:photos/models/file/file.dart";+import "package:photos/models/selected_files.dart";import "package:photos/theme/ente_theme.dart";-class GroupHeaderWidget extends StatelessWidget {+class GroupHeaderWidget extends StatefulWidget {final String title;final int gridSize;final double? height;+ final List<EnteFile> filesInGroup;+ final SelectedFiles? selectedFiles;+ final bool showSelectAllByDefault;const GroupHeaderWidget({super.key,required this.title,required this.gridSize,+ required this.filesInGroup,+ required this.selectedFiles,+ required this.showSelectAllByDefault,this.height,});+ @override+ State<GroupHeaderWidget> createState() => _GroupHeaderWidgetState();+}++class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {+ late final ValueNotifier<bool> _showSelectAllButtonNotifier;+ late final ValueNotifier<bool> _areAllFromGroupSelectedNotifier;++ @override+ void initState() {+ super.initState();+ _areAllFromGroupSelectedNotifier =+ ValueNotifier(_areAllFromGroupSelected());++ widget.selectedFiles?.addListener(_selectedFilesListener);+ _showSelectAllButtonNotifier = ValueNotifier(widget.showSelectAllByDefault);+ }++ @override+ void dispose() {+ _areAllFromGroupSelectedNotifier.dispose();+ _showSelectAllButtonNotifier.dispose();+ widget.selectedFiles?.removeListener(_selectedFilesListener);+ super.dispose();+ }+@overrideWidget build(BuildContext context) {final colorScheme = getEnteColorScheme(context);final textTheme = getEnteTextTheme(context);final textStyle =- gridSize < photoGridSizeMax ? textTheme.body : textTheme.small;- final double horizontalPadding = gridSize < photoGridSizeMax ? 12.0 : 8.0;- final double verticalPadding = gridSize < photoGridSizeMax ? 12.0 : 14.0;+ widget.gridSize < photoGridSizeMax ? textTheme.body : textTheme.small;+ final double horizontalPadding =+ widget.gridSize < photoGridSizeMax ? 12.0 : 8.0;+ final double verticalPadding =+ widget.gridSize < photoGridSizeMax ? 12.0 : 14.0;return SizedBox(- height: height,+ height: widget.height,child: Padding(padding: EdgeInsets.symmetric(horizontal: horizontalPadding,vertical: verticalPadding,),- child: Container(- alignment: Alignment.centerLeft,- child: Text(- title,- style: (title == S.of(context).dayToday)- ? textStyle- : textStyle.copyWith(color: colorScheme.textMuted),- maxLines: 1,- // TODO: Make it possible to see the full title if overflowing- overflow: TextOverflow.ellipsis,- ),+ child: Row(+ children: [+ Container(+ alignment: Alignment.centerLeft,+ child: Text(+ widget.title,+ style: (widget.title == S.of(context).dayToday)+ ? textStyle+ : textStyle.copyWith(color: colorScheme.textMuted),+ maxLines: 1,+ // TODO: Make it possible to see the full title if overflowing+ overflow: TextOverflow.ellipsis,+ ),+ ),+ Expanded(child: Container()),+ ValueListenableBuilder(+ valueListenable: _showSelectAllButtonNotifier,+ builder: (context, value, _) {+ return !value+ ? const SizedBox.shrink()+ : GestureDetector(+ behavior: HitTestBehavior.translucent,+ child: ValueListenableBuilder(+ valueListenable: _areAllFromGroupSelectedNotifier,+ builder: (context, dynamic value, _) {+ return value+ ? const Icon(+ Icons.check_circle,+ size: 18,+ )+ : Icon(+ Icons.check_circle_outlined,+ color:+ getEnteColorScheme(context).strokeMuted,+ size: 18,+ );+ },+ ),+ onTap: () {+ widget.selectedFiles?.toggleGroupSelection(+ widget.filesInGroup.toSet(),+ );+ },+ );+ },+ ),+ ],),),);}++ void _selectedFilesListener() {+ if (widget.selectedFiles == null) return;+ _areAllFromGroupSelectedNotifier.value =+ widget.selectedFiles!.files.containsAll(widget.filesInGroup.toSet());++ //Can remove this if we decide to show select all by default for all galleries+ if (widget.selectedFiles!.files.isEmpty && !widget.showSelectAllByDefault) {+ _showSelectAllButtonNotifier.value = false;+ } else {+ _showSelectAllButtonNotifier.value = true;+ }+ }++ bool _areAllFromGroupSelected() {+ if (widget.selectedFiles != null &&+ widget.selectedFiles!.files.length >= widget.filesInGroup.length) {+ return widget.selectedFiles!.files.containsAll(widget.filesInGroup);+ } else {+ return false;+ }+ }}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dartindex 9d4b913013..55141f12ba 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart@@ -13,7 +13,6 @@ import 'package:photos/models/file_load_result.dart';import "package:photos/models/gallery/gallery_sections.dart";import 'package:photos/models/selected_files.dart';import "package:photos/service_locator.dart";-import "package:photos/theme/ente_theme.dart";import 'package:photos/ui/common/loading_widget.dart';import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";import "package:photos/ui/viewer/gallery/component/group/type.dart";@@ -224,8 +223,11 @@ class GalleryState extends State<Gallery> {getIntrinsicSizeOfWidget(GroupHeaderWidget(- title: "This is a temp title",+ title: "Dummy title",gridSize: localSettings.getPhotoGridSize(),+ filesInGroup: const [],+ selectedFiles: null,+ showSelectAllByDefault: false,),context,).then((size) {@@ -434,7 +436,6 @@ class GalleryState extends State<Gallery> {if (groupHeaderExtent == null) return const SliverFillRemaining();_logger.info("Building Gallery ${widget.tagPrefix}");- final colorScheme = getEnteColorScheme(context);final galleryGroups = GalleryGroups(allFiles: _allGalleryFiles,@@ -443,6 +444,7 @@ class GalleryState extends State<Gallery> {selectedFiles: widget.selectedFiles,tagPrefix: widget.tagPrefix,headerExtent: groupHeaderExtent!,+ showSelectAllByDefault: widget.showSelectAllByDefault,);GalleryFilesState.of(context).setGalleryFiles = _allGalleryFiles;if (!_hasLoadedFiles) {@@ -507,6 +509,8 @@ class GalleryState extends State<Gallery> {galleryGroups: galleryGroups,getSectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox: () =>_sectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox,+ selectedFiles: widget.selectedFiles,+ showSelectAllByDefault: widget.showSelectAllByDefault,),],),@@ -581,10 +585,15 @@ class PinnedGroupHeader extends StatefulWidget {final GalleryGroups galleryGroups;final double? Function()getSectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox;+ final SelectedFiles? selectedFiles;+ final bool showSelectAllByDefault;+const PinnedGroupHeader({required this.scrollController,required this.galleryGroups,required this.getSectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox,+ required this.selectedFiles,+ required this.showSelectAllByDefault,super.key,});@@ -593,7 +602,7 @@ class PinnedGroupHeader extends StatefulWidget {}class _PinnedGroupHeaderState extends State<PinnedGroupHeader> {- String? currentGroupID;+ String? currentGroupId;@overridevoid initState() {super.initState();@@ -617,7 +626,7 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader> {widget.getSectionedListSliverRenderBoxYOffsetRelativeToStackRenderBox()!;if (normalizedScrollOffset < 0) {- currentGroupID = null;+ currentGroupId = null;} else {final groupScrollOffsets = widget.galleryGroups.groupScrollOffsets;@@ -649,7 +658,7 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader> {high = mid - 1;}}- currentGroupID = widget.galleryGroups+ currentGroupId = widget.galleryGroups.scrollOffsetToGroupIdMap[groupScrollOffsets[floorIndex]];}@@ -658,16 +667,20 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader> {@overrideWidget build(BuildContext context) {- return currentGroupID != null+ return currentGroupId != null? GroupHeaderWidget(- title: widget.galleryGroups.groupIdToheaderDataMap[currentGroupID!]!+ title: widget.galleryGroups.groupIdToheaderDataMap[currentGroupId!]!.groupType.getTitle(context,- widget.galleryGroups.groupIDToFilesMap[currentGroupID]!.first,+ widget.galleryGroups.groupIDToFilesMap[currentGroupId]!.first,),gridSize: localSettings.getPhotoGridSize(),height: widget.galleryGroups.headerExtent,+ filesInGroup:+ widget.galleryGroups.groupIDToFilesMap[currentGroupId!]!,+ selectedFiles: widget.selectedFiles,+ showSelectAllByDefault: widget.showSelectAllByDefault,): const SizedBox.shrink();}