π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add option to change gallery layout from home gallery itself
ashilkn783f53bfdc3f
diff --git a/mobile/apps/photos/lib/generated/intl/messages_en.dart b/mobile/apps/photos/lib/generated/intl/messages_en.dartindex 71e695f344..1e8901086d 100644--- a/mobile/apps/photos/lib/generated/intl/messages_en.dart+++ b/mobile/apps/photos/lib/generated/intl/messages_en.dart@@ -774,6 +774,7 @@ class MessageLookup extends MessageLookupByLibrary {"custom": MessageLookupByLibrary.simpleMessage("Custom"),"customEndpoint": m20,"darkTheme": MessageLookupByLibrary.simpleMessage("Dark"),+ "day": MessageLookupByLibrary.simpleMessage("Day"),"dayToday": MessageLookupByLibrary.simpleMessage("Today"),"dayYesterday": MessageLookupByLibrary.simpleMessage("Yesterday"),"declineTrustInvite":@@ -1204,6 +1205,7 @@ class MessageLookup extends MessageLookupByLibrary {"lastWeek": MessageLookupByLibrary.simpleMessage("Last week"),"lastYearsTrip":MessageLookupByLibrary.simpleMessage("Last year\'s trip"),+ "layout": MessageLookupByLibrary.simpleMessage("Layout"),"leave": MessageLookupByLibrary.simpleMessage("Leave"),"leaveAlbum": MessageLookupByLibrary.simpleMessage("Leave album"),"leaveFamily": MessageLookupByLibrary.simpleMessage("Leave family"),diff --git a/mobile/apps/photos/lib/generated/l10n.dart b/mobile/apps/photos/lib/generated/l10n.dartindex c659e463e4..1045fba5f2 100644--- a/mobile/apps/photos/lib/generated/l10n.dart+++ b/mobile/apps/photos/lib/generated/l10n.dart@@ -12365,6 +12365,26 @@ class S {args: [],);}++ /// `Layout`+ String get layout {+ return Intl.message(+ 'Layout',+ name: 'layout',+ desc: '',+ args: [],+ );+ }++ /// `Day`+ String get day {+ return Intl.message(+ 'Day',+ name: 'day',+ desc: '',+ args: [],+ );+ }}class AppLocalizationDelegate extends LocalizationsDelegate<S> {diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex b139f16c78..a4b2c471ec 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -1795,5 +1795,7 @@"thisYear": "This year","groupBy": "Group by","faceThumbnailGenerationFailed": "Unable to generate face thumbnails",- "fileAnalysisFailed": "Unable to analyze file"+ "fileAnalysisFailed": "Unable to analyze file",+ "layout" : "Layout",+ "day": "Day"}diff --git a/mobile/apps/photos/lib/models/gallery/gallery_sections.dart b/mobile/apps/photos/lib/models/gallery/gallery_sections.dartindex c161935eb5..3723af5a3e 100644--- a/mobile/apps/photos/lib/models/gallery/gallery_sections.dart+++ b/mobile/apps/photos/lib/models/gallery/gallery_sections.dart@@ -24,6 +24,7 @@ class GalleryGroups {final String tagPrefix;final bool showSelectAll;final _logger = Logger("GalleryGroups");+ final bool showGallerySettingsCTA;//TODO: Add support for sort orderfinal bool sortOrderAsc;@@ -43,6 +44,7 @@ class GalleryGroups {required this.showSelectAll,this.limitSelectionToOne = false,this.fileToJumpScrollTo,+ this.showGallerySettingsCTA = false,}) {init();if (!groupType.showGroupHeader()) {@@ -195,7 +197,7 @@ class GalleryGroups {final maxOffset = minOffset +(numberOfGridRows * tileHeight) +(numberOfGridRows - 1) * spacing +- groupHeaderExtent!;+ groupHeaderExtent;final bodyFirstIndex = firstIndex + 1;groupLayouts.add(@@ -204,7 +206,7 @@ class GalleryGroups {lastIndex: lastIndex,minOffset: minOffset,maxOffset: maxOffset,- headerExtent: groupHeaderExtent!,+ headerExtent: groupHeaderExtent,tileHeight: tileHeight,spacing: spacing,builder: (context, rowIndex) {@@ -218,6 +220,8 @@ class GalleryGroups {filesInGroup: groupIDToFilesMap[groupID]!,selectedFiles: selectedFiles,showSelectAll: showSelectAll && !limitSelectionToOne,+ showGallerySettingCTA:+ rowIndex == 0 && showGallerySettingsCTA,);} else {return const SizedBox(height: spacing);diff --git a/mobile/apps/photos/lib/ui/components/captioned_text_widget.dart b/mobile/apps/photos/lib/ui/components/captioned_text_widget.dartindex d10810eaa0..f5ba42d4b2 100644--- a/mobile/apps/photos/lib/ui/components/captioned_text_widget.dart+++ b/mobile/apps/photos/lib/ui/components/captioned_text_widget.dart@@ -1,5 +1,6 @@import 'package:flutter/material.dart';import 'package:photos/ente_theme_data.dart';+import "package:photos/utils/string_util.dart";class CaptionedTextWidget extends StatelessWidget {final String title;@@ -23,10 +24,12 @@ class CaptionedTextWidget extends StatelessWidget {final enteColorScheme = Theme.of(context).colorScheme.enteTheme.colorScheme;final enteTextTheme = Theme.of(context).colorScheme.enteTheme.textTheme;+ final capitalized = title.capitalizeFirst();+final List<Widget> children = [Flexible(child: Text(- title,+ capitalized,style: textStyle ??(makeTextBold? enteTextTheme.bodyBold.copyWith(color: textColor)diff --git a/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart b/mobile/apps/photos/lib/ui/home/home_gallery_widget.dartindex 016d590c10..607543f12a 100644--- a/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart+++ b/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart@@ -137,6 +137,7 @@ class _HomeGalleryWidgetState extends State<HomeGalleryWidget> {galleryType: GalleryType.homepage,groupType: widget.groupType,fileToJumpScrollTo: widget.fileToJumpScrollTo,+ showGallerySettingsCTA: true,);return GalleryFilesState(child: SelectionState(diff --git a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dartindex 99233bf30c..cb2fdf0ca9 100644--- a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart+++ b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart@@ -20,7 +20,11 @@ import "package:photos/ui/viewer/gallery/photo_grid_size_picker_page.dart";import "package:photos/utils/navigation_util.dart";class GallerySettingsScreen extends StatefulWidget {- const GallerySettingsScreen({super.key});+ final bool fromGallerySettingsCTA;+ const GallerySettingsScreen({+ super.key,+ required this.fromGallerySettingsCTA,+ });@overrideState<GallerySettingsScreen> createState() => _GallerySettingsScreenState();@@ -54,7 +58,9 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {iconButtonType: IconButtonType.secondary,onTap: () {Navigator.pop(context);- Navigator.pop(context);+ if (!widget.fromGallerySettingsCTA) {+ Navigator.pop(context);+ }},),],diff --git a/mobile/apps/photos/lib/ui/settings/general_section_widget.dart b/mobile/apps/photos/lib/ui/settings/general_section_widget.dartindex d51685eb8d..a1c71dbca5 100644--- a/mobile/apps/photos/lib/ui/settings/general_section_widget.dart+++ b/mobile/apps/photos/lib/ui/settings/general_section_widget.dart@@ -170,7 +170,9 @@ class GeneralSectionWidget extends StatelessWidget {void _onGallerySettingsTapped(BuildContext context) {routeToPage(context,- const GallerySettingsScreen(),+ const GallerySettingsScreen(+ fromGallerySettingsCTA: false,+ ),);}}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 23b338c6ae..dd6b0dceb4 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@@ -4,6 +4,7 @@ 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";+import "package:photos/ui/viewer/gallery/layout_settings.dart";class GroupHeaderWidget extends StatefulWidget {final String title;@@ -12,6 +13,7 @@ class GroupHeaderWidget extends StatefulWidget {final List<EnteFile> filesInGroup;final SelectedFiles? selectedFiles;final bool showSelectAll;+ final bool showGallerySettingCTA;const GroupHeaderWidget({super.key,@@ -20,6 +22,7 @@ class GroupHeaderWidget extends StatefulWidget {required this.filesInGroup,required this.selectedFiles,required this.showSelectAll,+ this.showGallerySettingCTA = false,this.height,});@@ -67,14 +70,15 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {return SizedBox(height: widget.height,- child: Padding(- padding: EdgeInsets.symmetric(- horizontal: horizontalPadding,- vertical: verticalPadding,- ),- child: Row(- children: [- Container(+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.center,+ children: [+ Padding(+ padding: EdgeInsets.symmetric(+ horizontal: horizontalPadding,+ vertical: verticalPadding,+ ),+ child: Container(alignment: Alignment.centerLeft,child: Text(widget.title,@@ -89,34 +93,50 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {overflow: TextOverflow.ellipsis,),),- Expanded(child: Container()),- !widget.showSelectAll- ? 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(),- );+ ),+ Expanded(child: Container()),+ !widget.showSelectAll+ ? 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: colorScheme.strokeMuted,+ size: 18,+ );},),- ],- ),+ onTap: () {+ widget.selectedFiles?.toggleGroupSelection(+ widget.filesInGroup.toSet(),+ );+ },+ ),+ widget.showGallerySettingCTA+ ? const SizedBox(width: 8)+ : const SizedBox.shrink(),+ widget.showGallerySettingCTA+ ? GestureDetector(+ onTap: () => _showLayoutSettingsOverflowMenu(context),+ child: Padding(+ padding: const EdgeInsets.all(4),+ child: Icon(+ Icons.more_vert_outlined,+ color: colorScheme.strokeBase,+ ),+ ),+ )+ : const SizedBox.shrink(),+ const SizedBox(width: 12),+ ],),);}@@ -135,4 +155,14 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {return false;}}++ void _showLayoutSettingsOverflowMenu(BuildContext context) {+ showModalBottomSheet(+ context: context,+ backgroundColor: getEnteColorScheme(context).backgroundElevated,+ builder: (BuildContext context) {+ return const GalleryLayoutSettings();+ },+ );+ }}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dartindex 6565dcc48c..577ad00cdd 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart@@ -62,6 +62,7 @@ class Gallery extends StatefulWidget {final Duration reloadDebounceTime;final Duration reloadDebounceExecutionInterval;final GalleryType? galleryType;+ final bool showGallerySettingsCTA;/// When true, selection will be limited to one item. Tapping on any item/// will select even when no other item is selected.@@ -111,6 +112,7 @@ class Gallery extends StatefulWidget {this.galleryType,this.disableVerticalPaddingForScrollbar = false,this.fileToJumpScrollTo,+ this.showGallerySettingsCTA = false,super.key,});@@ -199,8 +201,8 @@ class GalleryState extends State<Gallery> {Bus.instance.on<TabDoubleTapEvent>().listen((event) async {// todo: Assign ID to Gallery and fire generic event with ID &// target index/date- if (mounted && event.selectedIndex == 0 && _scrollController != null) {- await _scrollController!.animateTo(+ if (mounted && event.selectedIndex == 0) {+ await _scrollController.animateTo(0,duration: const Duration(milliseconds: 250),curve: Curves.easeOutExpo,@@ -306,6 +308,7 @@ class GalleryState extends State<Gallery> {groupHeaderExtent: groupHeaderExtent!,showSelectAll: widget.showSelectAll,limitSelectionToOne: widget.limitSelectionToOne,+ showGallerySettingsCTA: widget.showGallerySettingsCTA,);if (callSetState) {@@ -494,7 +497,7 @@ class GalleryState extends State<Gallery> {subscription.cancel();}_debouncer.cancelDebounceTimer();- _scrollController?.dispose();+ _scrollController.dispose();scrollBarInUseNotifier.dispose();_headerHeightNotifier.dispose();widget.selectedFiles?.removeListener(_selectedFilesListener);@@ -644,6 +647,8 @@ class GalleryState extends State<Gallery> {showSelectAll: widget.showSelectAll &&!widget.limitSelectionToOne,scrollbarInUseNotifier: scrollBarInUseNotifier,+ showGallerySettingsCTA:+ widget.showGallerySettingsCTA,): const SizedBox.shrink(),],@@ -652,67 +657,6 @@ class GalleryState extends State<Gallery> {),);}-- // create groups of 200 files for performance- List<List<EnteFile>> _genericGroupForPerf(List<EnteFile> files) {- if (_groupType == GroupType.size) {- // sort files by fileSize on the bases of _sortOrderAsc- files.sort((a, b) {- if (_sortOrderAsc) {- return a.fileSize!.compareTo(b.fileSize!);- } else {- return b.fileSize!.compareTo(a.fileSize!);- }- });- }- // todo:(neeraj) Stick to default group behaviour for magicSearch and editLocationGallery- // In case of Magic search, we need to hide the scrollbar title (can be done- // by specifying none as groupType)- if (_groupType != GroupType.size) {- return [files];- }-- final List<List<EnteFile>> resultGroupedFiles = [];- List<EnteFile> singleGroupFile = [];- const int groupSize = 40;- for (int i = 0; i < files.length; i += 1) {- singleGroupFile.add(files[i]);- if (singleGroupFile.length == groupSize) {- resultGroupedFiles.add(singleGroupFile);- singleGroupFile = [];- }- }- if (singleGroupFile.isNotEmpty) {- resultGroupedFiles.add(singleGroupFile);- }- _logger.info('Grouped files into ${resultGroupedFiles.length} groups');- return resultGroupedFiles;- }-- List<List<EnteFile>> _groupBasedOnTime(List<EnteFile> files) {- List<EnteFile> dailyFiles = [];-- final List<List<EnteFile>> resultGroupedFiles = [];- for (int index = 0; index < files.length; index++) {- if (index > 0 &&- !_groupType.areFromSameGroup(files[index - 1], files[index])) {- resultGroupedFiles.add(dailyFiles);- dailyFiles = [];- }- dailyFiles.add(files[index]);- }- if (dailyFiles.isNotEmpty) {- resultGroupedFiles.add(dailyFiles);- }- if (_sortOrderAsc) {- resultGroupedFiles- .sort((a, b) => a[0].creationTime!.compareTo(b[0].creationTime!));- } else {- resultGroupedFiles- .sort((a, b) => b[0].creationTime!.compareTo(a[0].creationTime!));- }- return resultGroupedFiles;- }}class PinnedGroupHeader extends StatefulWidget {@@ -722,6 +666,7 @@ class PinnedGroupHeader extends StatefulWidget {final SelectedFiles? selectedFiles;final bool showSelectAll;final ValueNotifier<bool> scrollbarInUseNotifier;+ final bool showGallerySettingsCTA;const PinnedGroupHeader({required this.scrollController,@@ -730,6 +675,7 @@ class PinnedGroupHeader extends StatefulWidget {required this.selectedFiles,required this.showSelectAll,required this.scrollbarInUseNotifier,+ required this.showGallerySettingsCTA,super.key,});@@ -906,6 +852,7 @@ class _PinnedGroupHeaderState extends State<PinnedGroupHeader> {.galleryGroups.groupIDToFilesMap[currentGroupId!]!,selectedFiles: widget.selectedFiles,showSelectAll: widget.showSelectAll,+ showGallerySettingCTA: widget.showGallerySettingsCTA,),),),diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dartnew file mode 100644index 0000000000..4f505d6051--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart@@ -0,0 +1,181 @@+import "dart:async";++import "package:flutter/material.dart";+import "package:photos/core/event_bus.dart";+import "package:photos/events/force_reload_home_gallery_event.dart";+import "package:photos/l10n/l10n.dart";+import "package:photos/service_locator.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/components/captioned_text_widget.dart";+import "package:photos/ui/components/divider_widget.dart";+import "package:photos/ui/components/menu_item_widget/menu_item_widget.dart";+import "package:photos/ui/settings/gallery_settings_screen.dart";+import "package:photos/ui/viewer/gallery/component/group/type.dart";+import "package:photos/utils/navigation_util.dart";++class GalleryLayoutSettings extends StatefulWidget {+ const GalleryLayoutSettings({super.key});++ @override+ State<GalleryLayoutSettings> createState() => _GalleryLayoutSettingsState();+}++class _GalleryLayoutSettingsState extends State<GalleryLayoutSettings> {+ bool isDayLayout = localSettings.getGalleryGroupType() == GroupType.day &&+ localSettings.getPhotoGridSize() == 3;+ bool isMonthLayout = localSettings.getGalleryGroupType() == GroupType.month &&+ localSettings.getPhotoGridSize() == 5;+ late StreamSubscription<ForceReloadHomeGalleryEvent> _forceReloadSubscription;++ @override+ void initState() {+ super.initState();+ _forceReloadSubscription =+ Bus.instance.on<ForceReloadHomeGalleryEvent>().listen((event) {+ if (event.reason == "Gallery layout changed") {+ Future.delayed(const Duration(milliseconds: 1000), () {+ if (!mounted) return;+ setState(() {+ isDayLayout =+ localSettings.getGalleryGroupType() == GroupType.day &&+ localSettings.getPhotoGridSize() == 3;+ isMonthLayout =+ localSettings.getGalleryGroupType() == GroupType.month &&+ localSettings.getPhotoGridSize() == 5;+ });+ });+ }+ });+ }++ @override+ void dispose() {+ _forceReloadSubscription.cancel();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final textTheme = getEnteTextTheme(context);+ final colorScheme = getEnteColorScheme(context);+ return SafeArea(+ child: Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 16,+ vertical: 20,+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Column(+ children: [+ Padding(+ padding:+ const EdgeInsets.symmetric(horizontal: 16, vertical: 12),+ child: Align(+ child: Text(+ context.l10n.layout,+ style: textTheme.largeBold,+ ),+ ),+ ),+ const SizedBox(height: 16),+ Column(+ children: [+ MenuItemWidget(+ leadingIcon: Icons.grid_view_outlined,+ captionedTextWidget: CaptionedTextWidget(+ title: context.l10n.day,+ ),+ menuItemColor: colorScheme.fillFaint,+ alignCaptionedTextToLeft: true,+ isBottomBorderRadiusRemoved: true,+ showOnlyLoadingState: true,+ trailingIcon: isDayLayout ? Icons.check : null,+ onTap: () async {+ final futures = <Future>[+ localSettings.setGalleryGroupType(+ GroupType.day,+ ),+ localSettings.setPhotoGridSize(3),+ ];++ await Future.wait(futures);+ Bus.instance.fire(+ ForceReloadHomeGalleryEvent(+ "Gallery layout changed",+ ),+ );++ Navigator.pop(context);+ },+ ),+ DividerWidget(+ dividerType: DividerType.menuNoIcon,+ bgColor: getEnteColorScheme(context).fillFaint,+ ),+ MenuItemWidget(+ leadingIcon: Icons.grid_on_rounded,+ captionedTextWidget: CaptionedTextWidget(+ title: context.l10n.month,+ ),+ menuItemColor: colorScheme.fillFaint,+ alignCaptionedTextToLeft: true,+ isTopBorderRadiusRemoved: true,+ isBottomBorderRadiusRemoved: true,+ showOnlyLoadingState: true,+ trailingIcon: isMonthLayout ? Icons.check : null,+ onTap: () async {+ final futures = <Future>[+ localSettings.setGalleryGroupType(+ GroupType.month,+ ),+ localSettings.setPhotoGridSize(5),+ ];++ await Future.wait(futures);+ Bus.instance.fire(+ ForceReloadHomeGalleryEvent(+ "Gallery layout changed",+ ),+ );++ Navigator.pop(context);+ },+ ),+ DividerWidget(+ dividerType: DividerType.menuNoIcon,+ bgColor: getEnteColorScheme(context).fillFaint,+ ),+ MenuItemWidget(+ captionedTextWidget: const CaptionedTextWidget(+ title: "Custom",+ ),+ menuItemColor: colorScheme.fillFaint,+ alignCaptionedTextToLeft: true,+ showOnlyLoadingState: true,+ isTopBorderRadiusRemoved: true,+ leadingIcon:+ isDayLayout || isMonthLayout ? null : Icons.check,+ trailingWidget: Icon(+ Icons.chevron_right_outlined,+ color: colorScheme.strokeBase,+ ),+ onTap: () => routeToPage(+ context,+ const GallerySettingsScreen(+ fromGallerySettingsCTA: true,+ ),+ ),+ ),+ ],+ ),+ const SizedBox(height: 16),+ ],+ ),+ ],+ ),+ ),+ );+ }+}diff --git a/mobile/apps/photos/lib/utils/string_util.dart b/mobile/apps/photos/lib/utils/string_util.dartnew file mode 100644index 0000000000..b8a70f3f02--- /dev/null+++ b/mobile/apps/photos/lib/utils/string_util.dart@@ -0,0 +1,6 @@+extension StringCasingExtension on String {+ String capitalizeFirst() {+ if (isEmpty) return this;+ return this[0].toUpperCase() + substring(1);+ }+}