Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Refine gallery layout controls

ashil-pilotf125b80e6921
diff --git a/mobile/apps/photos/lib/core/constants.dart b/mobile/apps/photos/lib/core/constants.dart
index d523d2429a..abdcc396b2 100644
--- a/mobile/apps/photos/lib/core/constants.dart
+++ b/mobile/apps/photos/lib/core/constants.dart
@@ -19,8 +19,8 @@ const int galleryLoadStartTime = -8000000000000000; // June 28, 1716
const int galleryLoadEndTime = 9223372036854775807; // 2^63 - 1
const int batchSize = 1000;
const int batchSizeCopy = 100;
-const photoGridSizeDefault = 4;
-const photoGridSizeMin = 2;
+const photoGridSizeDefault = 3;
+const photoGridSizeMin = 3;
const photoGridSizeMax = 6;
const subGalleryMultiplier = 10;
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dart
index 8ebfe04e6f..91c2a9ec7c 100644
--- a/mobile/apps/photos/lib/main.dart
+++ b/mobile/apps/photos/lib/main.dart
@@ -323,6 +323,7 @@ Future<void> _runMinimally(
NetworkClient.instance.downloadDio,
packageInfo,
);
+ await localSettings.migrateGalleryLayoutPreferences();
MLDataDB.initialize(
preferRust: flagService.rustMlDb || localSettings.rustMlDbOverride,
);
@@ -494,6 +495,7 @@ Future<void> _init(
packageInfo,
);
+ await localSettings.migrateGalleryLayoutPreferences();
MLDataDB.initialize(
preferRust: flagService.rustMlDb || localSettings.rustMlDbOverride,
);
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
index 07b82c484d..78230c30fb 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
@@ -1,5 +1,4 @@
import "dart:core";
-import "dart:math" as math;
import "package:flutter/material.dart";
import "package:logging/logging.dart";
@@ -9,12 +8,9 @@ import "package:photos/models/file/dummy_file.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/gallery/fixed_extent_grid_row.dart";
import "package:photos/models/gallery/fixed_extent_section_layout.dart";
-import "package:photos/models/gallery/flex_layout.dart";
import "package:photos/models/gallery/gallery_layout_config.dart";
import "package:photos/models/gallery/justified_grid_row.dart";
import "package:photos/models/gallery/justified_layout.dart";
-import "package:photos/models/gallery/justified_layout_strategy.dart";
-import "package:photos/models/gallery/justified_layout_tuning.dart";
import "package:photos/models/gallery/section_layout.dart";
import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart";
@@ -67,10 +63,6 @@ class GalleryGroups {
}
}
- // Product decision: limit how tall the preferred justified row can grow as
- // the gallery widens.
- static const double _maximumJustifiedTargetRowHeight = 320.0;
-
late final int crossAxisCount;
late final GalleryLayoutType layoutType;
late final List<SectionLayout> _groupLayouts;
@@ -271,11 +263,13 @@ class GalleryGroups {
}
void init() {
- crossAxisCount = localSettings.getPhotoGridSize();
layoutType = resolveGalleryLayoutType(
layoutTypeOverride ?? localSettings.getGalleryLayoutType(),
justifiedLayoutAvailable: justifiedLayoutAvailable,
);
+ crossAxisCount = layoutType == GalleryLayoutType.justified
+ ? 2
+ : localSettings.getPhotoGridSize();
_buildGroups();
_groupLayouts = switch (layoutType) {
@@ -450,24 +444,6 @@ class GalleryGroups {
List<SectionLayout> _computeJustifiedGroupLayouts() {
final stopwatch = Stopwatch()..start();
- final strategy = localSettings.getJustifiedLayoutStrategy();
- final flexTuning = strategy == JustifiedLayoutStrategy.flex
- ? localSettings.getFlexLayoutTuning()
- : FlexLayoutTuning.defaults;
- final comfortLargeTuning = strategy == JustifiedLayoutStrategy.comfortLarge
- ? localSettings.getComfortLargeLayoutTuning()
- : ComfortLargeLayoutTuning.defaults;
- final gridTargetRowHeight =
- (widthAvailable - (crossAxisCount - 1) * spacing) / crossAxisCount;
- final baseTargetRowHeight = gridTargetRowHeight.isFinite
- ? math.min(gridTargetRowHeight, _maximumJustifiedTargetRowHeight)
- : gridTargetRowHeight;
- final targetHeightScale = switch (strategy) {
- JustifiedLayoutStrategy.comfortLarge =>
- comfortLargeTuning.targetHeightScale,
- JustifiedLayoutStrategy.flex => flexTuning.targetHeightScale,
- };
- final targetRowHeight = baseTargetRowHeight * targetHeightScale;
final groupLayouts = <SectionLayout>[];
var currentIndex = 0;
var currentOffset = 0.0;
@@ -480,29 +456,11 @@ class GalleryGroups {
file.height,
),
);
- final rows = switch (strategy) {
- JustifiedLayoutStrategy.comfortLarge =>
- JustifiedLayoutCalculator.computeRows(
- aspectRatios: aspectRatios,
- availableWidth: widthAvailable,
- targetRowHeight: targetRowHeight,
- spacing: spacing,
- maximumRowHeightFactor: comfortLargeTuning.maximumHeightFactor,
- wideFinalMaximumRowHeightFactor:
- comfortLargeTuning.wideFinalMaximumHeightFactor,
- minimumLandscapeRowHeightFactor:
- comfortLargeTuning.minimumLandscapeHeightFactor,
- ),
- JustifiedLayoutStrategy.flex => FlexLayoutCalculator.computeRows(
- aspectRatios: aspectRatios,
- availableWidth: widthAvailable,
- targetRowHeight: targetRowHeight,
- spacing: spacing,
- maximumRowHeightFactor: flexTuning.maximumHeightFactor,
- minimumNonFinalSingletonAspectRatio:
- flexTuning.minimumNonFinalSingletonAspectRatio,
- ),
- };
+ final rows = JustifiedLayoutCalculator.computePairedRows(
+ aspectRatios: aspectRatios,
+ availableWidth: widthAvailable,
+ spacing: spacing,
+ );
final firstIndex = currentIndex == 0 ? currentIndex : currentIndex + 1;
final lastIndex = firstIndex + rows.length;
final minOffset = currentOffset;
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_layout_config.dart b/mobile/apps/photos/lib/models/gallery/gallery_layout_config.dart
index ab96a7dfa2..706fe5b560 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_layout_config.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_layout_config.dart
@@ -1,9 +1,6 @@
-import "package:photos/service_locator.dart";
import "package:photos/settings/local_settings.dart";
-// FlagService treats debug builds as internal while still honoring the
-// developer setting that disables internal-user features.
-bool get isJustifiedLayoutAvailable => flagService.internalUser;
+const isJustifiedLayoutAvailable = true;
GalleryLayoutType resolveGalleryLayoutType(
GalleryLayoutType preferredLayoutType, {
diff --git a/mobile/apps/photos/lib/models/gallery/justified_layout.dart b/mobile/apps/photos/lib/models/gallery/justified_layout.dart
index 009c11b095..c99872877f 100644
--- a/mobile/apps/photos/lib/models/gallery/justified_layout.dart
+++ b/mobile/apps/photos/lib/models/gallery/justified_layout.dart
@@ -111,6 +111,50 @@ class JustifiedLayoutCalculator {
const JustifiedLayoutCalculator._();
+ static List<JustifiedRowLayout> computePairedRows({
+ required Iterable<double> aspectRatios,
+ required double availableWidth,
+ required double spacing,
+ }) {
+ if (!availableWidth.isFinite || availableWidth <= 0) {
+ throw ArgumentError.value(availableWidth, "availableWidth");
+ }
+ if (!spacing.isFinite || spacing < 0 || spacing >= availableWidth) {
+ throw ArgumentError.value(spacing, "spacing");
+ }
+ final ratios = aspectRatios
+ .map((ratio) {
+ return ratio.isFinite && ratio > 0
+ ? ratio.clamp(_minimumAspectRatio, _maximumAspectRatio).toDouble()
+ : 1.0;
+ })
+ .toList(growable: false);
+ final rows = <JustifiedRowLayout>[];
+ var offset = 0.0;
+ for (var firstIndex = 0; firstIndex < ratios.length; firstIndex += 2) {
+ final lastIndex = math.min(firstIndex + 1, ratios.length - 1);
+ final rowRatios = ratios.sublist(firstIndex, lastIndex + 1);
+ final contentWidth = availableWidth - (rowRatios.length - 1) * spacing;
+ final ratioSum = rowRatios.fold(0.0, (sum, ratio) => sum + ratio);
+ final height = rowRatios.length == 1
+ ? math.min(contentWidth / ratioSum, availableWidth / 2)
+ : contentWidth / ratioSum;
+ rows.add(
+ JustifiedRowLayout(
+ firstIndex: firstIndex,
+ lastIndex: lastIndex,
+ minOffset: offset,
+ height: height,
+ itemWidths: rowRatios
+ .map((ratio) => ratio * height)
+ .toList(growable: false),
+ ),
+ );
+ offset += height + spacing;
+ }
+ return rows;
+ }
+
static double aspectRatioForDimensions(int width, int height) {
if (width <= 0 || height <= 0) return 1;
return (width / height)
diff --git a/mobile/apps/photos/lib/settings/local_settings.dart b/mobile/apps/photos/lib/settings/local_settings.dart
index ce56ac9848..bd3403a723 100644
--- a/mobile/apps/photos/lib/settings/local_settings.dart
+++ b/mobile/apps/photos/lib/settings/local_settings.dart
@@ -2,6 +2,7 @@ import "dart:io";
import 'package:home_widget/home_widget.dart' as hw;
import 'package:photos/app_mode.dart';
+import 'package:photos/core/configuration.dart';
import 'package:photos/core/constants.dart';
import 'package:photos/models/gallery/justified_layout_strategy.dart';
import 'package:photos/models/gallery/justified_layout_tuning.dart';
@@ -292,6 +293,9 @@ class LocalSettings {
}
GalleryLayoutType getGalleryLayoutType() {
+ if (_prefs.getInt(kPhotoGridSize) == 2) {
+ return GalleryLayoutType.justified;
+ }
return switch (_prefs.getString(kGalleryLayoutType)) {
"justified" => GalleryLayoutType.justified,
_ => GalleryLayoutType.grid,
@@ -299,9 +303,28 @@ class LocalSettings {
}
Future<void> setGalleryLayoutType(GalleryLayoutType layoutType) async {
+ await migrateGalleryLayoutPreferences();
await _prefs.setString(kGalleryLayoutType, layoutType.name);
}
+ Future<void> migrateGalleryLayoutPreferences() async {
+ const migrationKey = "gallery_layout_controls_migrated";
+ if (_prefs.getBool(migrationKey) == true) return;
+ if (_prefs.getInt(kPhotoGridSize) == 2) {
+ await _prefs.setString(
+ kGalleryLayoutType,
+ GalleryLayoutType.justified.name,
+ );
+ await _prefs.setInt(kPhotoGridSize, photoGridSizeDefault);
+ } else if (!_prefs.containsKey(kPhotoGridSize) &&
+ (isAppModeSet ||
+ _prefs.containsKey(Configuration.userIDKey) ||
+ _prefs.containsKey(kGalleryGroupType))) {
+ await _prefs.setInt(kPhotoGridSize, 4);
+ }
+ await _prefs.setBool(migrationKey, true);
+ }
+
JustifiedLayoutStrategy getJustifiedLayoutStrategy() {
return switch (_prefs.getString(kJustifiedLayoutStrategy)) {
"flex" ||
@@ -444,14 +467,20 @@ class LocalSettings {
}
int getPhotoGridSize() {
- if (_prefs.containsKey(kPhotoGridSize)) {
- return _prefs.getInt(kPhotoGridSize)!;
- } else {
- return photoGridSizeDefault;
- }
+ final storedSize = _prefs.getInt(kPhotoGridSize);
+ if (storedSize == null || storedSize == 2) return photoGridSizeDefault;
+ return storedSize.clamp(photoGridSizeMin, photoGridSizeMax);
}
Future<void> setPhotoGridSize(int value) async {
+ if (value < photoGridSizeMin || value > photoGridSizeMax) {
+ throw ArgumentError.value(
+ value,
+ "value",
+ "Grid supports 3–6 photos per row",
+ );
+ }
+ await migrateGalleryLayoutPreferences();
await _prefs.setInt(kPhotoGridSize, value);
}
diff --git a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart
index 9b5862251a..f5066809a2 100644
--- a/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/gallery_settings_screen.dart
@@ -1,105 +1,38 @@
import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
-import "package:photos/core/constants.dart";
import "package:photos/core/event_bus.dart";
-import "package:photos/events/gallery_layout_changed_event.dart";
import "package:photos/events/hide_shared_items_from_home_gallery_event.dart";
-import "package:photos/models/gallery/gallery_layout_config.dart";
-import "package:photos/models/gallery/justified_layout_strategy.dart";
import "package:photos/service_locator.dart";
-import "package:photos/settings/local_settings.dart";
-import "package:photos/ui/settings/justified_layout_tuning_screen.dart";
-import "package:photos/ui/viewer/gallery/component/group/type.dart";
-import "package:photos/ui/viewer/gallery/justified_layout_strategy_label.dart";
+import "package:photos/ui/viewer/gallery/gallery_layout_controls.dart";
-class GallerySettingsScreen extends StatefulWidget {
+class GallerySettingsScreen extends StatelessWidget {
final bool fromGalleryLayoutSettingsCTA;
const GallerySettingsScreen({
super.key,
required this.fromGalleryLayoutSettingsCTA,
});
- @override
- State<GallerySettingsScreen> createState() => _GallerySettingsScreenState();
-}
-
-class _GallerySettingsScreenState extends State<GallerySettingsScreen> {
- late GalleryLayoutType _layoutType;
- late JustifiedLayoutStrategy _justifiedStrategy;
- late int _photoGridSize;
- late GroupType _groupType;
-
- @override
- void initState() {
- super.initState();
- _layoutType = resolveGalleryLayoutType(
- localSettings.getGalleryLayoutType(),
- );
- _photoGridSize = localSettings.getPhotoGridSize();
- _justifiedStrategy = localSettings.getJustifiedLayoutStrategy();
- _groupType = localSettings.getGalleryGroupType();
- }
-
@override
Widget build(BuildContext context) {
- final l10n = context.strings;
-
return SettingsPageScaffold(
- title: l10n.gallery,
+ title: context.strings.gallery,
children: [
- if (isJustifiedLayoutAvailable) ...[
- SettingsItem(
- title: "${l10n.layout} (i)",
- trailing: _trailingLabel(
- context,
- _layoutTypeLabel(context, _layoutType, _justifiedStrategy),
- ),
- onTap: () async => _showLayoutTypeSheet(context),
- ),
- const SizedBox(height: 8),
- SettingsItem(
- title: "Justified layout tuning (i)",
- onTap: () async {
- await Navigator.of(context).push(
- MaterialPageRoute<void>(
- builder: (_) => const JustifiedLayoutTuningScreen(),
- ),
- );
- },
- ),
- const SizedBox(height: 8),
- ],
- SettingsItem(
- title: l10n.photoGridSize,
- trailing: _trailingLabel(context, _photoGridSize.toString()),
- onTap: () async => _showPhotoGridSizeSheet(context),
- ),
- const SizedBox(height: 8),
- SettingsItem(
- title: l10n.groupBy,
- trailing: _trailingLabel(
- context,
- _groupType.getLocalizedName(context),
- ),
- onTap: () async => _showGroupTypeSheet(context),
- ),
- if (!widget.fromGalleryLayoutSettingsCTA && !isLocalGalleryMode) ...[
+ const GalleryLayoutControls(showHeading: true),
+ if (!fromGalleryLayoutSettingsCTA && !isLocalGalleryMode) ...[
const SizedBox(height: 8),
SettingsItem(
- title: l10n.hideSharedItemsFromHomeGallery,
+ title: context.strings.hideSharedItemsFromHomeGallery,
showChevron: false,
trailing: ToggleSwitchComponent.async(
value: () => localSettings.hideSharedItemsFromHomeGallery,
onChanged: () async {
- final prevSetting =
- localSettings.hideSharedItemsFromHomeGallery;
+ final nextValue = !localSettings.hideSharedItemsFromHomeGallery;
await localSettings.setHideSharedItemsFromHomeGallery(
- !prevSetting,
+ nextValue,
);
-
Bus.instance.fire(
- HideSharedItemsFromHomeGalleryEvent(!prevSetting),
+ HideSharedItemsFromHomeGalleryEvent(nextValue),
);
},
),
@@ -108,187 +41,4 @@ class _GallerySettingsScreenState extends State<GallerySettingsScreen> {
],
);
}
-
- Widget _trailingLabel(BuildContext context, String label) {
- final colors = context.componentColors;
- return Text(
- label,
- style: TextStyles.mini.copyWith(color: colors.textLight),
- );
- }
-
- String _layoutTypeLabel(
- BuildContext context,
- GalleryLayoutType layoutType,
- JustifiedLayoutStrategy? strategy,
- ) {
- return switch (layoutType) {
- GalleryLayoutType.grid => context.strings.grid,
- GalleryLayoutType.justified => strategy!.label(context),
- };
- }
-
- Future<void> _showLayoutTypeSheet(BuildContext context) async {
- if (!isJustifiedLayoutAvailable) return;
- final l10n = context.strings;
- await showBottomSheetComponent<void>(
- context: context,
- builder: (sheetContext) => BottomSheetComponent(
- title: l10n.layout,
- content: MenuGroupComponent(
- items: [
- for (final (layoutType, strategy) in [
- (GalleryLayoutType.grid, null),
- for (final strategy in JustifiedLayoutStrategy.values)
- (GalleryLayoutType.justified, strategy),
- ])
- MenuComponent(
- key: ValueKey((layoutType, strategy)),
- title: _layoutTypeLabel(sheetContext, layoutType, strategy),
- trailing:
- _layoutType == layoutType &&
- (strategy == null || _justifiedStrategy == strategy)
- ? Icon(
- Icons.check,
- color: sheetContext.componentColors.primary,
- )
- : null,
- onTap: () async {
- await _setLayoutType(layoutType, strategy);
- if (sheetContext.mounted) {
- Navigator.of(sheetContext).pop();
- }
- },
- ),
- ],
- ),
- ),
- );
- }
-
- Future<void> _setLayoutType(
- GalleryLayoutType layoutType,
- JustifiedLayoutStrategy? strategy,
- ) async {
- if (layoutType == GalleryLayoutType.justified &&
- !isJustifiedLayoutAvailable) {
- return;
- }
- final resetGridSize =
- strategy == JustifiedLayoutStrategy.flex &&
- localSettings.getPhotoGridSize() != 2;
- if (localSettings.getGalleryLayoutType() == layoutType &&
- (strategy == null ||
- localSettings.getJustifiedLayoutStrategy() == strategy) &&
- !resetGridSize) {
- return;
- }
- await Future.wait([
- localSettings.setGalleryLayoutType(layoutType),
- if (strategy != null) localSettings.setJustifiedLayoutStrategy(strategy),
- if (resetGridSize) localSettings.setPhotoGridSize(2),
- ]);
- if (mounted) {
- setState(() {
- _layoutType = layoutType;
- if (strategy != null) _justifiedStrategy = strategy;
- _photoGridSize = localSettings.getPhotoGridSize();
- });
- }
- Bus.instance.fire(GalleryLayoutChangedEvent());
- }
-
- Future<void> _showPhotoGridSizeSheet(BuildContext context) async {
- final l10n = context.strings;
- await showBottomSheetComponent<void>(
- context: context,
- builder: (sheetContext) => BottomSheetComponent(
- title: l10n.photoGridSize,
- content: MenuGroupComponent(
- items: [
- for (
- int gridSize = photoGridSizeMin;
- gridSize <= photoGridSizeMax;
- gridSize++
- )
- MenuComponent(
- key: ValueKey(gridSize),
- title: "$gridSize",
- trailing: _photoGridSize == gridSize
- ? Icon(
- Icons.check,
- color: sheetContext.componentColors.primary,
- )
- : null,
- onTap: () async {
- await _setPhotoGridSize(gridSize);
- if (sheetContext.mounted) {
- Navigator.of(sheetContext).pop();
- }
- },
- ),
- ],
- ),
- ),
- );
- }
-
- Future<void> _setPhotoGridSize(int gridSize) async {
- if (localSettings.getPhotoGridSize() == gridSize) return;
- await localSettings.setPhotoGridSize(gridSize);
- if (mounted) {
- setState(() {
- _photoGridSize = gridSize;
- });
- }
- Bus.instance.fire(GalleryLayoutChangedEvent());
- }
-
- Future<void> _showGroupTypeSheet(BuildContext context) async {
- final l10n = context.strings;
- await showBottomSheetComponent<void>(
- context: context,
- builder: (sheetContext) => BottomSheetComponent(
- title: l10n.groupBy,
- content: MenuGroupComponent(
- items: [
- for (final groupType in _groupTypes)
- MenuComponent(
- key: ValueKey(groupType),
- title: groupType.getLocalizedName(sheetContext),
- trailing: _groupType == groupType
- ? Icon(
- Icons.check,
- color: sheetContext.componentColors.primary,
- )
- : null,
- onTap: () async {
- await _setGroupType(groupType);
- if (sheetContext.mounted) {
- Navigator.of(sheetContext).pop();
- }
- },
- ),
- ],
- ),
- ),
- );
- }
-
- List<GroupType> get _groupTypes {
- return GroupType.values
- .where((type) => type != GroupType.size && type != GroupType.none)
- .toList();
- }
-
- Future<void> _setGroupType(GroupType groupType) async {
- if (localSettings.getGalleryGroupType() == groupType) return;
- await localSettings.setGalleryGroupType(groupType);
- if (mounted) {
- setState(() {
- _groupType = groupType;
- });
- }
- Bus.instance.fire(GalleryLayoutChangedEvent());
- }
}
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
index a2f4a2ffa3..f6c01b7bb4 100644
--- a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
@@ -28,7 +28,7 @@ class SettingsSearchRegistry {
final hasLoggedIn = Configuration.instance.isLoggedIn();
final isLocalGallery = isLocalGalleryMode;
final showThemeControls = Platform.isAndroid || kDebugMode;
- final showJustifiedLayout = isJustifiedLayoutAvailable;
+ const showJustifiedLayout = isJustifiedLayoutAvailable;
final items = <SettingsSearchItem>[];
if (hasLoggedIn && !isLocalGallery) {
@@ -329,7 +329,7 @@ class SettingsSearchRegistry {
if (showJustifiedLayout) {
items.add(
SettingsSearchItem(
- title: "${l10n.layout} (i)",
+ title: l10n.layout,
subtitle: l10n.gallery,
sectionPath: "${l10n.appearance} > ${l10n.gallery}",
icon: HugeIcons.strokeRoundedDashboardSquare02,
@@ -343,7 +343,7 @@ class SettingsSearchRegistry {
items.add(
SettingsSearchItem(
- title: l10n.photoGridSize,
+ title: l10n.photosPerRow,
subtitle: l10n.gallery,
sectionPath: "${l10n.appearance} > ${l10n.gallery}",
icon: HugeIcons.strokeRoundedDashboardSquare02,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
index 9b077e2e23..0cd3a9c549 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
@@ -126,9 +126,7 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
widget.file.fileType == FileType.livePhoto;
final effectiveThumbnailSize =
widget.thumbnailSize ??
- (widget.photoGridSize < photoGridSizeDefault
- ? thumbnailLargeSize
- : thumbnailSmallSize);
+ (widget.photoGridSize <= 3 ? thumbnailLargeSize : thumbnailSmallSize);
final Widget thumbnailWidget = ThumbnailWidget(
widget.file,
diskLoadDeferDuration: galleryThumbnailDiskLoadDeferDuration,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 09ff137d78..db462cc2cd 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -31,6 +31,7 @@ import "package:photos/ui/viewer/gallery/component/sectioned_sliver_list.dart";
import 'package:photos/ui/viewer/gallery/empty_state.dart';
import "package:photos/ui/viewer/gallery/gallery_app_bar_config.dart";
import "package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart";
+import "package:photos/ui/viewer/gallery/layout_settings.dart";
import "package:photos/ui/viewer/gallery/scrollbar/custom_scroll_bar.dart";
import "package:photos/ui/viewer/gallery/state/boundary_reporter_mixin.dart";
import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
@@ -42,20 +43,20 @@ import "package:photos/ui/viewer/gallery/swipe_to_select_helper.dart";
import "package:photos/utils/hierarchical_search_util.dart";
import "package:photos/utils/widget_util.dart";
-typedef GalleryLoader =
- Future<FileLoadResult> Function(
- int creationStartTime,
- int creationEndTime, {
- int? limit,
- bool? asc,
- });
+typedef GalleryLoader = Future<FileLoadResult> Function(
+ int creationStartTime,
+ int creationEndTime, {
+ int? limit,
+ bool? asc,
+});
typedef _LayoutScrollAnchor = ({EnteFile file, bool inHeader, double progress});
typedef SortAscFn = bool Function();
-typedef NewLocalFilesResolver =
- Future<List<EnteFile>?> Function(LocalPhotosAddedEvent event);
+typedef NewLocalFilesResolver = Future<List<EnteFile>?> Function(
+ LocalPhotosAddedEvent event,
+);
class Gallery extends StatefulWidget {
final GalleryLoader asyncLoader;
@@ -182,6 +183,11 @@ class GalleryState extends State<Gallery> {
InheritedGalleryBoundaries? _boundariesProvider;
late String _automationScrollIdentifier;
+ bool get _showLayoutControls =>
+ widget.showGallerySettingsCTA &&
+ !widget.disableScroll &&
+ !widget.limitSelectionToOne;
+
@override
void initState() {
super.initState();
@@ -393,7 +399,7 @@ class GalleryState extends State<Gallery> {
groupHeaderExtent: groupHeaderExtent!,
showSelectAll: widget.showSelectAll,
limitSelectionToOne: widget.limitSelectionToOne,
- showGallerySettingsCTA: widget.showGallerySettingsCTA,
+ showGallerySettingsCTA: _showLayoutControls,
groupHeaderAction: widget.groupHeaderAction,
layoutTypeOverride: widget.layoutTypeOverride,
justifiedLayoutAvailable: isJustifiedLayoutAvailable,
@@ -479,12 +485,18 @@ class GalleryState extends State<Gallery> {
: 0;
}
+ int get _photoGridSize =>
+ (widget.layoutTypeOverride ?? localSettings.getGalleryLayoutType()) ==
+ GalleryLayoutType.justified
+ ? 2
+ : localSettings.getPhotoGridSize();
+
Future<double> _measureGroupHeaderExtent() async {
if (!_groupType.showGroupHeader()) return GalleryGroups.spacing;
final size = await getIntrinsicSizeOfWidget(
GroupHeaderWidget(
title: "Dummy title",
- gridSize: localSettings.getPhotoGridSize(),
+ gridSize: _photoGridSize,
filesInGroup: const [],
selectedFiles: null,
showSelectAll: false,
@@ -867,7 +879,7 @@ class GalleryState extends State<Gallery> {
final shouldEnableSwipeSelection = widget.limitSelectionToOne == false;
if (groupHeaderExtent == null) {
- final photoGridSize = localSettings.getPhotoGridSize();
+ final photoGridSize = _photoGridSize;
final tileHeight =
(widthAvailable - (photoGridSize - 1) * GalleryGroups.spacing) /
photoGridSize;
@@ -1069,11 +1081,13 @@ class GalleryState extends State<Gallery> {
widget.showSelectAll &&
!widget.limitSelectionToOne,
scrollbarInUseNotifier: scrollBarInUseNotifier,
- showGallerySettingsCTA:
- widget.showGallerySettingsCTA,
+ showGallerySettingsCTA: _showLayoutControls,
groupHeaderAction: widget.groupHeaderAction,
)
: const SizedBox.shrink(),
+ if (_showLayoutControls &&
+ !groups.groupType.showGroupHeader())
+ _FloatingLayoutControl(topInset: appBarPinnedHeight),
],
),
),
@@ -1111,6 +1125,21 @@ class _GalleryAppBarScrollBody extends StatelessWidget {
}
}
+class _FloatingLayoutControl extends StatelessWidget {
+ const _FloatingLayoutControl({this.topInset = 0});
+
+ final double topInset;
+
+ @override
+ Widget build(BuildContext context) {
+ return Positioned(
+ right: 16,
+ top: topInset + 16,
+ child: const FloatingGalleryLayoutButton(),
+ );
+ }
+}
+
class PinnedGroupHeader extends StatefulWidget {
final ScrollController scrollController;
final GalleryGroups galleryGroups;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_layout_controls.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_layout_controls.dart
new file mode 100644
index 0000000000..243ba3c220
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_layout_controls.dart
@@ -0,0 +1,385 @@
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:flutter/material.dart";
+import "package:flutter/rendering.dart";
+import "package:photos/core/constants.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/events/gallery_layout_changed_event.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/settings/local_settings.dart";
+import "package:photos/ui/viewer/gallery/component/group/type.dart";
+
+class GalleryLayoutControls extends StatefulWidget {
+ const GalleryLayoutControls({
+ super.key,
+ this.showHeading = false,
+ this.keepHeight = false,
+ });
+
+ final bool showHeading;
+ final bool keepHeight;
+
+ @override
+ State<GalleryLayoutControls> createState() => _GalleryLayoutControlsState();
+}
+
+class _GalleryLayoutControlsState extends State<GalleryLayoutControls> {
+ late GalleryLayoutType _layoutType;
+ late int _gridSize;
+ late GroupType _groupType;
+
+ @override
+ void initState() {
+ super.initState();
+ _layoutType = localSettings.getGalleryLayoutType();
+ _gridSize = localSettings.getPhotoGridSize();
+ _groupType = localSettings.getGalleryGroupType();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.strings;
+ final colors = context.componentColors;
+ final density = MenuGroupComponent(
+ items: [
+ MenuComponent(
+ title: l10n.photosPerRow,
+ trailing: DecoratedBox(
+ decoration: BoxDecoration(
+ border: Border.all(color: colors.strokeFaint),
+ borderRadius: BorderRadius.circular(Radii.md),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ IconButtonComponent(
+ key: const ValueKey("fewer-photos-per-row"),
+ icon: const Icon(Icons.remove),
+ size: 44,
+ iconSize: 20,
+ tooltip: _gridSize > photoGridSizeMin
+ ? "${l10n.photosPerRow}: ${_gridSize - 1}"
+ : null,
+ shouldSurfaceExecutionStates: false,
+ onTap: _gridSize > photoGridSizeMin
+ ? () => _setGridSize(_gridSize - 1)
+ : null,
+ ),
+ SizedBox(
+ width: 28,
+ child: Center(
+ child: Text(
+ "$_gridSize",
+ style: TextStyles.bodyBold.copyWith(
+ color: colors.textBase,
+ ),
+ ),
+ ),
+ ),
+ IconButtonComponent(
+ key: const ValueKey("more-photos-per-row"),
+ icon: const Icon(Icons.add),
+ size: 44,
+ iconSize: 20,
+ tooltip: _gridSize < photoGridSizeMax
+ ? "${l10n.photosPerRow}: ${_gridSize + 1}"
+ : null,
+ shouldSurfaceExecutionStates: false,
+ onTap: _gridSize < photoGridSizeMax
+ ? () => _setGridSize(_gridSize + 1)
+ : null,
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ );
+ final grouping = MenuGroupComponent(
+ items: [
+ MenuComponent(
+ title: l10n.groupBy,
+ trailing: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ _groupType.getLocalizedName(context),
+ style: TextStyles.mini.copyWith(color: colors.textLight),
+ ),
+ const SizedBox(width: 8),
+ Icon(Icons.chevron_right, color: colors.textLighter, size: 20),
+ ],
+ ),
+ onTap: _showGrouping,
+ ),
+ ],
+ );
+ final collapsed = _layoutType == GalleryLayoutType.justified ? 1.0 : 0.0;
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ if (widget.showHeading)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 12),
+ child: Text(
+ l10n.layout,
+ style: TextStyles.body.copyWith(color: colors.textBase),
+ ),
+ ),
+ Row(
+ children: [
+ Expanded(child: _layoutCard(GalleryLayoutType.grid)),
+ const SizedBox(width: 8),
+ Expanded(child: _layoutCard(GalleryLayoutType.justified)),
+ ],
+ ),
+ if (widget.keepHeight)
+ TweenAnimationBuilder<double>(
+ tween: Tween(begin: collapsed, end: collapsed),
+ duration: MediaQuery.disableAnimationsOf(context)
+ ? Duration.zero
+ : const Duration(milliseconds: 240),
+ curve: Curves.easeOutCubic,
+ builder: (context, progress, _) => _FixedHeightLayoutRows(
+ collapseProgress: progress,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(top: 8),
+ child: ExcludeSemantics(
+ excluding: _layoutType == GalleryLayoutType.justified,
+ child: ExcludeFocus(
+ excluding: _layoutType == GalleryLayoutType.justified,
+ child: IgnorePointer(
+ ignoring: _layoutType == GalleryLayoutType.justified,
+ child: Opacity(opacity: 1 - progress, child: density),
+ ),
+ ),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(top: 8),
+ child: grouping,
+ ),
+ ],
+ ),
+ )
+ else ...[
+ if (_layoutType == GalleryLayoutType.grid) ...[
+ const SizedBox(height: 8),
+ density,
+ ],
+ const SizedBox(height: 8),
+ grouping,
+ ],
+ ],
+ );
+ }
+
+ Widget _layoutCard(GalleryLayoutType type) {
+ final colors = context.componentColors;
+ final selected = _layoutType == type;
+ final shape = RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(Radii.lg),
+ side: BorderSide(
+ color: selected ? colors.strokeDark : Colors.transparent,
+ ),
+ );
+ return Semantics(
+ key: ValueKey(type),
+ label: type == GalleryLayoutType.grid
+ ? context.strings.squarePhotos
+ : context.strings.photosInOriginalProportions,
+ button: true,
+ selected: selected,
+ onTap: () => _setLayout(type),
+ child: ExcludeSemantics(
+ child: Material(
+ color: colors.fillLight,
+ shape: shape,
+ clipBehavior: Clip.antiAlias,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _setLayout(type),
+ child: SizedBox(
+ height: 92,
+ child: Stack(
+ children: [
+ Center(
+ child: SizedBox.square(
+ dimension: 52,
+ child: CustomPaint(
+ painter: _GallerySamplePainter(
+ type,
+ colors.textLighter,
+ ),
+ ),
+ ),
+ ),
+ if (selected)
+ Positioned(
+ top: 8,
+ right: 8,
+ child: SizedBox.square(
+ dimension: 20,
+ child: Center(
+ child: Icon(
+ Icons.check,
+ color: colors.textBase,
+ size: 20,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ Future<void> _setLayout(GalleryLayoutType type) async {
+ if (_layoutType == type) return;
+ await localSettings.setGalleryLayoutType(type);
+ if (mounted) setState(() => _layoutType = type);
+ Bus.instance.fire(GalleryLayoutChangedEvent());
+ }
+
+ Future<void> _setGridSize(int size) async {
+ await localSettings.setPhotoGridSize(size);
+ if (mounted) setState(() => _gridSize = size);
+ Bus.instance.fire(GalleryLayoutChangedEvent());
+ }
+
+ Future<void> _showGrouping() async {
+ await showBottomSheetComponent<void>(
+ context: context,
+ builder: (sheetContext) => BottomSheetComponent(
+ title: sheetContext.strings.groupBy,
+ content: MenuGroupComponent(
+ items: [
+ for (final type in GroupType.values.where(
+ (type) => type != GroupType.size && type != GroupType.none,
+ ))
+ MenuComponent(
+ title: type.getLocalizedName(sheetContext),
+ trailing: _groupType == type
+ ? Icon(
+ Icons.check,
+ color: sheetContext.componentColors.textBase,
+ )
+ : null,
+ onTap: () async {
+ if (_groupType != type) {
+ await localSettings.setGalleryGroupType(type);
+ if (mounted) setState(() => _groupType = type);
+ Bus.instance.fire(GalleryLayoutChangedEvent());
+ }
+ if (sheetContext.mounted) Navigator.of(sheetContext).pop();
+ },
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _FixedHeightLayoutRows extends MultiChildRenderObjectWidget {
+ const _FixedHeightLayoutRows({
+ required this.collapseProgress,
+ required super.children,
+ });
+
+ final double collapseProgress;
+
+ @override
+ RenderObject createRenderObject(BuildContext context) =>
+ _RenderFixedHeightLayoutRows(
+ collapseProgress: collapseProgress,
+ textDirection: Directionality.of(context),
+ );
+
+ @override
+ void updateRenderObject(
+ BuildContext context,
+ _RenderFixedHeightLayoutRows renderObject,
+ ) {
+ renderObject
+ ..collapseProgress = collapseProgress
+ ..textDirection = Directionality.of(context);
+ }
+}
+
+class _RenderFixedHeightLayoutRows extends RenderFlex {
+ _RenderFixedHeightLayoutRows({
+ required double collapseProgress,
+ required super.textDirection,
+ }) : _collapseProgress = collapseProgress,
+ super(
+ direction: Axis.vertical,
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ );
+
+ double _collapseProgress;
+
+ set collapseProgress(double value) {
+ if (_collapseProgress == value) return;
+ _collapseProgress = value;
+ markNeedsLayout();
+ }
+
+ @override
+ void performLayout() {
+ super.performLayout();
+ final density = firstChild;
+ if (density == null) return;
+ final grouping = childAfter(density);
+ if (grouping == null) return;
+ final parentData = grouping.parentData! as FlexParentData;
+ parentData.offset -= Offset(0, density.size.height * _collapseProgress);
+ }
+}
+
+class _GallerySamplePainter extends CustomPainter {
+ const _GallerySamplePainter(this.type, this.color);
+
+ final GalleryLayoutType type;
+ final Color color;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final paint = Paint()
+ ..color = color
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 1.5;
+ final rect = (Offset.zero & size).deflate(0.75);
+ final outline = RRect.fromRectAndRadius(rect, const Radius.circular(4));
+ canvas.save();
+ canvas.clipRRect(outline);
+ if (type == GalleryLayoutType.grid) {
+ for (var index = 1; index < 3; index++) {
+ final x = rect.left + rect.width * index / 3;
+ final y = rect.top + rect.height * index / 3;
+ canvas.drawLine(Offset(x, rect.top), Offset(x, rect.bottom), paint);
+ canvas.drawLine(Offset(rect.left, y), Offset(rect.right, y), paint);
+ }
+ } else {
+ final y = rect.top + rect.height * 1.25 / 2.25;
+ final topX = rect.left + rect.width * 1.6 / 2.6;
+ final bottomX = rect.left + rect.width / 2.6;
+ canvas.drawLine(Offset(rect.left, y), Offset(rect.right, y), paint);
+ canvas.drawLine(Offset(topX, rect.top), Offset(topX, y), paint);
+ canvas.drawLine(Offset(bottomX, y), Offset(bottomX, rect.bottom), paint);
+ }
+ canvas.restore();
+ canvas.drawRRect(outline, paint);
+ }
+
+ @override
+ bool shouldRepaint(_GallerySamplePainter oldDelegate) =>
+ oldDelegate.type != type || oldDelegate.color != color;
+}
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
index 2b304705b2..53ac1f57c5 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/layout_settings.dart
@@ -1,160 +1,52 @@
-import "dart:async";
-
import "package:ente_components/ente_components.dart";
-import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:ente_strings/ente_strings.dart";
import "package:flutter/material.dart";
-import "package:photos/core/event_bus.dart";
-import "package:photos/events/gallery_layout_changed_event.dart";
-import "package:photos/models/gallery/gallery_layout_config.dart";
-import "package:photos/models/gallery/justified_layout_strategy.dart";
-import "package:photos/service_locator.dart";
-import "package:photos/settings/local_settings.dart";
-import "package:photos/ui/settings/gallery_settings_screen.dart";
-import "package:photos/ui/viewer/gallery/component/group/type.dart";
-import "package:photos/ui/viewer/gallery/justified_layout_strategy_label.dart";
+import "package:photos/ui/viewer/gallery/gallery_layout_controls.dart";
-class GalleryLayoutSettings extends StatefulWidget {
+class GalleryLayoutSettings extends StatelessWidget {
const GalleryLayoutSettings({super.key});
@override
- State<GalleryLayoutSettings> createState() => _GalleryLayoutSettingsState();
-}
-
-class _GalleryLayoutSettingsState extends State<GalleryLayoutSettings> {
- late bool isDayLayout;
- late bool isMonthLayout;
- late bool isJustifiedLayout;
- late JustifiedLayoutStrategy justifiedStrategy;
-
- @override
- void initState() {
- super.initState();
- _readLatestSetting();
- }
-
- void _readLatestSetting() {
- final layoutType = resolveGalleryLayoutType(
- localSettings.getGalleryLayoutType(),
+ Widget build(BuildContext context) {
+ return BottomSheetComponent(
+ title: context.strings.layout,
+ content: const GalleryLayoutControls(keepHeight: true),
);
- isDayLayout =
- layoutType == GalleryLayoutType.grid &&
- localSettings.getGalleryGroupType() == GroupType.day &&
- localSettings.getPhotoGridSize() == 3;
- isMonthLayout =
- layoutType == GalleryLayoutType.grid &&
- localSettings.getGalleryGroupType() == GroupType.month &&
- localSettings.getPhotoGridSize() == 5;
- isJustifiedLayout = layoutType == GalleryLayoutType.justified;
- justifiedStrategy = localSettings.getJustifiedLayoutStrategy();
}
+}
- void _reloadWithLatestSetting() {
- if (!mounted) return;
- setState(() {
- _readLatestSetting();
- });
- }
+class FloatingGalleryLayoutButton extends StatelessWidget {
+ const FloatingGalleryLayoutButton({super.key});
@override
Widget build(BuildContext context) {
- final colors = context.componentColors;
- return BottomSheetComponent(
- title: context.strings.layout,
- content: MenuGroupComponent(
- items: [
- MenuComponent(
- title: context.strings.day,
- leading: const Icon(Icons.grid_view_outlined),
- trailing: isDayLayout
- ? Icon(Icons.check, color: colors.primary)
- : null,
- showOnlyLoadingState: true,
- onTap: () => _applyLayout(GroupType.day, 3),
- ),
- MenuComponent(
- title: context.strings.month.capitalizeFirst(),
- leading: const Icon(Icons.grid_on_rounded),
- trailing: isMonthLayout
- ? Icon(Icons.check, color: colors.primary)
- : null,
- showOnlyLoadingState: true,
- onTap: () => _applyLayout(GroupType.month, 5),
- ),
- if (isJustifiedLayoutAvailable)
- for (final strategy in JustifiedLayoutStrategy.values)
- MenuComponent(
- key: ValueKey(strategy),
- title: strategy.label(context),
- leading: const Icon(Icons.view_quilt_outlined),
- trailing: isJustifiedLayout && justifiedStrategy == strategy
- ? Icon(Icons.check, color: colors.primary)
- : null,
- showOnlyLoadingState: true,
- onTap: () => _applyJustifiedLayout(strategy),
- ),
- MenuComponent(
- title: context.strings.custom,
- trailing: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- if (!isDayLayout && !isMonthLayout && !isJustifiedLayout) ...[
- Icon(Icons.check, color: colors.primary),
- const SizedBox(width: 8),
- ],
- const Icon(Icons.chevron_right_outlined),
- ],
+ return Semantics(
+ button: true,
+ label: context.strings.layout,
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ color: context.componentColors.fillLight,
+ shape: BoxShape.circle,
+ boxShadow: const [
+ BoxShadow(
+ color: Color(0x14000000),
+ blurRadius: 8,
+ offset: Offset(0, 2),
),
- onTap: () =>
- routeToPage(
- context,
- const GallerySettingsScreen(
- fromGalleryLayoutSettingsCTA: true,
- ),
- ).then((_) {
- _reloadWithLatestSetting();
- }),
+ ],
+ ),
+ child: IconButtonComponent(
+ icon: const Icon(Icons.more_vert_outlined),
+ variant: IconButtonComponentVariant.circular,
+ size: 48,
+ tooltip: context.strings.layout,
+ shouldSurfaceExecutionStates: false,
+ onTap: () => showBottomSheetComponent<void>(
+ context: context,
+ builder: (_) => const GalleryLayoutSettings(),
),
- ],
+ ),
),
);
}
-
- Future<void> _applyLayout(GroupType groupType, int gridSize) async {
- final alreadyApplied =
- localSettings.getGalleryLayoutType() == GalleryLayoutType.grid &&
- localSettings.getGalleryGroupType() == groupType &&
- localSettings.getPhotoGridSize() == gridSize;
- if (!alreadyApplied) {
- await Future.wait([
- localSettings.setGalleryLayoutType(GalleryLayoutType.grid),
- localSettings.setGalleryGroupType(groupType),
- localSettings.setPhotoGridSize(gridSize),
- ]);
- Bus.instance.fire(GalleryLayoutChangedEvent());
- }
-
- if (!mounted) return;
- Navigator.pop(context);
- }
-
- Future<void> _applyJustifiedLayout(JustifiedLayoutStrategy strategy) async {
- if (!isJustifiedLayoutAvailable) return;
- final resetGridSize =
- strategy == JustifiedLayoutStrategy.flex &&
- localSettings.getPhotoGridSize() != 2;
- if (localSettings.getGalleryLayoutType() != GalleryLayoutType.justified ||
- localSettings.getJustifiedLayoutStrategy() != strategy ||
- resetGridSize) {
- await Future.wait([
- localSettings.setGalleryLayoutType(GalleryLayoutType.justified),
- localSettings.setJustifiedLayoutStrategy(strategy),
- if (resetGridSize) localSettings.setPhotoGridSize(2),
- ]);
- Bus.instance.fire(GalleryLayoutChangedEvent());
- }
-
- if (!mounted) return;
- Navigator.pop(context);
- }
}
diff --git a/mobile/apps/photos/lib/ui/viewer/location/dynamic_location_gallery_widget.dart b/mobile/apps/photos/lib/ui/viewer/location/dynamic_location_gallery_widget.dart
index 8a3fa9f7cd..a573a5acce 100644
--- a/mobile/apps/photos/lib/ui/viewer/location/dynamic_location_gallery_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/location/dynamic_location_gallery_widget.dart
@@ -1,11 +1,14 @@
+import "dart:async";
import "dart:developer" as dev;
-import "dart:math";
import "package:flutter/material.dart";
import "package:photos/core/constants.dart";
+import "package:photos/core/event_bus.dart";
import "package:photos/db/files_db.dart";
+import "package:photos/events/gallery_layout_changed_event.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/file_load_result.dart";
+import "package:photos/models/gallery/justified_layout.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/services/filter/db_filters.dart";
@@ -32,7 +35,7 @@ class DynamicLocationGalleryWidget extends StatefulWidget {
class _DynamicLocationGalleryWidgetState
extends State<DynamicLocationGalleryWidget> {
late final Future<FileLoadResult> fileLoadResult;
- double heightOfGallery = 0;
+ late final StreamSubscription<GalleryLayoutChangedEvent> _layoutSubscription;
@override
void initState() {
@@ -50,9 +53,20 @@ class _DynamicLocationGalleryWidgetState
),
);
+ _layoutSubscription = Bus.instance.on<GalleryLayoutChangedEvent>().listen((
+ _,
+ ) {
+ if (mounted) setState(() {});
+ });
super.initState();
}
+ @override
+ void dispose() {
+ _layoutSubscription.cancel();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
const galleryFilesLimit = 1000;
@@ -88,10 +102,7 @@ class _DynamicLocationGalleryWidgetState
builder: (context, constrains) {
return SizedBox(
height: _galleryHeight(
- min(
- (widget.memoriesCountNotifier.value ?? 0),
- galleryFilesLimit,
- ),
+ (snapshot.data as FileLoadResult).files,
constrains.maxWidth,
),
child: GalleryFilesState(
@@ -109,7 +120,6 @@ class _DynamicLocationGalleryWidgetState
},
tagPrefix: widget.tagPrefix,
enableFileGrouping: false,
- layoutTypeOverride: GalleryLayoutType.grid,
showSelectAll: false,
),
),
@@ -124,7 +134,20 @@ class _DynamicLocationGalleryWidgetState
);
}
- double _galleryHeight(int fileCount, double widthOfGrid) {
+ double _galleryHeight(List<EnteFile> files, double widthOfGrid) {
+ if (localSettings.getGalleryLayoutType() == GalleryLayoutType.justified) {
+ final rows = JustifiedLayoutCalculator.computePairedRows(
+ aspectRatios: files.map(
+ (file) => JustifiedLayoutCalculator.aspectRatioForDimensions(
+ file.width,
+ file.height,
+ ),
+ ),
+ availableWidth: widthOfGrid,
+ spacing: galleryGridSpacing,
+ );
+ return (rows.isEmpty ? 0 : rows.last.maxOffset) + 120;
+ }
final photoGridSize = localSettings.getPhotoGridSize();
final totalWhiteSpaceBetweenPhotos =
galleryGridSpacing * (photoGridSize - 1);
@@ -132,7 +155,7 @@ class _DynamicLocationGalleryWidgetState
final thumbnailHeight =
((widthOfGrid - totalWhiteSpaceBetweenPhotos) / photoGridSize);
- final numberOfRows = (fileCount / photoGridSize).ceil();
+ final numberOfRows = (files.length / photoGridSize).ceil();
final galleryHeight =
(thumbnailHeight * numberOfRows) +
diff --git a/mobile/apps/photos/test/models/gallery_groups_justified_test.dart b/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
index b4ba15ae1a..aa46567a68 100644
--- a/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
+++ b/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
@@ -123,7 +123,11 @@ void main() {
for (final file in expectedFiles) {
final fileOffset = groups.getOffsetOfFile(file);
expect(fileOffset, isNotNull);
- expect(groups.getFileAtScrollOffset(fileOffset!), same(file));
+ final fileIndex = expectedFiles.indexOf(file);
+ expect(
+ groups.getFileAtScrollOffset(fileOffset!),
+ same(expectedFiles[fileIndex - fileIndex % 2]),
+ );
expect(
groups.getOffsetOfGroupContainingFile(file),
closeTo(justifiedSection.minOffset, 1e-9),
@@ -136,119 +140,41 @@ void main() {
}
});
- test("routes justified galleries through the selected strategy", () async {
- final files = List.generate(
- 4,
- (index) => _file(
- index: index,
- creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
- width: 9,
- height: 16,
- ),
- );
- await localSettings.setPhotoGridSize(2);
- await localSettings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- 1,
- );
- GalleryGroups groups() => _galleryGroups(
- files: files,
- groupType: GroupType.none,
- groupHeaderExtent: GalleryGroups.spacing,
- widthAvailable: 402,
- );
- final comfortLarge = groups().groupLayouts.single as JustifiedSectionLayout;
- expect(comfortLarge.rows.map((row) => row.itemWidths.length), [2, 2]);
- await localSettings.setJustifiedLayoutStrategy(
- JustifiedLayoutStrategy.flex,
- );
- await localSettings.setFlexLayoutTuningValue(
- FlexLayoutTuningField.targetHeightScale,
- 1,
- );
- final flex = groups().groupLayouts.single as JustifiedSectionLayout;
- expect(flex.rows.map((row) => row.itemWidths.length), [3, 1]);
- _expectRowsCoverFiles(flex, files.length);
- });
-
- test("routes Flex with its non-final singleton tuning", () async {
- final files = List<EnteFile>.generate(
- 3,
- (index) => _file(
- index: index,
- creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
- width: 16,
- height: 9,
- ),
- );
- await localSettings.setPhotoGridSize(2);
- await localSettings.setJustifiedLayoutStrategy(
- JustifiedLayoutStrategy.flex,
- );
-
- JustifiedSectionLayout section() =>
- _galleryGroups(
- files: files,
- groupType: GroupType.none,
- groupHeaderExtent: GalleryGroups.spacing,
- widthAvailable: 402,
- ).groupLayouts.single
- as JustifiedSectionLayout;
-
- expect(section().rows.map((row) => row.itemWidths.length), [1, 1, 1]);
- await localSettings.setFlexLayoutTuningValue(
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio,
- 2,
- );
- final constrainedRows = section().rows;
- expect(constrainedRows.map((row) => row.itemWidths.length), [2, 1]);
- });
-
- test("keeps layout tuning separate for Flex and Comfort Large", () async {
- final file = _file(
- index: 0,
- creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
- width: 1,
- height: 1,
- );
- await localSettings.setPhotoGridSize(2);
- double rowHeight() {
- final section =
- _galleryGroups(
- files: [file],
- groupType: GroupType.none,
- groupHeaderExtent: GalleryGroups.spacing,
- widthAvailable: 1024,
- ).groupLayouts.single
- as JustifiedSectionLayout;
- return section.rows.single.height;
- }
-
- expect(
- rowHeight(),
- 320 * ComfortLargeLayoutTuning.defaults.targetHeightScale,
- );
-
- await localSettings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- 1.25,
- );
- expect(rowHeight(), 400);
-
- await localSettings.setJustifiedLayoutStrategy(
- JustifiedLayoutStrategy.flex,
- );
- final defaultFlexHeight =
- 320 *
- FlexLayoutTuning.defaults.targetHeightScale *
- FlexLayoutTuning.defaults.maximumHeightFactor;
- expect(rowHeight(), defaultFlexHeight);
- await localSettings.setFlexLayoutTuningValue(
- FlexLayoutTuningField.maximumHeightFactor,
- 2,
- );
- expect(rowHeight(), 320 * FlexLayoutTuning.defaults.targetHeightScale * 2);
- });
+ test(
+ "justified always pairs photos independently of the saved grid count",
+ () async {
+ final files = List.generate(
+ 5,
+ (index) => _file(
+ index: index,
+ creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
+ width: index.isEven ? 3 : 1,
+ height: index.isEven ? 2 : 2,
+ ),
+ );
+ for (final count in [3, 6]) {
+ await localSettings.setPhotoGridSize(count);
+ final groups = _galleryGroups(
+ files: files,
+ groupType: GroupType.none,
+ groupHeaderExtent: GalleryGroups.spacing,
+ widthAvailable: 402,
+ );
+ expect(groups.crossAxisCount, 2);
+ final section = groups.groupLayouts.single as JustifiedSectionLayout;
+ expect(section.rows.map((row) => row.itemWidths.length), [2, 2, 1]);
+ _expectRowsCoverFiles(section, files.length);
+ for (final row in section.rows.take(2)) {
+ expect(
+ row.itemWidths.reduce((a, b) => a + b) + GalleryGroups.spacing,
+ closeTo(402, 1e-9),
+ );
+ expect(row.itemWidths.first / row.itemWidths.last, closeTo(3, 1e-9));
+ }
+ expect(section.rows.last.height, lessThanOrEqualTo(201));
+ }
+ },
+ );
test(
"headerless justified remains one continuous group past grid chunks",
@@ -289,11 +215,7 @@ void main() {
expect(section.bodyMinOffset, GalleryGroups.spacing);
_expectRowsCoverFiles(section, fileCount);
- final rowAcrossLegacyBoundary = section.rows.singleWhere(
- (row) => row.firstIndex <= 39 && row.lastIndex >= 40,
- );
- expect(rowAcrossLegacyBoundary.firstIndex, 39);
- expect(rowAcrossLegacyBoundary.lastIndex, 41);
+ expect(section.rows, hasLength(fileCount ~/ 2));
for (final row in section.rows) {
final firstFileInRow = files[row.firstIndex];
@@ -308,39 +230,6 @@ void main() {
},
);
- test(
- "caps the target height only when the grid-derived target is taller",
- () async {
- final file = _file(
- index: 0,
- creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
- width: 1,
- height: 1,
- );
- double rowHeight() {
- final section =
- _galleryGroups(
- files: [file],
- groupType: GroupType.none,
- groupHeaderExtent: GalleryGroups.spacing,
- widthAvailable: 1024,
- ).groupLayouts.single
- as JustifiedSectionLayout;
- return section.rows.single.height;
- }
-
- await localSettings.setPhotoGridSize(2);
- await localSettings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- 1,
- );
- expect(rowHeight(), 320);
-
- await localSettings.setPhotoGridSize(4);
- expect(rowHeight(), (1024 - 3 * GalleryGroups.spacing) / 4);
- },
- );
-
testWidgets("justified rows request large thumbnails for every tile", (
tester,
) async {
diff --git a/mobile/apps/photos/test/settings/local_settings_gallery_layout_test.dart b/mobile/apps/photos/test/settings/local_settings_gallery_layout_test.dart
index 38f52a2a01..59f49e3959 100644
--- a/mobile/apps/photos/test/settings/local_settings_gallery_layout_test.dart
+++ b/mobile/apps/photos/test/settings/local_settings_gallery_layout_test.dart
@@ -1,7 +1,9 @@
import "package:flutter_test/flutter_test.dart";
+import "package:photos/core/configuration.dart";
import "package:photos/models/gallery/justified_layout_strategy.dart";
import "package:photos/models/gallery/justified_layout_tuning.dart";
import "package:photos/settings/local_settings.dart";
+import "package:photos/ui/viewer/gallery/component/group/type.dart";
import "package:shared_preferences/shared_preferences.dart";
void main() {
@@ -12,8 +14,59 @@ void main() {
final settings = LocalSettings(await SharedPreferences.getInstance());
expect(settings.getGalleryLayoutType(), GalleryLayoutType.grid);
+ expect(settings.getPhotoGridSize(), 3);
});
+ test(
+ "migrates the two-column preference without changing other settings",
+ () async {
+ for (final count in [2, 3, 4, 5, 6]) {
+ SharedPreferences.setMockInitialValues({
+ LocalSettings.kPhotoGridSize: count,
+ LocalSettings.kGalleryGroupType: GroupType.month.toString(),
+ "album_sort_order": "oldest_first",
+ "hide_shared_items_from_home_gallery": true,
+ });
+ final preferences = await SharedPreferences.getInstance();
+ final settings = LocalSettings(preferences);
+ await settings.migrateGalleryLayoutPreferences();
+ expect(
+ settings.getGalleryLayoutType(),
+ count == 2 ? GalleryLayoutType.justified : GalleryLayoutType.grid,
+ );
+ expect(settings.getPhotoGridSize(), count == 2 ? 3 : count);
+ expect(settings.getGalleryGroupType(), GroupType.month);
+ expect(preferences.getString("album_sort_order"), "oldest_first");
+ expect(
+ preferences.getBool("hide_shared_items_from_home_gallery"),
+ isTrue,
+ );
+ await settings.setGalleryLayoutType(GalleryLayoutType.grid);
+ await settings.migrateGalleryLayoutPreferences();
+ expect(settings.getGalleryLayoutType(), GalleryLayoutType.grid);
+ }
+ },
+ );
+
+ test(
+ "retains the old implicit default while new installs keep three",
+ () async {
+ SharedPreferences.setMockInitialValues({Configuration.userIDKey: 1});
+ var preferences = await SharedPreferences.getInstance();
+ var settings = LocalSettings(preferences);
+ await settings.migrateGalleryLayoutPreferences();
+ expect(settings.getPhotoGridSize(), 4);
+
+ SharedPreferences.setMockInitialValues({});
+ preferences = await SharedPreferences.getInstance();
+ settings = LocalSettings(preferences);
+ await settings.migrateGalleryLayoutPreferences();
+ await preferences.setInt(Configuration.userIDKey, 1);
+ await settings.migrateGalleryLayoutPreferences();
+ expect(settings.getPhotoGridSize(), 3);
+ },
+ );
+
test("gallery layout persists justified", () async {
SharedPreferences.setMockInitialValues({});
final preferences = await SharedPreferences.getInstance();
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/component/gallery_file_widget_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/component/gallery_file_widget_test.dart
index a7b04971b2..cc6dc05465 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/component/gallery_file_widget_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/component/gallery_file_widget_test.dart
@@ -211,7 +211,7 @@ void main() {
);
}
- testWidgets("a thumbnail tier change recreates the thumbnail loader", (
+ testWidgets("Grid thumbnail tiers and overrides recreate the loader", (
tester,
) async {
final file = EnteFile()
@@ -219,7 +219,7 @@ void main() {
..fileType = FileType.image
..title = "photo.jpg";
- Widget buildGalleryTile(int thumbnailSize) {
+ Widget buildGalleryTile({required int gridSize, int? thumbnailSize}) {
return MaterialApp(
home: GalleryContextState(
sortOrderAsc: false,
@@ -232,7 +232,7 @@ void main() {
selectedFiles: null,
limitSelectionToOne: true,
tag: "gallery_",
- photoGridSize: photoGridSizeDefault,
+ photoGridSize: gridSize,
thumbnailSize: thumbnailSize,
currentUserID: null,
),
@@ -241,28 +241,40 @@ void main() {
);
}
- await tester.pumpWidget(buildGalleryTile(thumbnailSmallSize));
- final smallThumbnailState = tester.state<State<ThumbnailWidget>>(
- find.byType(ThumbnailWidget),
- );
- expect(
- tester
- .widget<ThumbnailWidget>(find.byType(ThumbnailWidget))
- .thumbnailSize,
- thumbnailSmallSize,
- );
+ for (final useOverride in [false, true]) {
+ await tester.pumpWidget(
+ buildGalleryTile(
+ gridSize: useOverride ? 3 : 4,
+ thumbnailSize: useOverride ? thumbnailSmallSize : null,
+ ),
+ );
+ final smallThumbnailState = tester.state<State<ThumbnailWidget>>(
+ find.byType(ThumbnailWidget),
+ );
+ expect(
+ tester
+ .widget<ThumbnailWidget>(find.byType(ThumbnailWidget))
+ .thumbnailSize,
+ thumbnailSmallSize,
+ );
- await tester.pumpWidget(buildGalleryTile(thumbnailLargeSize));
- final largeThumbnailState = tester.state<State<ThumbnailWidget>>(
- find.byType(ThumbnailWidget),
- );
- expect(
- tester
- .widget<ThumbnailWidget>(find.byType(ThumbnailWidget))
- .thumbnailSize,
- thumbnailLargeSize,
- );
- expect(largeThumbnailState, isNot(same(smallThumbnailState)));
+ await tester.pumpWidget(
+ buildGalleryTile(
+ gridSize: 3,
+ thumbnailSize: useOverride ? thumbnailLargeSize : null,
+ ),
+ );
+ final largeThumbnailState = tester.state<State<ThumbnailWidget>>(
+ find.byType(ThumbnailWidget),
+ );
+ expect(
+ tester
+ .widget<ThumbnailWidget>(find.byType(ThumbnailWidget))
+ .thumbnailSize,
+ thumbnailLargeSize,
+ );
+ expect(largeThumbnailState, isNot(same(smallThumbnailState)));
+ }
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump(const Duration(milliseconds: 100));
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
index 832512bffc..8a57f44c72 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
@@ -169,112 +169,229 @@ void main() {
},
);
- testWidgets("Flex remains unavailable when internal features are disabled", (
- tester,
- ) async {
- await localSettings.setGalleryLayoutType(GalleryLayoutType.justified);
- await localSettings.setJustifiedLayoutStrategy(
- JustifiedLayoutStrategy.flex,
- );
- await localSettings.setInternalUserDisabled(true);
-
- expect(isJustifiedLayoutAvailable, isFalse);
- expect(
- resolveGalleryLayoutType(localSettings.getGalleryLayoutType()),
- GalleryLayoutType.grid,
- );
- for (final settings in [
- const Scaffold(body: GalleryLayoutSettings()),
- const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: true),
- ]) {
- await tester.pumpWidget(
- MaterialApp(
- theme: lightThemeData,
- localizationsDelegates: StringsLocalizations.localizationsDelegates,
- supportedLocales: StringsLocalizations.supportedLocales,
- home: settings,
- ),
- );
- await tester.pumpAndSettle();
- expect(find.text("Justified Β· Flex (i)"), findsNothing);
- expect(find.text("Layout (i)"), findsNothing);
- }
- });
-
testWidgets(
- "selecting or reselecting Flex in either menu sets grid size 2 and notifies galleries",
+ "both entry points preserve grouping and the remembered Grid count",
(tester) async {
var events = 0;
final subscription = Bus.instance.on<GalleryLayoutChangedEvent>().listen(
(_) => events++,
);
addTearDown(subscription.cancel);
- for (final (quickMenu, initialStrategy) in [
- (true, JustifiedLayoutStrategy.comfortLarge),
- (false, JustifiedLayoutStrategy.comfortLarge),
- (true, JustifiedLayoutStrategy.flex),
- (false, JustifiedLayoutStrategy.flex),
- ]) {
- await localSettings.setGalleryLayoutType(GalleryLayoutType.justified);
- await localSettings.setJustifiedLayoutStrategy(initialStrategy);
- await localSettings.setPhotoGridSize(4);
+ for (final quickMenu in [true, false]) {
+ await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);
+ await localSettings.setPhotoGridSize(5);
+ await localSettings.setGalleryGroupType(GroupType.month);
events = 0;
await tester.pumpWidget(
MaterialApp(
theme: lightThemeData,
localizationsDelegates: StringsLocalizations.localizationsDelegates,
supportedLocales: StringsLocalizations.supportedLocales,
- home: Scaffold(
- body: Builder(
- builder: (context) => TextButton(
- onPressed: () => Navigator.of(context).push(
- MaterialPageRoute<void>(
- builder: (_) => quickMenu
- ? const Scaffold(body: GalleryLayoutSettings())
- : const GallerySettingsScreen(
- fromGalleryLayoutSettingsCTA: true,
- ),
- ),
+ home: quickMenu
+ ? const Scaffold(body: GalleryLayoutSettings())
+ : const GallerySettingsScreen(
+ fromGalleryLayoutSettingsCTA: true,
),
- child: const Text("Open settings"),
- ),
- ),
- ),
),
);
- await tester.tap(find.text("Open settings"));
await tester.pumpAndSettle();
- if (!quickMenu) {
- await tester.tap(find.text("Layout (i)"));
- await tester.pumpAndSettle();
+ expect(find.text("Photos per row"), findsOneWidget);
+ final cardTop = tester
+ .getTopLeft(find.byKey(const ValueKey(GalleryLayoutType.grid)))
+ .dy;
+ final groupingTop = tester.getTopLeft(find.text("Group by")).dy;
+ final sheetHeight = quickMenu
+ ? tester.getSize(find.byType(GalleryLayoutSettings)).height
+ : null;
+ expect(find.text("Grid"), findsNothing);
+ expect(find.text("Justified"), findsNothing);
+ await tester.tap(
+ find.byKey(const ValueKey(GalleryLayoutType.justified)),
+ );
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 120));
+ if (quickMenu) {
+ expect(
+ tester.getSize(find.byType(GalleryLayoutSettings)).height,
+ sheetHeight,
+ );
+ expect(
+ tester
+ .getTopLeft(find.byKey(const ValueKey(GalleryLayoutType.grid)))
+ .dy,
+ cardTop,
+ );
}
- expect(find.text("Justified Β· Comfort"), findsNothing);
- expect(find.text("Justified Β· Flex Full Rows"), findsNothing);
- await tester.tap(find.text("Justified Β· Flex (i)").hitTestable());
await tester.pumpAndSettle();
expect(
localSettings.getGalleryLayoutType(),
GalleryLayoutType.justified,
);
+ expect(find.text("Photos per row").hitTestable(), findsNothing);
+ if (quickMenu) {
+ expect(
+ tester.getSize(find.byType(GalleryLayoutSettings)).height,
+ sheetHeight,
+ );
+ expect(
+ tester
+ .getTopLeft(find.byKey(const ValueKey(GalleryLayoutType.grid)))
+ .dy,
+ cardTop,
+ );
+ expect(
+ tester.getTopLeft(find.text("Group by")).dy,
+ lessThan(groupingTop),
+ );
+ }
+ expect(localSettings.getPhotoGridSize(), 5);
+ expect(localSettings.getGalleryGroupType(), GroupType.month);
+ expect(events, 1);
+ await tester.tap(find.byKey(const ValueKey(GalleryLayoutType.grid)));
+ await tester.pumpAndSettle();
+ expect(find.text("5"), findsOneWidget);
+ await tester.tap(find.byKey(const ValueKey("more-photos-per-row")));
+ await tester.pumpAndSettle();
+ expect(localSettings.getPhotoGridSize(), 6);
+ expect(localSettings.getGalleryGroupType(), GroupType.month);
+ expect(events, 3);
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pumpAndSettle();
+ }
+ },
+ );
+
+ testWidgets(
+ "only opted-in galleries show a header CTA or floating Layout control",
+ (tester) async {
+ final files = List.generate(120, _justifiedTestFile);
+ for (final groupType in [GroupType.day, GroupType.none]) {
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: Scaffold(
+ body: _galleryHost(
+ Gallery(
+ asyncLoader: (start, end, {limit, asc}) async =>
+ FileLoadResult(files, false),
+ initialFiles: files,
+ tagPrefix: "default_layout_cta_",
+ groupType: groupType,
+ showSelectAll: false,
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.pump(const Duration(milliseconds: 750));
+ await tester.pump();
+ if (groupType == GroupType.day) {
+ expect(find.byType(GroupHeaderWidget), findsWidgets);
+ }
+ expect(find.byType(FloatingGalleryLayoutButton), findsNothing);
expect(
- localSettings.getJustifiedLayoutStrategy(),
- JustifiedLayoutStrategy.flex,
+ find.byWidgetPredicate(
+ (widget) =>
+ widget is GroupHeaderWidget &&
+ widget.showGalleryLayoutSettingCTA,
+ ),
+ findsNothing,
);
- expect(localSettings.getPhotoGridSize(), 2);
- expect(events, 1);
- if (!quickMenu) {
- expect(find.text("2"), findsOneWidget);
- await tester.tap(find.text("Layout (i)"));
- await tester.pumpAndSettle();
- await tester.tap(find.text("Grid"));
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pumpAndSettle();
+ }
+ for (final pinnedDisabled in [false, true]) {
+ final galleryKey = GlobalKey<GalleryState>();
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: Scaffold(
+ body: _galleryHost(
+ Gallery(
+ key: galleryKey,
+ asyncLoader: (start, end, {limit, asc}) async =>
+ FileLoadResult(files, false),
+ initialFiles: files,
+ tagPrefix: "layout_cta_",
+ header: const SizedBox(height: 120),
+ groupType: GroupType.day,
+ disablePinnedGroupHeader: pinnedDisabled,
+ showSelectAll: false,
+ showGallerySettingsCTA: true,
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.pump(const Duration(milliseconds: 750));
+ await tester.pump();
+ expect(find.byType(FloatingGalleryLayoutButton), findsNothing);
+ expect(
+ find.byWidgetPredicate(
+ (widget) =>
+ widget is GroupHeaderWidget &&
+ widget.showGalleryLayoutSettingCTA,
+ ),
+ findsWidgets,
+ );
+ if (!pinnedDisabled) {
+ final scrollable = find
+ .descendant(
+ of: find.byType(Gallery),
+ matching: find.byType(Scrollable),
+ )
+ .first;
+ tester.state<ScrollableState>(scrollable).position.jumpTo(300);
await tester.pumpAndSettle();
- expect(localSettings.getGalleryLayoutType(), GalleryLayoutType.grid);
- expect(localSettings.getPhotoGridSize(), 2);
- expect(events, 2);
+ expect(find.byType(FloatingGalleryLayoutButton), findsNothing);
+ expect(
+ find.byWidgetPredicate(
+ (widget) =>
+ widget is GroupHeaderWidget &&
+ widget.isPinnedHeader &&
+ widget.showGalleryLayoutSettingCTA,
+ ),
+ findsOneWidget,
+ );
}
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpAndSettle();
}
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: Scaffold(
+ body: _galleryHost(
+ Gallery(
+ asyncLoader: (start, end, {limit, asc}) async =>
+ FileLoadResult(files, false),
+ initialFiles: files,
+ tagPrefix: "headerless_layout_cta_",
+ groupType: GroupType.none,
+ showSelectAll: false,
+ showGallerySettingsCTA: true,
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+ final galleryRect = tester.getRect(find.byType(Gallery));
+ final buttonRect = tester.getRect(
+ find.byType(FloatingGalleryLayoutButton),
+ );
+ expect(buttonRect.top, closeTo(galleryRect.top + 16, 0.001));
+ expect(buttonRect.right, closeTo(galleryRect.right - 16, 0.001));
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pumpAndSettle();
},
);
@@ -410,7 +527,7 @@ void main() {
tester,
) async {
await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);
- await localSettings.setPhotoGridSize(2);
+ await localSettings.setPhotoGridSize(3);
final galleryKey = GlobalKey<GalleryState>();
final files = List<EnteFile>.generate(1000, _justifiedTestFile);
@@ -437,7 +554,7 @@ void main() {
await tester.pump();
final oldGroups = galleryKey.currentState!.galleryGroups!;
- final anchorFile = files[800];
+ final anchorFile = files[804];
final oldGeometry = oldGroups.getGeometryOfFile(anchorFile)!;
const rowProgress = 0.72;
final oldAnchorOffset =
@@ -469,7 +586,7 @@ void main() {
final justifiedGroups = galleryKey.currentState!.galleryGroups!;
expect(justifiedGroups.layoutType, GalleryLayoutType.justified);
final newGeometry = justifiedGroups.getGeometryOfFile(anchorFile)!;
- expect(newGeometry.rowExtent, lessThan(oldGeometry.rowExtent));
+ expect(newGeometry.rowExtent, isNot(oldGeometry.rowExtent));
final expectedAnchorOffset =
newGeometry.rowOffset + newGeometry.rowExtent * rowProgress;
expect(
@@ -591,7 +708,7 @@ void main() {
same(anchorFile),
);
- await localSettings.setPhotoGridSize(2);
+ await localSettings.setPhotoGridSize(3);
Bus.instance.fire(GalleryLayoutChangedEvent());
await tester.pumpAndSettle();
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 945b9da070..371e52dd4a 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -1875,6 +1875,9 @@
"grantPermissionDesc": "Please allow Ente to access your library so we can organize it with face recognition. All processing happens on your device.",
"greenery": "The green life",
"grid": "Grid",
+ "photosInOriginalProportions": "Photos in original proportions",
+ "squarePhotos": "Square photos",
+ "photosPerRow": "Photos per row",
"groupBy": "Group by",
"groupByDay": "Day",
"groupByMonth": "Month",