π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Make group by feature functional on gallery
ashilkn7ff2c8f424d0
diff --git a/mobile/apps/photos/lib/generated/intl/messages_en.dart b/mobile/apps/photos/lib/generated/intl/messages_en.dartindex f9bdd4c629..d8e386a7c8 100644--- a/mobile/apps/photos/lib/generated/intl/messages_en.dart+++ b/mobile/apps/photos/lib/generated/intl/messages_en.dart@@ -1096,6 +1096,7 @@ class MessageLookup extends MessageLookupByLibrary {"grantPermission":MessageLookupByLibrary.simpleMessage("Grant permission"),"greenery": MessageLookupByLibrary.simpleMessage("The green life"),+ "groupBy": MessageLookupByLibrary.simpleMessage("Group by"),"groupNearbyPhotos":MessageLookupByLibrary.simpleMessage("Group nearby photos"),"guestView": MessageLookupByLibrary.simpleMessage("Guest view"),@@ -2036,6 +2037,8 @@ class MessageLookup extends MessageLookupByLibrary {"thisIsPersonVerificationId": m100,"thisIsYourVerificationId": MessageLookupByLibrary.simpleMessage("This is your Verification ID"),+ "thisMonth": MessageLookupByLibrary.simpleMessage("This month"),+ "thisWeek": MessageLookupByLibrary.simpleMessage("This week"),"thisWeekThroughTheYears":MessageLookupByLibrary.simpleMessage("This week through the years"),"thisWeekXYearsAgo": m101,@@ -2050,6 +2053,7 @@ class MessageLookup extends MessageLookupByLibrary {"thisWillRemovePublicLinksOfAllSelectedQuickLinks":MessageLookupByLibrary.simpleMessage("This will remove public links of all selected quick links."),+ "thisYear": MessageLookupByLibrary.simpleMessage("This year"),"throughTheYears": m102,"toEnableAppLockPleaseSetupDevicePasscodeOrScreen":MessageLookupByLibrary.simpleMessage(diff --git a/mobile/apps/photos/lib/generated/l10n.dart b/mobile/apps/photos/lib/generated/l10n.dartindex 5a63f58f68..2f434ad5da 100644--- a/mobile/apps/photos/lib/generated/l10n.dart+++ b/mobile/apps/photos/lib/generated/l10n.dart@@ -12295,6 +12295,46 @@ class S {args: [],);}++ /// `This week`+ String get thisWeek {+ return Intl.message(+ 'This week',+ name: 'thisWeek',+ desc: '',+ args: [],+ );+ }++ /// `This month`+ String get thisMonth {+ return Intl.message(+ 'This month',+ name: 'thisMonth',+ desc: '',+ args: [],+ );+ }++ /// `This year`+ String get thisYear {+ return Intl.message(+ 'This year',+ name: 'thisYear',+ desc: '',+ args: [],+ );+ }++ /// `Group by`+ String get groupBy {+ return Intl.message(+ 'Group by',+ name: 'groupBy',+ 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 e9cd89b1f7..8d8e338633 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -1788,5 +1788,9 @@"cLDesc5": "You will now receive an opt-out notification for all the birthdays your have saved on Ente, along with a collection of their best photos.","cLTitle6": "Resumable Uploads and Downloads","cLDesc6": "No more waiting for uploads/downloads to complete before you can close the app. All uploads and downloads now have the ability to be paused midway, and resume from where you left off.",- "indexingPausedStatusDescription": "Indexing is paused. It will automatically resume when the device is ready. The device is considered ready when its battery level, battery health, and thermal status are within a healthy range."+ "indexingPausedStatusDescription": "Indexing is paused. It will automatically resume when the device is ready. The device is considered ready when its battery level, battery health, and thermal status are within a healthy range.",+ "thisWeek": "This week",+ "thisMonth": "This month",+ "thisYear": "This year",+ "groupBy": "Group by"}diff --git a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dartindex 4cbb43182d..23627f6679 100644--- a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart+++ b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart@@ -14,6 +14,8 @@ import "package:photos/ui/components/menu_item_widget/menu_item_widget.dart";import "package:photos/ui/components/title_bar_title_widget.dart";import "package:photos/ui/components/title_bar_widget.dart";import "package:photos/ui/components/toggle_switch_widget.dart";+import "package:photos/ui/viewer/gallery/component/group/type.dart";+import "package:photos/ui/viewer/gallery/gallery_group_type_picker_page.dart";import "package:photos/ui/viewer/gallery/photo_grid_size_picker_page.dart";import "package:photos/utils/navigation_util.dart";@@ -26,11 +28,13 @@ class GallerySettingsScreen extends StatefulWidget {class _GallerySettingsScreenState extends State<GallerySettingsScreen> {late int _photoGridSize;+ late String _groupType;@overridevoid initState() {super.initState();_photoGridSize = localSettings.getPhotoGridSize();+ _groupType = localSettings.getGalleryGroupType().name;}@override@@ -94,6 +98,36 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {const SizedBox(height: 24,),+ GestureDetector(+ onTap: () {+ routeToPage(+ context,+ const GalleryGroupTypePickerPage(),+ ).then((value) {+ setState(() {+ _groupType =+ localSettings.getGalleryGroupType().name;+ });+ });+ },+ child: MenuItemWidget(+ captionedTextWidget: CaptionedTextWidget(+ title: S.of(context).groupBy,+ subTitle: _groupType,+ ),+ menuItemColor: colorScheme.fillFaint,+ trailingWidget: Icon(+ Icons.chevron_right_outlined,+ color: colorScheme.strokeBase,+ ),+ singleBorderRadius: 8,+ alignCaptionedTextToLeft: true,+ isGestureDetectorDisabled: true,+ ),+ ),+ const SizedBox(+ height: 24,+ ),MenuItemWidget(captionedTextWidget: CaptionedTextWidget(title: S.of(context).showMemories,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 e08f724962..bb15519f81 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@@ -70,7 +70,10 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {alignment: Alignment.centerLeft,child: Text(widget.title,- style: (widget.title == S.of(context).dayToday)+ style: (widget.title == S.of(context).dayToday ||+ widget.title == S.of(context).thisWeek ||+ widget.title == S.of(context).thisMonth ||+ widget.title == S.of(context).thisYear)? textStyle: textStyle.copyWith(color: colorScheme.textMuted),maxLines: 1,diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/type.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/type.dartindex 26373b6102..7505677ee6 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/type.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/type.dart@@ -18,17 +18,17 @@ extension GroupTypeExtension on GroupType {String get name {switch (this) {case GroupType.day:- return "day";+ return "Day";case GroupType.week:- return "week";+ return "Week";case GroupType.month:- return "month";+ return "Month";case GroupType.size:- return "size";+ return "Size";case GroupType.year:- return "year";+ return "Year";case GroupType.none:- return "none";+ return "None";}}@@ -50,19 +50,11 @@ extension GroupTypeExtension on GroupType {if (this == GroupType.day) {return _getDayTitle(context, file.creationTime!);} else if (this == GroupType.week) {- // return weeks starting date to end date based on file- final date = DateTime.fromMicrosecondsSinceEpoch(file.creationTime!);- final startOfWeek = date.subtract(Duration(days: date.weekday - 1));- final endOfWeek = startOfWeek.add(const Duration(days: 6));- return "${DateFormat.MMMd(Localizations.localeOf(context).languageCode).format(startOfWeek)} - ${DateFormat.MMMd(Localizations.localeOf(context).languageCode).format(endOfWeek)}, ${endOfWeek.year}";+ return _getWeekTitle(context, file.creationTime!);} else if (this == GroupType.year) {- final date = DateTime.fromMicrosecondsSinceEpoch(file.creationTime!);- return DateFormat.y(Localizations.localeOf(context).languageCode)- .format(date);+ return _getYearTitle(context, file.creationTime!);} else if (this == GroupType.month) {- final date = DateTime.fromMicrosecondsSinceEpoch(file.creationTime!);- return DateFormat.yMMM(Localizations.localeOf(context).languageCode)- .format(date);+ return _getMonthTitle(context, file.creationTime!);} else {throw UnimplementedError("getTitle not implemented for $this");}@@ -195,4 +187,47 @@ extension GroupTypeExtension on GroupType {.format(date);}}++ String _getWeekTitle(BuildContext context, int timestamp) {+ final date = DateTime.fromMicrosecondsSinceEpoch(timestamp);+ final now = DateTime.now();++ // Check if it's the current week+ final startOfWeek = date.subtract(Duration(days: date.weekday - 1));+ final nowStartOfWeek = now.subtract(Duration(days: now.weekday - 1));++ if (startOfWeek.year == nowStartOfWeek.year &&+ startOfWeek.month == nowStartOfWeek.month &&+ startOfWeek.day == nowStartOfWeek.day) {+ return "This week";+ }++ // Return formatted week range+ final endOfWeek = startOfWeek.add(const Duration(days: 6));+ return "${DateFormat.MMMd(Localizations.localeOf(context).languageCode).format(startOfWeek)} - ${DateFormat.MMMd(Localizations.localeOf(context).languageCode).format(endOfWeek)}, ${endOfWeek.year}";+ }++ String _getMonthTitle(BuildContext context, int timestamp) {+ final date = DateTime.fromMicrosecondsSinceEpoch(timestamp);+ final now = DateTime.now();++ if (date.year == now.year && date.month == now.month) {+ return "This month";+ }++ return DateFormat.yMMM(Localizations.localeOf(context).languageCode)+ .format(date);+ }++ String _getYearTitle(BuildContext context, int timestamp) {+ final date = DateTime.fromMicrosecondsSinceEpoch(timestamp);+ final now = DateTime.now();++ if (date.year == now.year) {+ return "This year";+ }++ return DateFormat.y(Localizations.localeOf(context).languageCode)+ .format(date);+ }}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dartindex 2389bbfd36..915cbead16 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart@@ -76,7 +76,9 @@ class Gallery extends StatefulWidget {// add a Function variable to get sort value in boolfinal SortAscFn? sortAsyncFn;- final GroupType groupType;++ /// Pass value to override default group type.+ final GroupType? groupType;final bool disablePinnedGroupHeader;final bool disableVerticalPaddingForScrollbar;@@ -92,7 +94,7 @@ class Gallery extends StatefulWidget {this.footer = const SizedBox(height: 212),this.emptyState = const EmptyState(),this.albumName = '',- this.groupType = GroupType.day,+ this.groupType,this.enableFileGrouping = true,this.loadingWidget = const EnteLoadingWidget(),this.disableScroll = false,@@ -210,6 +212,7 @@ class GalleryState extends State<Gallery> {_logger.info("Force refresh all files on ${event.reason}");_sortOrderAsc =widget.sortAsyncFn != null ? widget.sortAsyncFn!() : false;+ _setGroupType();final result = await _loadFiles();_setFilesAndReload(result.files);});@@ -290,7 +293,13 @@ class GalleryState extends State<Gallery> {}void _setGroupType() {- _groupType = widget.enableFileGrouping ? widget.groupType : GroupType.none;+ if (!widget.enableFileGrouping) {+ _groupType = GroupType.none;+ } else if (widget.groupType != null) {+ _groupType = widget.groupType!;+ } else {+ _groupType = localSettings.getGalleryGroupType();+ }}void _setFilesAndReload(List<EnteFile> files) {@@ -667,7 +676,7 @@ class GalleryState extends State<Gallery> {final List<List<EnteFile>> resultGroupedFiles = [];for (int index = 0; index < files.length; index++) {if (index > 0 &&- !widget.groupType.areFromSameGroup(files[index - 1], files[index])) {+ !_groupType.areFromSameGroup(files[index - 1], files[index])) {resultGroupedFiles.add(dailyFiles);dailyFiles = [];}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_group_type_picker_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_group_type_picker_page.dartnew file mode 100644index 0000000000..76ef5835fb--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_group_type_picker_page.dart@@ -0,0 +1,138 @@+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/generated/l10n.dart";+import "package:photos/service_locator.dart";+import 'package:photos/theme/ente_theme.dart';+import "package:photos/ui/components/buttons/icon_button_widget.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/components/title_bar_title_widget.dart';+import 'package:photos/ui/components/title_bar_widget.dart';+import 'package:photos/ui/viewer/gallery/component/group/type.dart';+import 'package:photos/utils/separators_util.dart';++class GalleryGroupTypePickerPage extends StatelessWidget {+ const GalleryGroupTypePickerPage({super.key});++ @override+ Widget build(BuildContext context) {+ return Scaffold(+ body: CustomScrollView(+ primary: false,+ slivers: <Widget>[+ TitleBarWidget(+ flexibleSpaceTitle: TitleBarTitleWidget(+ title: S.of(context).groupBy,+ ),+ actionIcons: [+ IconButtonWidget(+ icon: Icons.close_outlined,+ iconButtonType: IconButtonType.secondary,+ onTap: () {+ Navigator.pop(context);+ Navigator.pop(context);+ Navigator.pop(context);+ Navigator.pop(context);+ },+ ),+ ],+ ),+ SliverList(+ delegate: SliverChildBuilderDelegate(+ (context, index) {+ return const Padding(+ padding: EdgeInsets.symmetric(+ horizontal: 16,+ vertical: 20,+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ ClipRRect(+ borderRadius: BorderRadius.all(Radius.circular(8)),+ child: ItemsWidget(),+ ),+ ],+ ),+ );+ },+ childCount: 1,+ ),+ ),+ const SliverPadding(padding: EdgeInsets.symmetric(vertical: 12)),+ ],+ ),+ );+ }+}++class ItemsWidget extends StatefulWidget {+ const ItemsWidget({super.key});++ @override+ State<ItemsWidget> createState() => _ItemsWidgetState();+}++class _ItemsWidgetState extends State<ItemsWidget> {+ late GroupType currentGroupType;+ List<Widget> items = [];+ final groupTypes = GroupType.values+ .where(+ (type) => type != GroupType.size && type != GroupType.none,+ )+ .toList();++ @override+ void initState() {+ currentGroupType = localSettings.getGalleryGroupType();+ super.initState();+ }++ @override+ Widget build(BuildContext context) {+ items.clear();+ for (final groupType in groupTypes) {+ items.add(+ _menuItemForPicker(groupType),+ );+ }+ items = addSeparators(+ items,+ DividerWidget(+ dividerType: DividerType.menuNoIcon,+ bgColor: getEnteColorScheme(context).fillFaint,+ ),+ );+ return Column(+ mainAxisSize: MainAxisSize.min,+ children: items,+ );+ }++ Widget _menuItemForPicker(GroupType groupType) {+ return MenuItemWidget(+ key: ValueKey(groupType.name),+ menuItemColor: getEnteColorScheme(context).fillFaint,+ captionedTextWidget: CaptionedTextWidget(+ title: groupType.name,+ ),+ trailingIcon: currentGroupType == groupType ? Icons.check : null,+ alignCaptionedTextToLeft: true,+ isTopBorderRadiusRemoved: true,+ isBottomBorderRadiusRemoved: true,+ showOnlyLoadingState: true,+ onTap: () async {+ await localSettings.setGalleryGroupType(groupType).then(+ (value) => setState(() {+ currentGroupType = groupType;+ }),+ );+ Bus.instance.fire(+ ForceReloadHomeGalleryEvent("group type changed"),+ );+ },+ );+ }+}diff --git a/mobile/apps/photos/lib/utils/local_settings.dart b/mobile/apps/photos/lib/utils/local_settings.dartindex 4133bf0087..72d9a789dd 100644--- a/mobile/apps/photos/lib/utils/local_settings.dart+++ b/mobile/apps/photos/lib/utils/local_settings.dart@@ -1,4 +1,5 @@import 'package:photos/core/constants.dart';+import 'package:photos/ui/viewer/gallery/component/group/type.dart';import "package:photos/utils/ram_check_util.dart";import 'package:shared_preferences/shared_preferences.dart';@@ -20,6 +21,7 @@ enum AlbumViewType {class LocalSettings {static const kCollectionSortPref = "collection_sort_pref";+ static const kGalleryGroupType = "gallery_group_type";static const kPhotoGridSize = "photo_grid_size";static const _kisMLLocalIndexingEnabled = "ls.ml_local_indexing";static const _kHasSeenMLEnablingBanner = "ls.has_seen_ml_enabling_banner";@@ -70,6 +72,21 @@ class LocalSettings {return _prefs.setInt(kCollectionSortDirection, direction.index);}+ GroupType getGalleryGroupType() {+ final groupTypeString = _prefs.getString(kGalleryGroupType);+ if (groupTypeString != null) {+ return GroupType.values.firstWhere(+ (type) => type.toString() == groupTypeString,+ orElse: () => GroupType.values[0],+ );+ }+ return GroupType.values[0];+ }++ Future<void> setGalleryGroupType(GroupType groupType) async {+ await _prefs.setString(kGalleryGroupType, groupType.toString());+ }+int getPhotoGridSize() {if (_prefs.containsKey(kPhotoGridSize)) {return _prefs.getInt(kPhotoGridSize)!;