Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

[mob][photos] Use Flex for justified gallery layout

ashil-pilotd2741474c540
diff --git a/mobile/apps/photos/lib/models/gallery/flex_layout.dart b/mobile/apps/photos/lib/models/gallery/flex_layout.dart
index 169b029f2d..7ce64a8357 100644
--- a/mobile/apps/photos/lib/models/gallery/flex_layout.dart
+++ b/mobile/apps/photos/lib/models/gallery/flex_layout.dart
@@ -6,8 +6,11 @@ import "package:photos/models/gallery/justified_layout.dart";
// Selects the minimum-cost sequence from candidate row breaks across the group.
class FlexLayoutCalculator {
+ static const double _minimumAspectRatio = 1 / 3;
+ static const double _maximumAspectRatio = 4;
+ static const double _minimumNonFinalSingletonAspectRatio = 0.75;
static const double _minimumTappableExtent = 48;
- static const double _defaultMaximumRowHeightFactor = 1.6;
+ static const double _maximumRowHeightFactor = 1.6;
static const double _minimumLandscapeRowHeight = 96;
static const int _minimumLandscapeDensityItemCount = 3;
static const double _preferredTileWidthFactor = 0.6;
@@ -15,13 +18,24 @@ class FlexLayoutCalculator {
const FlexLayoutCalculator._();
+ static double aspectRatioForDimensions(int width, int height) {
+ if (width <= 0 || height <= 0) return 1;
+ return (width / height)
+ .clamp(_minimumAspectRatio, _maximumAspectRatio)
+ .toDouble();
+ }
+
+ static int _maximumItemsPerRowFor(double availableWidth) {
+ if (availableWidth < 600) return 3;
+ if (availableWidth < 1008) return 4;
+ return 5;
+ }
+
static List<JustifiedRowLayout> computeRows({
required Iterable<double> aspectRatios,
required double availableWidth,
required double targetRowHeight,
required double spacing,
- required double minimumNonFinalSingletonAspectRatio,
- double maximumRowHeightFactor = _defaultMaximumRowHeightFactor,
}) {
if (!availableWidth.isFinite || availableWidth <= 0) {
throw ArgumentError.value(availableWidth, "availableWidth");
@@ -32,26 +46,12 @@ class FlexLayoutCalculator {
if (!spacing.isFinite || spacing < 0) {
throw ArgumentError.value(spacing, "spacing");
}
- if (!maximumRowHeightFactor.isFinite || maximumRowHeightFactor < 1) {
- throw ArgumentError.value(
- maximumRowHeightFactor,
- "maximumRowHeightFactor",
- );
- }
- if (!minimumNonFinalSingletonAspectRatio.isFinite ||
- minimumNonFinalSingletonAspectRatio <= 0) {
- throw ArgumentError.value(
- minimumNonFinalSingletonAspectRatio,
- "minimumNonFinalSingletonAspectRatio",
- );
- }
-
final ratios = Float64List.fromList(aspectRatios.toList(growable: false));
if (ratios.isEmpty) return const [];
for (var i = 0; i < ratios.length; i++) {
final ratio = ratios[i];
ratios[i] = ratio.isFinite && ratio > 0
- ? ratio.clamp(1 / 3, 4).toDouble()
+ ? ratio.clamp(_minimumAspectRatio, _maximumAspectRatio).toDouble()
: 1;
}
@@ -60,13 +60,10 @@ class FlexLayoutCalculator {
final nextBreak = Uint32List(count);
final maximumHeight = math.max(
_minimumTappableExtent,
- targetRowHeight * maximumRowHeightFactor,
+ targetRowHeight * _maximumRowHeightFactor,
);
final preferredTileWidth = targetRowHeight * _preferredTileWidthFactor;
- final maximumCandidateRowLength =
- JustifiedLayoutCalculator.responsiveMaximumItemsPerRowFor(
- availableWidth,
- );
+ final maximumCandidateRowLength = _maximumItemsPerRowFor(availableWidth);
for (var start = count - 1; start >= 0; start--) {
var ratioSum = 0.0;
@@ -82,7 +79,7 @@ class FlexLayoutCalculator {
final isTail = end == count - 1;
if (!isTail &&
itemCount == 1 &&
- ratios[start] < minimumNonFinalSingletonAspectRatio) {
+ ratios[start] < _minimumNonFinalSingletonAspectRatio) {
continue;
}
final geometry = _rowGeometry(
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
index 0a25ec2822..19423e1792 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
@@ -10,11 +10,8 @@ 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";
@@ -36,7 +33,6 @@ class GalleryGroups {
final bool showGallerySettingsCTA;
final Widget? groupHeaderAction;
final GalleryLayoutType? layoutTypeOverride;
- final bool justifiedLayoutAvailable;
final bool sortOrderAsc;
final double widthAvailable;
@@ -55,7 +51,6 @@ class GalleryGroups {
this.showGallerySettingsCTA = false,
this.groupHeaderAction,
this.layoutTypeOverride,
- required this.justifiedLayoutAvailable,
}) {
init();
if (!groupType.showGroupHeader()) {
@@ -70,6 +65,7 @@ class GalleryGroups {
// Product decision: limit how tall the preferred justified row can grow as
// the gallery widens.
static const double _maximumJustifiedTargetRowHeight = 320.0;
+ static const double _justifiedTargetRowHeightScale = 1.12;
late final int crossAxisCount;
late final GalleryLayoutType layoutType;
@@ -271,10 +267,7 @@ class GalleryGroups {
}
void init() {
- layoutType = resolveGalleryLayoutType(
- layoutTypeOverride ?? localSettings.getGalleryLayoutType(),
- justifiedLayoutAvailable: justifiedLayoutAvailable,
- );
+ layoutType = layoutTypeOverride ?? localSettings.getGalleryLayoutType();
crossAxisCount = layoutType == GalleryLayoutType.justified
? 2
: localSettings.getPhotoGridSize();
@@ -452,24 +445,13 @@ 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 targetRowHeight =
+ baseTargetRowHeight * _justifiedTargetRowHeightScale;
final groupLayouts = <SectionLayout>[];
var currentIndex = 0;
var currentOffset = 0.0;
@@ -477,34 +459,17 @@ class GalleryGroups {
for (final groupID in _groupIdToFilesMap.keys) {
final filesInGroup = _groupIdToFilesMap[groupID]!;
final aspectRatios = filesInGroup.map(
- (file) => JustifiedLayoutCalculator.aspectRatioForDimensions(
+ (file) => FlexLayoutCalculator.aspectRatioForDimensions(
file.width,
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 = FlexLayoutCalculator.computeRows(
+ aspectRatios: aspectRatios,
+ availableWidth: widthAvailable,
+ targetRowHeight: targetRowHeight,
+ 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
deleted file mode 100644
index 706fe5b560..0000000000
--- a/mobile/apps/photos/lib/models/gallery/gallery_layout_config.dart
+++ /dev/null
@@ -1,14 +0,0 @@
-import "package:photos/settings/local_settings.dart";
-
-const isJustifiedLayoutAvailable = true;
-
-GalleryLayoutType resolveGalleryLayoutType(
- GalleryLayoutType preferredLayoutType, {
- bool? justifiedLayoutAvailable,
-}) {
- final isAvailable = justifiedLayoutAvailable ?? isJustifiedLayoutAvailable;
- if (preferredLayoutType == GalleryLayoutType.justified && !isAvailable) {
- return GalleryLayoutType.grid;
- }
- return 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..0f8e3f13fd 100644
--- a/mobile/apps/photos/lib/models/gallery/justified_layout.dart
+++ b/mobile/apps/photos/lib/models/gallery/justified_layout.dart
@@ -1,6 +1,3 @@
-import "dart:collection";
-import "dart:math" as math;
-
import "package:photos/models/gallery/section_layout.dart";
class JustifiedRowLayout {
@@ -91,286 +88,3 @@ class JustifiedSectionLayout extends SectionLayout {
return result;
}
}
-
-class JustifiedLayoutCalculator {
- static const double _minimumAspectRatio = 1 / 3;
- static const double _maximumAspectRatio = 4.0;
- static const double _maximumRowHeightFactor = 2.4;
- static const double _maximumWideFinalRowHeightFactor = 1.0;
- static const double _minimumLandscapeRowHeightFactor = 0.88;
- static const double _mediumWidthBreakpoint = 600;
- static const double _expandedWidthBreakpoint = 1008;
- // Product decision: cap visual density based on the available gallery width,
- // independently of tap-target sizing.
- static const int _compactMaximumItemsPerRow = 3;
- static const int _mediumMaximumItemsPerRow = 4;
- static const int _expandedMaximumItemsPerRow = 5;
- static const int _minimumLandscapeDensityItemCount = 3;
- // Logical pixels map to density-independent tap extents on both platforms.
- static const double _minimumTappableExtent = 48.0;
-
- const JustifiedLayoutCalculator._();
-
- static double aspectRatioForDimensions(int width, int height) {
- if (width <= 0 || height <= 0) return 1;
- return (width / height)
- .clamp(_minimumAspectRatio, _maximumAspectRatio)
- .toDouble();
- }
-
- static int responsiveMaximumItemsPerRowFor(double availableWidth) {
- if (availableWidth < _mediumWidthBreakpoint) {
- return _compactMaximumItemsPerRow;
- }
- if (availableWidth < _expandedWidthBreakpoint) {
- return _mediumMaximumItemsPerRow;
- }
- return _expandedMaximumItemsPerRow;
- }
-
- static List<JustifiedRowLayout> computeRows({
- required Iterable<double> aspectRatios,
- required double availableWidth,
- required double targetRowHeight,
- required double spacing,
- double maximumRowHeightFactor = _maximumRowHeightFactor,
- double wideFinalMaximumRowHeightFactor = _maximumWideFinalRowHeightFactor,
- double minimumLandscapeRowHeightFactor = _minimumLandscapeRowHeightFactor,
- }) {
- if (aspectRatios.isEmpty) return const [];
- if (!availableWidth.isFinite || availableWidth <= 0) {
- throw ArgumentError.value(availableWidth, "availableWidth");
- }
- if (!targetRowHeight.isFinite || targetRowHeight <= 0) {
- throw ArgumentError.value(targetRowHeight, "targetRowHeight");
- }
- if (!spacing.isFinite || spacing < 0) {
- throw ArgumentError.value(spacing, "spacing");
- }
- if (!maximumRowHeightFactor.isFinite || maximumRowHeightFactor < 1) {
- throw ArgumentError.value(
- maximumRowHeightFactor,
- "maximumRowHeightFactor",
- );
- }
- if (!wideFinalMaximumRowHeightFactor.isFinite ||
- wideFinalMaximumRowHeightFactor < 1) {
- throw ArgumentError.value(
- wideFinalMaximumRowHeightFactor,
- "wideFinalMaximumRowHeightFactor",
- );
- }
- if (!minimumLandscapeRowHeightFactor.isFinite ||
- minimumLandscapeRowHeightFactor <= 0) {
- throw ArgumentError.value(
- minimumLandscapeRowHeightFactor,
- "minimumLandscapeRowHeightFactor",
- );
- }
-
- final rows = <JustifiedRowLayout>[];
- final pendingRatios = <double>[];
- final maximumRowHeight = targetRowHeight * maximumRowHeightFactor;
- final maximumItemsPerRow = responsiveMaximumItemsPerRowFor(availableWidth);
- // On wider galleries, prefer a partial final row once its configured
- // growth limit is reached. Compact layouts retain their tail treatment.
- final limitsFinalRowGrowth = availableWidth >= _mediumWidthBreakpoint;
- final maximumFinalRowHeightFactor = limitsFinalRowGrowth
- ? wideFinalMaximumRowHeightFactor
- : maximumRowHeightFactor;
- final maximumFinalRowHeight = targetRowHeight * maximumFinalRowHeightFactor;
- final lastCommittedRatios = <double>[];
- var pendingRatioSum = 0.0;
- var pendingMinimumRatio = double.infinity;
- var pendingFirstIndex = 0;
- var rowOffset = 0.0;
-
- double widthWithoutGaps(int itemCount) =>
- math.max(1, availableWidth - spacing * (itemCount - 1));
-
- void addPendingRow({
- required bool fillWidth,
- double raggedHeightFactor = 1,
- }) {
- if (pendingRatios.isEmpty) return;
- final contentWidth = widthWithoutGaps(pendingRatios.length);
- final fittedHeight = contentWidth / pendingRatioSum;
- final minimumTappableHeight = math.max(
- _minimumTappableExtent,
- _minimumTappableExtent / pendingMinimumRatio,
- );
- final height = fillWidth
- ? fittedHeight
- : math.min(
- fittedHeight,
- math.max(
- targetRowHeight * raggedHeightFactor,
- minimumTappableHeight,
- ),
- );
- final widths = pendingRatios
- .map((ratio) => ratio * height)
- .toList(growable: false);
-
- if (fillWidth && widths.isNotEmpty) {
- final precedingWidth = widths
- .take(widths.length - 1)
- .fold<double>(0, (sum, width) => sum + width);
- widths[widths.length - 1] = math.max(0, contentWidth - precedingWidth);
- }
-
- rows.add(
- JustifiedRowLayout(
- firstIndex: pendingFirstIndex,
- lastIndex: pendingFirstIndex + pendingRatios.length - 1,
- minOffset: rowOffset,
- height: height,
- itemWidths: UnmodifiableListView(widths),
- ),
- );
- lastCommittedRatios
- ..clear()
- ..addAll(pendingRatios);
- rowOffset += height + spacing;
- pendingFirstIndex += pendingRatios.length;
- pendingRatios.clear();
- pendingRatioSum = 0;
- pendingMinimumRatio = double.infinity;
- }
-
- bool canJustifyFinalRow(List<double> ratios) {
- final ratioSum = ratios.fold<double>(0, (sum, ratio) => sum + ratio);
- final height = widthWithoutGaps(ratios.length) / ratioSum;
- final minimumWidth =
- height * ratios.reduce((left, right) => math.min(left, right));
- final isTappableAndBounded =
- height >= _minimumTappableExtent &&
- height <= maximumFinalRowHeight &&
- minimumWidth >= _minimumTappableExtent;
- if (!isTappableAndBounded) return false;
-
- return ratios.length < _minimumLandscapeDensityItemCount ||
- ratios.any((ratio) => ratio < 1) ||
- height >= targetRowHeight * minimumLandscapeRowHeightFactor;
- }
-
- void replacePendingRatios(Iterable<double> ratios) {
- pendingRatios
- ..clear()
- ..addAll(ratios);
- pendingRatioSum = pendingRatios.fold<double>(
- 0,
- (sum, ratio) => sum + ratio,
- );
- pendingMinimumRatio = pendingRatios.fold<double>(
- double.infinity,
- (minimum, ratio) => math.min(minimum, ratio),
- );
- }
-
- void rewindLastRow() {
- final removedRow = rows.removeLast();
- rowOffset = removedRow.minOffset;
- pendingFirstIndex = removedRow.firstIndex;
- }
-
- for (final rawRatio in aspectRatios) {
- // Reaching the item cap only proves that a row is non-final once another
- // item arrives. An exact-cap group tail still uses the final-row policy.
- if (pendingRatios.length == maximumItemsPerRow) {
- addPendingRow(fillWidth: true);
- }
-
- final ratio = rawRatio.isFinite && rawRatio > 0
- ? rawRatio.clamp(_minimumAspectRatio, _maximumAspectRatio).toDouble()
- : 1.0;
- if (pendingRatios.isNotEmpty) {
- final candidateCount = pendingRatios.length + 1;
- final candidateRatioSum = pendingRatioSum + ratio;
- final candidateHeight =
- widthWithoutGaps(candidateCount) / candidateRatioSum;
- final candidateMinimumWidth =
- candidateHeight * math.min(pendingMinimumRatio, ratio);
- final currentHeight =
- widthWithoutGaps(pendingRatios.length) / pendingRatioSum;
- final violatesTapTarget =
- candidateHeight < _minimumTappableExtent ||
- candidateMinimumWidth < _minimumTappableExtent;
- final violatesLandscapeDensity =
- candidateCount >= _minimumLandscapeDensityItemCount &&
- pendingMinimumRatio >= 1 &&
- ratio >= 1 &&
- candidateHeight < targetRowHeight * minimumLandscapeRowHeightFactor;
-
- if (violatesTapTarget || violatesLandscapeDensity) {
- final leaveSingletonRagged = pendingRatios.length == 1;
- addPendingRow(
- fillWidth:
- !leaveSingletonRagged && currentHeight <= maximumRowHeight,
- );
- }
- }
-
- pendingRatios.add(ratio);
- pendingRatioSum += ratio;
- pendingMinimumRatio = math.min(pendingMinimumRatio, ratio);
-
- final naturalWidth =
- pendingRatioSum * targetRowHeight +
- spacing * (pendingRatios.length - 1);
- if (naturalWidth >= availableWidth) {
- addPendingRow(fillWidth: true);
- }
- }
-
- // Compact galleries retain the established behavior of filling a row that
- // ends exactly at their item cap. Wider galleries defer it to the bounded
- // final-row treatment below.
- if (!limitsFinalRowGrowth && pendingRatios.length == maximumItemsPerRow) {
- addPendingRow(fillWidth: true);
- }
-
- // Product decision: avoid one-item group tails by rebalancing the preceding
- // row when the replacement rows meet tap-target, height, and density limits.
- if (pendingRatios.length == 1 && rows.isNotEmpty) {
- final tailRatios = <double>[...lastCommittedRatios, pendingRatios.single];
- if (lastCommittedRatios.length < maximumItemsPerRow &&
- canJustifyFinalRow(tailRatios)) {
- rewindLastRow();
- replacePendingRatios(tailRatios);
- addPendingRow(fillWidth: true);
- } else if (tailRatios.length >= 4) {
- final firstRowItemCount = (tailRatios.length + 1) ~/ 2;
- final firstRow = tailRatios.sublist(0, firstRowItemCount);
- final secondRow = tailRatios.sublist(firstRowItemCount);
- if (canJustifyFinalRow(firstRow) && canJustifyFinalRow(secondRow)) {
- rewindLastRow();
- replacePendingRatios(firstRow);
- addPendingRow(fillWidth: true);
- replacePendingRatios(secondRow);
- addPendingRow(fillWidth: true);
- }
- }
- }
-
- if (pendingRatios.isNotEmpty) {
- final shouldJustifyFinalRow = canJustifyFinalRow(pendingRatios);
- final singletonHeightFactor =
- pendingRatios.length == 1 && pendingRatios.single < 1
- ? math.min(maximumRowHeightFactor, 1 / pendingRatios.single)
- : 1.0;
- final finalRowHeightFactor = pendingRatios.length == 1
- ? math.min(singletonHeightFactor, maximumFinalRowHeightFactor)
- : limitsFinalRowGrowth
- ? maximumFinalRowHeightFactor
- : 1.0;
- addPendingRow(
- fillWidth: pendingRatios.length > 1 && shouldJustifyFinalRow,
- // Give compact portrait singletons roughly one target-width column;
- // wider tails also obey their configured growth limit.
- raggedHeightFactor: finalRowHeightFactor,
- );
- }
- return UnmodifiableListView(rows);
- }
-}
diff --git a/mobile/apps/photos/lib/models/gallery/justified_layout_strategy.dart b/mobile/apps/photos/lib/models/gallery/justified_layout_strategy.dart
deleted file mode 100644
index 0beb764bb5..0000000000
--- a/mobile/apps/photos/lib/models/gallery/justified_layout_strategy.dart
+++ /dev/null
@@ -1 +0,0 @@
-enum JustifiedLayoutStrategy { comfortLarge, flex }
diff --git a/mobile/apps/photos/lib/models/gallery/justified_layout_tuning.dart b/mobile/apps/photos/lib/models/gallery/justified_layout_tuning.dart
deleted file mode 100644
index 20d819b8cf..0000000000
--- a/mobile/apps/photos/lib/models/gallery/justified_layout_tuning.dart
+++ /dev/null
@@ -1,93 +0,0 @@
-enum FlexLayoutTuningField {
- targetHeightScale,
- maximumHeightFactor,
- minimumNonFinalSingletonAspectRatio,
-}
-
-enum ComfortLargeLayoutTuningField {
- targetHeightScale,
- maximumHeightFactor,
- wideFinalMaximumHeightFactor,
- minimumLandscapeHeightFactor,
-}
-
-class FlexLayoutTuning {
- static const defaults = FlexLayoutTuning();
-
- final double targetHeightScale;
- final double maximumHeightFactor;
- final double minimumNonFinalSingletonAspectRatio;
-
- const FlexLayoutTuning({
- this.targetHeightScale = 1.12,
- this.maximumHeightFactor = 1.6,
- this.minimumNonFinalSingletonAspectRatio = 0.75,
- });
-
- double valueFor(FlexLayoutTuningField field) {
- return switch (field) {
- FlexLayoutTuningField.targetHeightScale => targetHeightScale,
- FlexLayoutTuningField.maximumHeightFactor => maximumHeightFactor,
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio =>
- minimumNonFinalSingletonAspectRatio,
- };
- }
-}
-
-extension FlexLayoutTuningFieldValue on FlexLayoutTuningField {
- double get defaultValue => FlexLayoutTuning.defaults.valueFor(this);
-
- double get maximumValue => 10;
-
- double get minimumValue => switch (this) {
- FlexLayoutTuningField.targetHeightScale ||
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio => 0.1,
- FlexLayoutTuningField.maximumHeightFactor => 1,
- };
-
- bool isValid(double value) =>
- value.isFinite && value >= minimumValue && value <= maximumValue;
-}
-
-class ComfortLargeLayoutTuning {
- static const defaults = ComfortLargeLayoutTuning();
-
- final double targetHeightScale;
- final double maximumHeightFactor;
- final double wideFinalMaximumHeightFactor;
- final double minimumLandscapeHeightFactor;
-
- const ComfortLargeLayoutTuning({
- this.targetHeightScale = 1.5,
- this.maximumHeightFactor = 2.4,
- this.wideFinalMaximumHeightFactor = 1.0,
- this.minimumLandscapeHeightFactor = 0.88,
- });
-
- double valueFor(ComfortLargeLayoutTuningField field) {
- return switch (field) {
- ComfortLargeLayoutTuningField.targetHeightScale => targetHeightScale,
- ComfortLargeLayoutTuningField.maximumHeightFactor => maximumHeightFactor,
- ComfortLargeLayoutTuningField.wideFinalMaximumHeightFactor =>
- wideFinalMaximumHeightFactor,
- ComfortLargeLayoutTuningField.minimumLandscapeHeightFactor =>
- minimumLandscapeHeightFactor,
- };
- }
-}
-
-extension ComfortLargeLayoutTuningFieldValue on ComfortLargeLayoutTuningField {
- double get defaultValue => ComfortLargeLayoutTuning.defaults.valueFor(this);
-
- double get maximumValue => 10;
-
- double get minimumValue => switch (this) {
- ComfortLargeLayoutTuningField.targetHeightScale ||
- ComfortLargeLayoutTuningField.minimumLandscapeHeightFactor => 0.1,
- ComfortLargeLayoutTuningField.maximumHeightFactor ||
- ComfortLargeLayoutTuningField.wideFinalMaximumHeightFactor => 1,
- };
-
- bool isValid(double value) =>
- value.isFinite && value >= minimumValue && value <= maximumValue;
-}
diff --git a/mobile/apps/photos/lib/settings/local_settings.dart b/mobile/apps/photos/lib/settings/local_settings.dart
index 77f12f31dd..0ee9e134aa 100644
--- a/mobile/apps/photos/lib/settings/local_settings.dart
+++ b/mobile/apps/photos/lib/settings/local_settings.dart
@@ -4,8 +4,6 @@ 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';
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';
@@ -60,21 +58,6 @@ class LocalSettings {
static const kCollectionSortPref = "collection_sort_pref";
static const kGalleryGroupType = "gallery_group_type";
static const kGalleryLayoutType = "gallery_layout_type";
- static const kJustifiedLayoutStrategy = "justified_layout_strategy";
- static const kFlexLayoutTuningTargetHeightScale =
- "gallery.justified.flex_full_rows.target_height_scale";
- static const kFlexLayoutTuningMaximumHeightFactor =
- "gallery.justified.flex_full_rows.maximum_height_factor";
- static const kFlexLayoutTuningMinimumNonFinalSingletonAspectRatio =
- "gallery.justified.flex_full_rows.minimum_non_final_singleton_aspect_ratio";
- static const kComfortLargeLayoutTuningTargetHeightScale =
- "gallery.justified.comfort_large.target_height_scale";
- static const kComfortLargeLayoutTuningMaximumHeightFactor =
- "gallery.justified.comfort_large.maximum_height_factor";
- static const kComfortLargeLayoutTuningWideFinalMaximumHeightFactor =
- "gallery.justified.comfort_large.wide_final_maximum_height_factor";
- static const kComfortLargeLayoutTuningMinimumLandscapeHeightFactor =
- "gallery.justified.comfort_large.minimum_landscape_height_factor";
static const kPhotoGridSize = "photo_grid_size";
static const _kisMLLocalIndexingEnabled = "ls.ml_local_indexing";
static const _kLocalGalleryMLLocalIndexingEnabled =
@@ -322,147 +305,6 @@ class LocalSettings {
await _prefs.setBool(migrationKey, true);
}
- JustifiedLayoutStrategy getJustifiedLayoutStrategy() {
- return switch (_prefs.getString(kJustifiedLayoutStrategy)) {
- "flex" ||
- "flexFullRows" ||
- "flexOptimized" => JustifiedLayoutStrategy.flex,
- _ => JustifiedLayoutStrategy.comfortLarge,
- };
- }
-
- Future<void> setJustifiedLayoutStrategy(
- JustifiedLayoutStrategy strategy,
- ) async {
- await _prefs.setString(kJustifiedLayoutStrategy, strategy.name);
- }
-
- FlexLayoutTuning getFlexLayoutTuning() {
- return FlexLayoutTuning(
- targetHeightScale: _validDoubleOrDefault(
- kFlexLayoutTuningTargetHeightScale,
- FlexLayoutTuningField.targetHeightScale.defaultValue,
- FlexLayoutTuningField.targetHeightScale.isValid,
- ),
- maximumHeightFactor: _validDoubleOrDefault(
- kFlexLayoutTuningMaximumHeightFactor,
- FlexLayoutTuningField.maximumHeightFactor.defaultValue,
- FlexLayoutTuningField.maximumHeightFactor.isValid,
- ),
- minimumNonFinalSingletonAspectRatio: _validDoubleOrDefault(
- kFlexLayoutTuningMinimumNonFinalSingletonAspectRatio,
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio.defaultValue,
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio.isValid,
- ),
- );
- }
-
- Future<void> setFlexLayoutTuningValue(
- FlexLayoutTuningField field,
- double value,
- ) async {
- if (!field.isValid(value)) {
- throw ArgumentError.value(value, field.name);
- }
- await _prefs.setDouble(_flexLayoutTuningKey(field), value);
- }
-
- Future<void> resetFlexLayoutTuningValue(FlexLayoutTuningField field) async {
- await _prefs.remove(_flexLayoutTuningKey(field));
- }
-
- Future<void> resetFlexLayoutTuning() async {
- await Future.wait(
- FlexLayoutTuningField.values.map(resetFlexLayoutTuningValue),
- );
- }
-
- ComfortLargeLayoutTuning getComfortLargeLayoutTuning() {
- return ComfortLargeLayoutTuning(
- targetHeightScale: _validDoubleOrDefault(
- kComfortLargeLayoutTuningTargetHeightScale,
- ComfortLargeLayoutTuningField.targetHeightScale.defaultValue,
- ComfortLargeLayoutTuningField.targetHeightScale.isValid,
- ),
- maximumHeightFactor: _validDoubleOrDefault(
- kComfortLargeLayoutTuningMaximumHeightFactor,
- ComfortLargeLayoutTuningField.maximumHeightFactor.defaultValue,
- ComfortLargeLayoutTuningField.maximumHeightFactor.isValid,
- ),
- wideFinalMaximumHeightFactor: _validDoubleOrDefault(
- kComfortLargeLayoutTuningWideFinalMaximumHeightFactor,
- ComfortLargeLayoutTuningField.wideFinalMaximumHeightFactor.defaultValue,
- ComfortLargeLayoutTuningField.wideFinalMaximumHeightFactor.isValid,
- ),
- minimumLandscapeHeightFactor: _validDoubleOrDefault(
- kComfortLargeLayoutTuningMinimumLandscapeHeightFactor,
- ComfortLargeLayoutTuningField.minimumLandscapeHeightFactor.defaultValue,
- ComfortLargeLayoutTuningField.minimumLandscapeHeightFactor.isValid,
- ),
- );
- }
-
- Future<void> setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField field,
- double value,
- ) async {
- if (!field.isValid(value)) {
- throw ArgumentError.value(value, field.name);
- }
- await _prefs.setDouble(_comfortLargeLayoutTuningKey(field), value);
- }
-
- Future<void> resetComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField field,
- ) async {
- await _prefs.remove(_comfortLargeLayoutTuningKey(field));
- }
-
- Future<void> resetComfortLargeLayoutTuning() async {
- await Future.wait(
- ComfortLargeLayoutTuningField.values.map(
- resetComfortLargeLayoutTuningValue,
- ),
- );
- }
-
- double _validDoubleOrDefault(
- String key,
- double fallback,
- bool Function(double) isValid,
- ) {
- final storedValue = _prefs.get(key);
- if (storedValue is! num) return fallback;
- final value = storedValue.toDouble();
- return isValid(value) ? value : fallback;
- }
-
- static String _flexLayoutTuningKey(FlexLayoutTuningField field) {
- return switch (field) {
- FlexLayoutTuningField.targetHeightScale =>
- kFlexLayoutTuningTargetHeightScale,
- FlexLayoutTuningField.maximumHeightFactor =>
- kFlexLayoutTuningMaximumHeightFactor,
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio =>
- kFlexLayoutTuningMinimumNonFinalSingletonAspectRatio,
- };
- }
-
- static String _comfortLargeLayoutTuningKey(
- ComfortLargeLayoutTuningField field,
- ) {
- return switch (field) {
- ComfortLargeLayoutTuningField.targetHeightScale =>
- kComfortLargeLayoutTuningTargetHeightScale,
- ComfortLargeLayoutTuningField.maximumHeightFactor =>
- kComfortLargeLayoutTuningMaximumHeightFactor,
- ComfortLargeLayoutTuningField.wideFinalMaximumHeightFactor =>
- kComfortLargeLayoutTuningWideFinalMaximumHeightFactor,
- ComfortLargeLayoutTuningField.minimumLandscapeHeightFactor =>
- kComfortLargeLayoutTuningMinimumLandscapeHeightFactor,
- };
- }
-
int getPhotoGridSize() {
final storedSize = _prefs.getInt(kPhotoGridSize);
if (storedSize == null || storedSize == 2) return photoGridSizeDefault;
diff --git a/mobile/apps/photos/lib/ui/settings/justified_layout_tuning_screen.dart b/mobile/apps/photos/lib/ui/settings/justified_layout_tuning_screen.dart
deleted file mode 100644
index c939e30628..0000000000
--- a/mobile/apps/photos/lib/ui/settings/justified_layout_tuning_screen.dart
+++ /dev/null
@@ -1,281 +0,0 @@
-import "package:ente_components/ente_components.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/justified_layout_tuning.dart";
-import "package:photos/service_locator.dart";
-import "package:photos/ui/components/menu_section_title.dart";
-
-class JustifiedLayoutTuningScreen extends StatefulWidget {
- const JustifiedLayoutTuningScreen({super.key});
-
- @override
- State<JustifiedLayoutTuningScreen> createState() =>
- _JustifiedLayoutTuningScreenState();
-}
-
-class _JustifiedLayoutTuningScreenState
- extends State<JustifiedLayoutTuningScreen> {
- @override
- Widget build(BuildContext context) {
- final flexTuning = localSettings.getFlexLayoutTuning();
- final comfortLargeTuning = localSettings.getComfortLargeLayoutTuning();
-
- return SettingsPageScaffold(
- title: "Justified layout tuning (i)",
- children: [
- Text(
- "Height values are multipliers of the responsive target row height. "
- "Aspect ratio uses width ÷ height.",
- style: TextStyles.mini.copyWith(
- color: context.componentColors.textLight,
- ),
- ),
- const SizedBox(height: 16),
- const MenuSectionTitle(title: "Flex (i)"),
- MenuGroupComponent(
- items: [
- for (final field in FlexLayoutTuningField.values)
- SettingsItem(
- title: _flexFieldLabel(field),
- trailing: _valueLabel(context, flexTuning.valueFor(field)),
- onTap: () => _editFlexValue(field),
- ),
- SettingsItem(
- title: "Reset all",
- showChevron: false,
- onTap: _resetFlexValues,
- ),
- ],
- ),
- const SizedBox(height: 24),
- const MenuSectionTitle(title: "Comfort Large (i)"),
- MenuGroupComponent(
- items: [
- for (final field in ComfortLargeLayoutTuningField.values)
- SettingsItem(
- title: _comfortLargeFieldLabel(field),
- trailing: _valueLabel(
- context,
- comfortLargeTuning.valueFor(field),
- ),
- onTap: () => _editComfortLargeValue(field),
- ),
- SettingsItem(
- title: "Reset all",
- showChevron: false,
- onTap: _resetComfortLargeValues,
- ),
- ],
- ),
- ],
- );
- }
-
- Widget _valueLabel(BuildContext context, double value) {
- return Text(
- _formatValue(value),
- style: TextStyles.mini.copyWith(color: context.componentColors.textLight),
- );
- }
-
- Future<void> _editFlexValue(FlexLayoutTuningField field) async {
- final tuning = localSettings.getFlexLayoutTuning();
- await _showValueSheet(
- title: _flexFieldLabel(field),
- initialValue: tuning.valueFor(field),
- defaultValue: field.defaultValue,
- isValid: field.isValid,
- validRange: (field.minimumValue, field.maximumValue),
- onSave: (value) async {
- await localSettings.setFlexLayoutTuningValue(field, value);
- _refreshGallery();
- },
- onReset: () async {
- await localSettings.resetFlexLayoutTuningValue(field);
- _refreshGallery();
- },
- );
- }
-
- Future<void> _editComfortLargeValue(
- ComfortLargeLayoutTuningField field,
- ) async {
- final tuning = localSettings.getComfortLargeLayoutTuning();
- await _showValueSheet(
- title: _comfortLargeFieldLabel(field),
- initialValue: tuning.valueFor(field),
- defaultValue: field.defaultValue,
- isValid: field.isValid,
- validRange: (field.minimumValue, field.maximumValue),
- onSave: (value) async {
- await localSettings.setComfortLargeLayoutTuningValue(field, value);
- _refreshGallery();
- },
- onReset: () async {
- await localSettings.resetComfortLargeLayoutTuningValue(field);
- _refreshGallery();
- },
- );
- }
-
- Future<void> _showValueSheet({
- required String title,
- required double initialValue,
- required double defaultValue,
- required bool Function(double) isValid,
- required (double, double) validRange,
- required Future<void> Function(double) onSave,
- required Future<void> Function() onReset,
- }) async {
- await showBottomSheetComponent<void>(
- context: context,
- builder: (_) => _TuningValueSheet(
- title: title,
- initialValue: initialValue,
- defaultValue: defaultValue,
- isValid: isValid,
- validRange: validRange,
- onSave: onSave,
- onReset: onReset,
- ),
- );
- }
-
- Future<void> _resetFlexValues() async {
- await localSettings.resetFlexLayoutTuning();
- _refreshGallery();
- }
-
- Future<void> _resetComfortLargeValues() async {
- await localSettings.resetComfortLargeLayoutTuning();
- _refreshGallery();
- }
-
- void _refreshGallery() {
- if (mounted) setState(() {});
- Bus.instance.fire(GalleryLayoutChangedEvent());
- }
-}
-
-class _TuningValueSheet extends StatefulWidget {
- const _TuningValueSheet({
- required this.title,
- required this.initialValue,
- required this.defaultValue,
- required this.isValid,
- required this.validRange,
- required this.onSave,
- required this.onReset,
- });
-
- final String title;
- final double initialValue;
- final double defaultValue;
- final bool Function(double) isValid;
- final (double, double) validRange;
- final Future<void> Function(double) onSave;
- final Future<void> Function() onReset;
-
- @override
- State<_TuningValueSheet> createState() => _TuningValueSheetState();
-}
-
-class _TuningValueSheetState extends State<_TuningValueSheet> {
- late final TextEditingController _controller;
- late bool _isValid;
-
- @override
- void initState() {
- super.initState();
- final text = _formatValue(widget.initialValue);
- _controller = TextEditingController(text: text);
- _controller.selection = TextSelection(
- baseOffset: 0,
- extentOffset: text.length,
- );
- _isValid = _validate(text) != null;
- }
-
- @override
- void dispose() {
- _controller.dispose();
- super.dispose();
- }
-
- @override
- Widget build(BuildContext context) {
- return BottomSheetComponent(
- title: widget.title,
- isKeyboardAware: true,
- content: TextInputComponent(
- controller: _controller,
- autofocus: true,
- keyboardType: const TextInputType.numberWithOptions(decimal: true),
- textInputAction: TextInputAction.done,
- message: _isValid
- ? "Default: ${_formatValue(widget.defaultValue)}"
- : "Enter a value from ${_formatValue(widget.validRange.$1)} "
- "to ${_formatValue(widget.validRange.$2)}",
- messageType: _isValid
- ? TextInputComponentMessageType.helper
- : TextInputComponentMessageType.error,
- onChanged: (value) {
- final isValid = _validate(value) != null;
- if (_isValid != isValid) setState(() => _isValid = isValid);
- },
- onSubmit: (_) => _save(),
- ),
- actions: [
- ButtonComponent(
- label: context.strings.save,
- isDisabled: !_isValid,
- onTap: _save,
- ),
- ButtonComponent(
- label: context.strings.resetToDefault,
- variant: ButtonComponentVariant.secondary,
- onTap: _reset,
- ),
- ],
- );
- }
-
- double? _validate(String text) {
- final value = double.tryParse(text.trim());
- return value != null && widget.isValid(value) ? value : null;
- }
-
- Future<void> _save() async {
- final value = _validate(_controller.text);
- if (value == null) return;
- await widget.onSave(value);
- if (mounted) Navigator.of(context).pop();
- }
-
- Future<void> _reset() async {
- await widget.onReset();
- if (mounted) Navigator.of(context).pop();
- }
-}
-
-String _flexFieldLabel(FlexLayoutTuningField field) => switch (field) {
- FlexLayoutTuningField.targetHeightScale => "Target height scale",
- FlexLayoutTuningField.maximumHeightFactor => "Maximum height factor",
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio =>
- "Minimum non-final singleton aspect ratio",
-};
-
-String _comfortLargeFieldLabel(ComfortLargeLayoutTuningField field) =>
- switch (field) {
- ComfortLargeLayoutTuningField.targetHeightScale => "Target height scale",
- ComfortLargeLayoutTuningField.maximumHeightFactor =>
- "Maximum height factor",
- ComfortLargeLayoutTuningField.wideFinalMaximumHeightFactor =>
- "Wide final maximum height factor",
- ComfortLargeLayoutTuningField.minimumLandscapeHeightFactor =>
- "Minimum landscape height factor",
- };
-
-String _formatValue(double value) => value.toString();
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 f6c01b7bb4..b765ef80dd 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
@@ -6,7 +6,6 @@ import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
import "package:photos/core/configuration.dart";
-import "package:photos/models/gallery/gallery_layout_config.dart";
import "package:photos/service_locator.dart";
import "package:photos/ui/settings/about/about_us_page.dart";
import "package:photos/ui/settings/account/account_settings_page.dart";
@@ -28,7 +27,6 @@ class SettingsSearchRegistry {
final hasLoggedIn = Configuration.instance.isLoggedIn();
final isLocalGallery = isLocalGalleryMode;
final showThemeControls = Platform.isAndroid || kDebugMode;
- const showJustifiedLayout = isJustifiedLayoutAvailable;
final items = <SettingsSearchItem>[];
if (hasLoggedIn && !isLocalGallery) {
@@ -317,29 +315,22 @@ class SettingsSearchRegistry {
routeBuilder: (_) =>
const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: false),
isSubPage: true,
- keywords: [
- "grid size",
- "group by",
- "layout",
- if (showJustifiedLayout) "justified",
- ],
+ keywords: ["grid size", "group by", "layout", "justified"],
),
);
- if (showJustifiedLayout) {
- items.add(
- SettingsSearchItem(
- title: l10n.layout,
- subtitle: l10n.gallery,
- sectionPath: "${l10n.appearance} > ${l10n.gallery}",
- icon: HugeIcons.strokeRoundedDashboardSquare02,
- routeBuilder: (_) =>
- const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: false),
- isSubPage: true,
- keywords: ["layout", "grid", "justified"],
- ),
- );
- }
+ items.add(
+ SettingsSearchItem(
+ title: l10n.layout,
+ subtitle: l10n.gallery,
+ sectionPath: "${l10n.appearance} > ${l10n.gallery}",
+ icon: HugeIcons.strokeRoundedDashboardSquare02,
+ routeBuilder: (_) =>
+ const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: false),
+ isSubPage: true,
+ keywords: ["layout", "grid", "justified"],
+ ),
+ );
items.add(
SettingsSearchItem(
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index e80c3151cf..6f53bf5f12 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -19,7 +19,6 @@ import 'package:photos/events/tab_changed_event.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file_load_result.dart';
import "package:photos/models/gallery/gallery_groups.dart";
-import "package:photos/models/gallery/gallery_layout_config.dart";
import "package:photos/models/gallery_type.dart";
import 'package:photos/models/selected_files.dart';
import "package:photos/service_locator.dart" show localSettings;
@@ -396,7 +395,6 @@ class GalleryState extends State<Gallery> {
showGallerySettingsCTA: widget.showGallerySettingsCTA,
groupHeaderAction: widget.groupHeaderAction,
layoutTypeOverride: widget.layoutTypeOverride,
- justifiedLayoutAvailable: isJustifiedLayoutAvailable,
);
galleryGroups = groups;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/justified_layout_strategy_label.dart b/mobile/apps/photos/lib/ui/viewer/gallery/justified_layout_strategy_label.dart
deleted file mode 100644
index cb0e8b3ba0..0000000000
--- a/mobile/apps/photos/lib/ui/viewer/gallery/justified_layout_strategy_label.dart
+++ /dev/null
@@ -1,12 +0,0 @@
-import "package:ente_strings/ente_strings.dart";
-import "package:flutter/widgets.dart";
-import "package:photos/models/gallery/justified_layout_strategy.dart";
-
-extension JustifiedLayoutStrategyLabel on JustifiedLayoutStrategy {
- String label(BuildContext context) => switch (this) {
- JustifiedLayoutStrategy.comfortLarge =>
- "${context.strings.layoutJustifiedComfort} Large (i)",
- JustifiedLayoutStrategy.flex =>
- "${context.strings.layoutJustifiedFlex} (i)",
- };
-}
diff --git a/mobile/apps/photos/test/models/flex_layout_test.dart b/mobile/apps/photos/test/models/flex_layout_test.dart
index 81ea8b3fcb..46aaad85e6 100644
--- a/mobile/apps/photos/test/models/flex_layout_test.dart
+++ b/mobile/apps/photos/test/models/flex_layout_test.dart
@@ -116,7 +116,7 @@ void main() {
expect(wideLandscapeRow.itemWidths, hasLength(5));
});
- test("fills a final row until its configurable maximum height", () {
+ test("fills a final row up to its maximum height", () {
final fitted = _rows([0.75, 0.75], targetHeight: 200).single;
expect(fitted.height, closeTo(400 / 1.5, 1e-9));
expect(_occupiedWidth(fitted), closeTo(402, 1e-9));
@@ -124,15 +124,6 @@ void main() {
final capped = _rows([0.75, 0.75], width: 1024, targetHeight: 320).single;
expect(capped.height, 512);
expect(_occupiedWidth(capped), lessThan(1024));
-
- final relaxed = _rows(
- [0.75, 0.75],
- width: 1024,
- targetHeight: 320,
- maximumHeightFactor: 2,
- ).single;
- expect(relaxed.height, 640);
- expect(relaxed.height, greaterThan(capped.height));
});
test(
@@ -159,6 +150,12 @@ void main() {
);
test("normalizes invalid ratios and handles empty groups", () {
+ expect(FlexLayoutCalculator.aspectRatioForDimensions(0, 100), 1);
+ expect(FlexLayoutCalculator.aspectRatioForDimensions(100, 0), 1);
+ expect(FlexLayoutCalculator.aspectRatioForDimensions(-1, 100), 1);
+ expect(FlexLayoutCalculator.aspectRatioForDimensions(4, 3), 4 / 3);
+ expect(FlexLayoutCalculator.aspectRatioForDimensions(1, 100), 1 / 3);
+ expect(FlexLayoutCalculator.aspectRatioForDimensions(100, 1), 4);
final rows = _rows([0, double.nan, double.infinity, 0.01, 100]);
expect(rows.last.lastIndex, 4);
@@ -168,30 +165,18 @@ void main() {
);
expect(_rows([]), isEmpty);
});
-
- test("rejects invalid tuning", () {
- expect(() => _rows([1], maximumHeightFactor: 0.9), throwsArgumentError);
- expect(
- () => _rows([1], minimumNonFinalSingletonAspectRatio: 0),
- throwsArgumentError,
- );
- });
}
List<JustifiedRowLayout> _rows(
List<double> ratios, {
double width = 402,
double? targetHeight,
- double maximumHeightFactor = 1.6,
- double minimumNonFinalSingletonAspectRatio = 0.75,
}) {
return FlexLayoutCalculator.computeRows(
aspectRatios: ratios,
availableWidth: width,
targetRowHeight: targetHeight ?? (width < 600 ? 200 : 320),
spacing: 2,
- maximumRowHeightFactor: maximumHeightFactor,
- minimumNonFinalSingletonAspectRatio: minimumNonFinalSingletonAspectRatio,
);
}
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 5560a6c651..6554c38c52 100644
--- a/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
+++ b/mobile/apps/photos/test/models/gallery_groups_justified_test.dart
@@ -12,8 +12,6 @@ import "package:photos/models/gallery/fixed_extent_section_layout.dart";
import "package:photos/models/gallery/gallery_groups.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/metadata/file_magic.dart";
import "package:photos/service_locator.dart";
import "package:photos/settings/local_settings.dart";
@@ -49,11 +47,6 @@ void main() {
setUp(() async {
await localSettings.setGalleryLayoutType(GalleryLayoutType.justified);
- await localSettings.setJustifiedLayoutStrategy(
- JustifiedLayoutStrategy.comfortLarge,
- );
- await localSettings.resetFlexLayoutTuning();
- await localSettings.resetComfortLargeLayoutTuning();
await localSettings.setPhotoGridSize(4);
});
@@ -120,14 +113,23 @@ void main() {
);
}
- for (final file in expectedFiles) {
- final fileOffset = groups.getOffsetOfFile(file);
- expect(fileOffset, isNotNull);
- expect(groups.getFileAtScrollOffset(fileOffset!), same(file));
- expect(
- groups.getOffsetOfGroupContainingFile(file),
- closeTo(justifiedSection.minOffset, 1e-9),
- );
+ for (final row in justifiedSection.rows) {
+ for (var index = row.firstIndex; index <= row.lastIndex; index++) {
+ final file = expectedFiles[index];
+ final fileOffset = groups.getOffsetOfFile(file);
+ expect(
+ fileOffset,
+ closeTo(justifiedSection.bodyMinOffset + row.minOffset, 1e-9),
+ );
+ expect(
+ groups.getFileAtScrollOffset(fileOffset!),
+ same(expectedFiles[row.firstIndex]),
+ );
+ expect(
+ groups.getOffsetOfGroupContainingFile(file),
+ closeTo(justifiedSection.minOffset, 1e-9),
+ );
+ }
}
expectedFirstChildIndex = justifiedSection.lastIndex + 1;
@@ -136,7 +138,7 @@ void main() {
}
});
- test("routes justified galleries through the selected strategy", () async {
+ test("justified uses Flex with its production defaults", () {
final files = List.generate(
4,
(index) => _file(
@@ -146,117 +148,20 @@ void main() {
height: 16,
),
);
- await localSettings.setPhotoGridSize(3);
- await localSettings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- 1,
- );
- GalleryGroups groups() => _galleryGroups(
+ final 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(3);
- 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(3);
- 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);
+ final section = groups.groupLayouts.single as JustifiedSectionLayout;
+ expect(section.rows.map((row) => row.itemWidths.length), [3, 1]);
+ _expectRowsCoverFiles(section, files.length);
});
test(
"headerless justified remains one continuous group past grid chunks",
- () async {
- await localSettings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- 1,
- );
+ () {
const fileCount = 100;
final files = List<EnteFile>.generate(
fileCount,
@@ -289,11 +194,10 @@ void main() {
expect(section.bodyMinOffset, GalleryGroups.spacing);
_expectRowsCoverFiles(section, fileCount);
- final rowAcrossLegacyBoundary = section.rows.singleWhere(
- (row) => row.firstIndex <= 19 && row.lastIndex >= 20,
+ expect(
+ section.rows.any((row) => row.firstIndex < 20 && row.lastIndex >= 20),
+ isTrue,
);
- expect(rowAcrossLegacyBoundary.firstIndex, 18);
- expect(rowAcrossLegacyBoundary.lastIndex, 20);
for (final row in section.rows) {
final firstFileInRow = files[row.firstIndex];
@@ -330,14 +234,10 @@ void main() {
}
await localSettings.setPhotoGridSize(3);
- await localSettings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- 1,
- );
- expect(rowHeight(), 320);
+ expect(rowHeight(), closeTo(320 * 1.12 * 1.6, 1e-9));
await localSettings.setPhotoGridSize(4);
- expect(rowHeight(), 320);
+ expect(rowHeight(), closeTo(320 * 1.12 * 1.6, 1e-9));
},
);
@@ -369,11 +269,16 @@ void main() {
final context = tester.element(
find.byKey(const ValueKey("justified-builder-context")),
);
- final rowWidget =
- section.builder(context, section.bodyFirstIndex) as JustifiedGridRow;
- final galleryTiles = rowWidget.children.map(
- (child) => (child as RepaintBoundary).child! as GalleryFileWidget,
- );
+ final galleryTiles = [
+ for (
+ var index = section.bodyFirstIndex;
+ index <= section.lastIndex;
+ index++
+ )
+ for (final child
+ in (section.builder(context, index) as JustifiedGridRow).children)
+ (child as RepaintBoundary).child! as GalleryFileWidget,
+ ];
expect(galleryTiles, hasLength(files.length));
expect(
@@ -442,37 +347,28 @@ void main() {
expect(groups.getOffsetOfFile(replacement), originalGeometry?.rowOffset);
});
- test(
- "a layout override keeps an embedded gallery on the fixed grid",
- () async {
- await localSettings.setJustifiedLayoutStrategy(
- JustifiedLayoutStrategy.flex,
- );
- final files = List<EnteFile>.generate(
- 12,
- (index) => _file(
- index: index,
- creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
- width: 400,
- height: 100,
- ),
- growable: false,
- );
+ test("a layout override keeps an embedded gallery on the fixed grid", () {
+ final files = List<EnteFile>.generate(
+ 12,
+ (index) => _file(
+ index: index,
+ creationTime: DateTime(2026, 8, 19).microsecondsSinceEpoch,
+ width: 400,
+ height: 100,
+ ),
+ growable: false,
+ );
- final groups = _galleryGroups(
- files: files,
- groupType: GroupType.none,
- groupHeaderExtent: GalleryGroups.spacing,
- layoutTypeOverride: GalleryLayoutType.grid,
- );
+ final groups = _galleryGroups(
+ files: files,
+ groupType: GroupType.none,
+ groupHeaderExtent: GalleryGroups.spacing,
+ layoutTypeOverride: GalleryLayoutType.grid,
+ );
- expect(groups.layoutType, GalleryLayoutType.grid);
- expect(
- groups.groupLayouts,
- everyElement(isA<FixedExtentSectionLayout>()),
- );
- },
- );
+ expect(groups.layoutType, GalleryLayoutType.grid);
+ expect(groups.groupLayouts, everyElement(isA<FixedExtentSectionLayout>()));
+ });
}
GalleryGroups _galleryGroups({
@@ -493,7 +389,6 @@ GalleryGroups _galleryGroups({
groupHeaderExtent: groupHeaderExtent,
showSelectAll: false,
layoutTypeOverride: layoutTypeOverride,
- justifiedLayoutAvailable: true,
);
}
diff --git a/mobile/apps/photos/test/models/justified_layout_test.dart b/mobile/apps/photos/test/models/justified_layout_test.dart
index ec06f40fb1..836c0984f8 100644
--- a/mobile/apps/photos/test/models/justified_layout_test.dart
+++ b/mobile/apps/photos/test/models/justified_layout_test.dart
@@ -3,356 +3,6 @@ import "package:flutter_test/flutter_test.dart";
import "package:photos/models/gallery/justified_layout.dart";
void main() {
- group("JustifiedLayoutCalculator", () {
- test("uses a square fallback for missing or invalid dimensions", () {
- expect(JustifiedLayoutCalculator.aspectRatioForDimensions(0, 0), 1);
- expect(JustifiedLayoutCalculator.aspectRatioForDimensions(0, 100), 1);
- expect(JustifiedLayoutCalculator.aspectRatioForDimensions(100, 0), 1);
- expect(JustifiedLayoutCalculator.aspectRatioForDimensions(-100, 50), 1);
- expect(JustifiedLayoutCalculator.aspectRatioForDimensions(100, -50), 1);
- });
-
- test("preserves normal ratios and clamps extreme dimensions", () {
- expect(JustifiedLayoutCalculator.aspectRatioForDimensions(4, 3), 4 / 3);
- expect(JustifiedLayoutCalculator.aspectRatioForDimensions(1, 100), 1 / 3);
- expect(JustifiedLayoutCalculator.aspectRatioForDimensions(100, 1), 4);
- });
-
- test("justified rows conserve the full available width", () {
- const availableWidth = 400.0;
- const spacing = 2.0;
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [1, 1, 1],
- availableWidth: availableWidth,
- targetRowHeight: 100,
- spacing: spacing,
- );
-
- expect(rows, hasLength(1));
- final row = rows.single;
- expect(row.itemWidths, hasLength(3));
- expect(_occupiedWidth(row, spacing), closeTo(availableWidth, 1e-9));
- });
-
- test("a two-item final row expands to the full available width", () {
- const availableWidth = 400.0;
- const spacing = 2.0;
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [1, 1],
- availableWidth: availableWidth,
- targetRowHeight: 100,
- spacing: spacing,
- );
-
- expect(rows, hasLength(1));
- final row = rows.single;
- expect(row.itemWidths, hasLength(2));
- expect(row.itemWidths, everyElement(row.height));
- expect(_occupiedWidth(row, spacing), closeTo(availableWidth, 1e-9));
- });
-
- test("caps wide final-row growth and leaves trailing space", () {
- for (final testCase in const [
- (width: 744.0, ratios: [0.75, 0.75]),
- (width: 1024.0, ratios: [0.75, 0.75, 0.75]),
- ]) {
- final row = JustifiedLayoutCalculator.computeRows(
- aspectRatios: testCase.ratios,
- availableWidth: testCase.width,
- targetRowHeight: 320,
- spacing: 2,
- ).single;
-
- expect(row.height, 320, reason: "available width ${testCase.width}");
- expect(
- _occupiedWidth(row, 2),
- lessThan(testCase.width),
- reason: "available width ${testCase.width}",
- );
- }
- });
-
- test("sizes final singletons by orientation and caps extremes", () {
- JustifiedRowLayout rowFor(
- double ratio, {
- double width = 402,
- double targetHeight = 200,
- }) {
- return JustifiedLayoutCalculator.computeRows(
- aspectRatios: [ratio],
- availableWidth: width,
- targetRowHeight: targetHeight,
- spacing: 2,
- ).single;
- }
-
- final portrait = rowFor(9 / 16);
- final extremePortrait = rowFor(0.25);
- final landscape = rowFor(3 / 2);
- final mediumPortrait = rowFor(0.5, width: 744, targetHeight: 320);
- final minimumTappablePortrait = rowFor(
- 0.25,
- width: 600,
- targetHeight: (600 - 10) / 6,
- );
-
- expect(portrait.itemWidths.single, 200);
- expect(extremePortrait.height, 200 * 2.4);
- expect(
- extremePortrait.itemWidths.single / extremePortrait.height,
- closeTo(1 / 3, 1e-9),
- );
- expect(landscape.height, 200);
- expect(mediumPortrait.height, 320);
- expect(mediumPortrait.itemWidths.single, 160);
- expect(minimumTappablePortrait.height, 144);
- expect(minimumTappablePortrait.itemWidths.single, 48);
- });
-
- test("rebalances a compact portrait orphan", () {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: List.filled(7, 9 / 16),
- availableWidth: 393,
- targetRowHeight: (393 - 2) / 2,
- spacing: 2,
- );
-
- expect(rows.map((row) => row.itemWidths.length), [3, 2, 2]);
- });
-
- test("does not create oversized tablet rows to avoid an orphan", () {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: List.filled(5, 0.5),
- availableWidth: 744,
- targetRowHeight: 320,
- spacing: 2,
- );
-
- expect(rows.map((row) => row.itemWidths.length), [4, 1]);
- });
-
- test("keeps a tappable portrait with the following panorama", () {
- const availableWidth = 393.0;
- const spacing = 2.0;
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [0.85, 4.0],
- availableWidth: availableWidth,
- targetRowHeight: 130,
- spacing: spacing,
- );
-
- expect(rows, hasLength(1));
- final row = rows.single;
- expect(row.firstIndex, 0);
- expect(row.lastIndex, 1);
- expect(row.height, closeTo(391 / 4.85, 1e-9));
- expect(row.height, greaterThanOrEqualTo(48));
- expect(row.itemWidths, everyElement(greaterThanOrEqualTo(48)));
- expect(_occupiedWidth(row, spacing), closeTo(availableWidth, 1e-9));
- });
-
- test("does not squeeze an extreme item into a mixed row", () {
- for (final ratios in const [
- [0.25, 4.0],
- [4.0, 0.25],
- ]) {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: ratios,
- availableWidth: 430,
- targetRowHeight: 106,
- spacing: 2,
- );
-
- expect(rows, hasLength(2));
- expect(rows.first.lastIndex, 0);
- expect(rows.last.firstIndex, 1);
- for (final row in rows) {
- expect(row.height, greaterThanOrEqualTo(48));
- expect(row.itemWidths, everyElement(greaterThanOrEqualTo(48)));
- }
- }
- });
-
- test("does not make a justified row shorter than the tap target", () {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [4.0, 4.0],
- availableWidth: 360,
- targetRowHeight: 80,
- spacing: 2,
- );
-
- expect(rows, hasLength(2));
- for (final row in rows) {
- expect(row.height, greaterThanOrEqualTo(48));
- expect(row.itemWidths, everyElement(greaterThanOrEqualTo(48)));
- }
- });
-
- test("accepts a justified row exactly at the tap target", () {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [1.0, 4.0],
- availableWidth: 242,
- targetRowHeight: 100,
- spacing: 2,
- );
-
- expect(rows, hasLength(1));
- expect(rows.single.height, 48);
- expect(rows.single.itemWidths, [48, 192]);
- });
-
- test("raises a sparse row to the minimum tappable height", () {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [4.0],
- availableWidth: 400,
- targetRowHeight: 30,
- spacing: 2,
- );
-
- expect(rows, hasLength(1));
- expect(rows.single.height, 48);
- expect(rows.single.itemWidths, [192]);
- });
-
- test("caps row density based on available width", () {
- for (final testCase in const [
- (width: 393.0, maximumItems: 3),
- (width: 599.9, maximumItems: 3),
- (width: 600.0, maximumItems: 4),
- (width: 1007.9, maximumItems: 4),
- (width: 1008.0, maximumItems: 5),
- ]) {
- final targetHeight =
- (testCase.width - 2 * (testCase.maximumItems - 1)) /
- testCase.maximumItems;
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: List.filled(testCase.maximumItems * 2, 1 / 3),
- availableWidth: testCase.width,
- targetRowHeight: targetHeight,
- spacing: 2,
- );
-
- expect(rows.map((row) => row.itemWidths.length), [
- testCase.maximumItems,
- testCase.maximumItems,
- ], reason: "available width ${testCase.width}");
- expect(
- rows.first.height,
- closeTo(3 * targetHeight, 1e-9),
- reason: "non-final row at width ${testCase.width}",
- );
- final expectedFinalHeight = testCase.width < 600
- ? 3 * targetHeight
- : targetHeight;
- expect(
- rows.last.height,
- closeTo(expectedFinalHeight, 1e-9),
- reason: "final row at width ${testCase.width}",
- );
- }
- });
-
- test("keeps cramped landscape rows independent of responsive cap", () {
- for (final testCase in const [
- (
- ratios: [4 / 3, 4 / 3, 4 / 3],
- width: 393.0,
- targetHeight: (393 - 4) / 3,
- rowCounts: [2, 1],
- ),
- (
- ratios: [1.0, 1.0, 1.0, 1.0],
- width: 1024.0,
- targetHeight: 320.0,
- rowCounts: [3, 1],
- ),
- ]) {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: testCase.ratios,
- availableWidth: testCase.width,
- targetRowHeight: testCase.targetHeight,
- spacing: 2,
- );
-
- expect(
- rows.map((row) => row.itemWidths.length),
- testCase.rowCounts,
- reason: "available width ${testCase.width}",
- );
- expect(rows.last.height, testCase.targetHeight);
- }
- });
-
- test("applies configurable Comfort row-height policies", () {
- final wideTail = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [0.75, 0.75],
- availableWidth: 1024,
- targetRowHeight: 320,
- spacing: 2,
- wideFinalMaximumRowHeightFactor: 2,
- ).single;
- expect(wideTail.height, 640);
-
- final landscapes = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [4 / 3, 4 / 3, 4 / 3],
- availableWidth: 393,
- targetRowHeight: (393 - 4) / 3,
- spacing: 2,
- minimumLandscapeRowHeightFactor: 0.5,
- );
- expect(landscapes.single.itemWidths, hasLength(3));
-
- final portrait = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [1 / 3],
- availableWidth: 393,
- targetRowHeight: 130,
- spacing: 2,
- maximumRowHeightFactor: 3,
- ).single;
- expect(portrait.height, 390);
- });
-
- test("merges a final portrait with a tappable two-item row", () {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [1.0, 1.0, 0.5],
- availableWidth: 393,
- targetRowHeight: (393 - 2) / 2,
- spacing: 2,
- );
-
- expect(rows, hasLength(1));
- expect(rows.single.itemWidths, hasLength(3));
- });
-
- test("rebalances a wide orphan when replacement rows stay bounded", () {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [0.8, 0.8, 0.8, 0.4, 2.0],
- availableWidth: 600,
- targetRowHeight: 200,
- spacing: 2,
- wideFinalMaximumRowHeightFactor: 1.25,
- );
-
- expect(rows.map((row) => row.itemWidths.length), [3, 2]);
- for (final row in rows) {
- expect(row.height, lessThanOrEqualTo(250));
- expect(_occupiedWidth(row, 2), closeTo(600, 1e-9));
- }
- });
-
- test("forced non-final singleton uses the target row height", () {
- final rows = JustifiedLayoutCalculator.computeRows(
- aspectRatios: const [0.5, 4],
- availableWidth: 393,
- targetRowHeight: 130,
- spacing: 2,
- );
-
- expect(rows, hasLength(2));
- expect(rows.first.height, 130);
- });
- });
-
group("JustifiedSectionLayout", () {
const rows = [
JustifiedRowLayout(
@@ -408,8 +58,3 @@ void main() {
});
});
}
-
-double _occupiedWidth(JustifiedRowLayout row, double spacing) {
- return row.itemWidths.fold<double>(0, (sum, width) => sum + width) +
- spacing * (row.itemWidths.length - 1);
-}
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 a584e8cbba..8f583810f7 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,5 @@
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";
@@ -85,263 +83,4 @@ void main() {
"justified",
);
});
-
- test(
- "justified strategy defaults to Comfort Large and persists Flex",
- () async {
- SharedPreferences.setMockInitialValues({});
- final preferences = await SharedPreferences.getInstance();
- final settings = LocalSettings(preferences);
- expect(
- settings.getJustifiedLayoutStrategy(),
- JustifiedLayoutStrategy.comfortLarge,
- );
- await settings.setJustifiedLayoutStrategy(JustifiedLayoutStrategy.flex);
- expect(
- LocalSettings(preferences).getJustifiedLayoutStrategy(),
- JustifiedLayoutStrategy.flex,
- );
- },
- );
-
- test("Flex reads former Full Rows and optimized selections", () async {
- for (final storedStrategy in ["flexFullRows", "flexOptimized"]) {
- SharedPreferences.setMockInitialValues({
- LocalSettings.kJustifiedLayoutStrategy: storedStrategy,
- });
- final settings = LocalSettings(await SharedPreferences.getInstance());
-
- expect(
- settings.getJustifiedLayoutStrategy(),
- JustifiedLayoutStrategy.flex,
- );
- }
- });
-
- group("justified layout tuning", () {
- test("uses defaults when tuning values are absent", () async {
- SharedPreferences.setMockInitialValues({});
- final settings = LocalSettings(await SharedPreferences.getInstance());
-
- final flex = settings.getFlexLayoutTuning();
- for (final field in FlexLayoutTuningField.values) {
- expect(flex.valueFor(field), FlexLayoutTuning.defaults.valueFor(field));
- }
-
- final comfortLarge = settings.getComfortLargeLayoutTuning();
- for (final field in ComfortLargeLayoutTuningField.values) {
- expect(
- comfortLarge.valueFor(field),
- ComfortLargeLayoutTuning.defaults.valueFor(field),
- );
- }
- });
-
- test("persists arbitrary valid decimal values", () async {
- SharedPreferences.setMockInitialValues({});
- final preferences = await SharedPreferences.getInstance();
- final settings = LocalSettings(preferences);
- const flexValues = <FlexLayoutTuningField, double>{
- FlexLayoutTuningField.targetHeightScale: 2.718281828,
- FlexLayoutTuningField.maximumHeightFactor: 9.125,
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio: 0.8125,
- };
- const comfortLargeValues = <ComfortLargeLayoutTuningField, double>{
- ComfortLargeLayoutTuningField.targetHeightScale: 0.123456789,
- ComfortLargeLayoutTuningField.maximumHeightFactor: 8.75,
- ComfortLargeLayoutTuningField.wideFinalMaximumHeightFactor: 3.14159,
- ComfortLargeLayoutTuningField.minimumLandscapeHeightFactor: 5.625,
- };
-
- for (final entry in flexValues.entries) {
- await settings.setFlexLayoutTuningValue(entry.key, entry.value);
- }
- for (final entry in comfortLargeValues.entries) {
- await settings.setComfortLargeLayoutTuningValue(entry.key, entry.value);
- }
-
- final reloadedSettings = LocalSettings(preferences);
- final flex = reloadedSettings.getFlexLayoutTuning();
- for (final entry in flexValues.entries) {
- expect(flex.valueFor(entry.key), entry.value);
- }
- final comfortLarge = reloadedSettings.getComfortLargeLayoutTuning();
- for (final entry in comfortLargeValues.entries) {
- expect(comfortLarge.valueFor(entry.key), entry.value);
- }
- });
-
- test("falls back independently for corrupt tuning values", () async {
- SharedPreferences.setMockInitialValues({
- LocalSettings.kFlexLayoutTuningTargetHeightScale: 0.0,
- LocalSettings.kFlexLayoutTuningMaximumHeightFactor: 0.99,
- LocalSettings.kFlexLayoutTuningMinimumNonFinalSingletonAspectRatio:
- "invalid",
- LocalSettings.kComfortLargeLayoutTuningTargetHeightScale: 0.0,
- LocalSettings.kComfortLargeLayoutTuningMaximumHeightFactor: 0.99,
- LocalSettings.kComfortLargeLayoutTuningWideFinalMaximumHeightFactor:
- double.infinity,
- LocalSettings.kComfortLargeLayoutTuningMinimumLandscapeHeightFactor:
- 10.5,
- });
- final settings = LocalSettings(await SharedPreferences.getInstance());
-
- final flex = settings.getFlexLayoutTuning();
- for (final field in FlexLayoutTuningField.values) {
- expect(flex.valueFor(field), FlexLayoutTuning.defaults.valueFor(field));
- }
- final comfortLarge = settings.getComfortLargeLayoutTuning();
- for (final field in ComfortLargeLayoutTuningField.values) {
- expect(
- comfortLarge.valueFor(field),
- ComfortLargeLayoutTuning.defaults.valueFor(field),
- );
- }
- });
-
- test("keeps strategy tuning isolated", () async {
- SharedPreferences.setMockInitialValues({});
- final settings = LocalSettings(await SharedPreferences.getInstance());
-
- await settings.setFlexLayoutTuningValue(
- FlexLayoutTuningField.targetHeightScale,
- 1.91,
- );
- expect(
- settings.getComfortLargeLayoutTuning().valueFor(
- ComfortLargeLayoutTuningField.targetHeightScale,
- ),
- ComfortLargeLayoutTuning.defaults.targetHeightScale,
- );
-
- await settings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- 2.73,
- );
- expect(
- settings.getFlexLayoutTuning().valueFor(
- FlexLayoutTuningField.targetHeightScale,
- ),
- 1.91,
- );
- });
-
- test("resets one field without changing its siblings", () async {
- SharedPreferences.setMockInitialValues({});
- final settings = LocalSettings(await SharedPreferences.getInstance());
- await settings.setFlexLayoutTuningValue(
- FlexLayoutTuningField.targetHeightScale,
- 1.91,
- );
- await settings.setFlexLayoutTuningValue(
- FlexLayoutTuningField.maximumHeightFactor,
- 2.73,
- );
- await settings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- 1.41,
- );
- await settings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.maximumHeightFactor,
- 3.41,
- );
- await settings.resetFlexLayoutTuningValue(
- FlexLayoutTuningField.targetHeightScale,
- );
- await settings.resetComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.targetHeightScale,
- );
- final flex = settings.getFlexLayoutTuning();
- expect(
- flex.targetHeightScale,
- FlexLayoutTuning.defaults.targetHeightScale,
- );
- expect(flex.maximumHeightFactor, 2.73);
- final comfortLarge = settings.getComfortLargeLayoutTuning();
- expect(
- comfortLarge.targetHeightScale,
- ComfortLargeLayoutTuning.defaults.targetHeightScale,
- );
- expect(comfortLarge.maximumHeightFactor, 3.41);
- });
-
- test("reset all removes only the selected strategy keys", () async {
- SharedPreferences.setMockInitialValues({});
- final preferences = await SharedPreferences.getInstance();
- final settings = LocalSettings(preferences);
- for (final field in FlexLayoutTuningField.values) {
- await settings.setFlexLayoutTuningValue(
- field,
- field == FlexLayoutTuningField.maximumHeightFactor ? 2.0 : 1.5,
- );
- }
- for (final field in ComfortLargeLayoutTuningField.values) {
- await settings.setComfortLargeLayoutTuningValue(field, switch (field) {
- ComfortLargeLayoutTuningField.maximumHeightFactor ||
- ComfortLargeLayoutTuningField.wideFinalMaximumHeightFactor => 2.0,
- _ => 1.5,
- });
- }
-
- await settings.resetFlexLayoutTuning();
-
- expect(
- preferences.containsKey(
- LocalSettings.kFlexLayoutTuningTargetHeightScale,
- ),
- isFalse,
- );
- expect(
- preferences.containsKey(
- LocalSettings.kFlexLayoutTuningMaximumHeightFactor,
- ),
- isFalse,
- );
- expect(
- preferences.containsKey(
- LocalSettings.kFlexLayoutTuningMinimumNonFinalSingletonAspectRatio,
- ),
- isFalse,
- );
- expect(
- preferences.getKeys().where((key) => key.contains(".comfort_large.")),
- isNotEmpty,
- );
-
- await settings.resetComfortLargeLayoutTuning();
-
- expect(
- preferences.getKeys().where((key) => key.contains(".comfort_large.")),
- isEmpty,
- );
- });
-
- test("rejects invalid values without persisting them", () async {
- SharedPreferences.setMockInitialValues({});
- final settings = LocalSettings(await SharedPreferences.getInstance());
-
- await expectLater(
- settings.setFlexLayoutTuningValue(
- FlexLayoutTuningField.minimumNonFinalSingletonAspectRatio,
- 0,
- ),
- throwsArgumentError,
- );
- await expectLater(
- settings.setComfortLargeLayoutTuningValue(
- ComfortLargeLayoutTuningField.maximumHeightFactor,
- 0.999,
- ),
- throwsArgumentError,
- );
- expect(
- settings.getFlexLayoutTuning().minimumNonFinalSingletonAspectRatio,
- FlexLayoutTuning.defaults.minimumNonFinalSingletonAspectRatio,
- );
- expect(
- settings.getComfortLargeLayoutTuning().maximumHeightFactor,
- ComfortLargeLayoutTuning.defaults.maximumHeightFactor,
- );
- });
- });
}
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 aef0fccb0b..c41047a464 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
@@ -14,13 +14,10 @@ import "package:photos/models/file/dummy_file.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/file_load_result.dart";
-import "package:photos/models/gallery/justified_layout_strategy.dart";
-import "package:photos/models/gallery/justified_layout_tuning.dart";
import "package:photos/models/metadata/file_magic.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/settings/justified_layout_tuning_screen.dart";
import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/type.dart";
import "package:photos/ui/viewer/gallery/gallery.dart";
@@ -54,23 +51,10 @@ void main() {
try {
await Configuration.instance.init(preferences);
} catch (_) {}
-
- // Construct the delayed flag refresher outside the widget-test fake clock.
- expect(flagService.internalUser, isTrue);
});
setUp(() async {
- await localSettings.setInternalUserDisabled(false);
await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);
- await localSettings.setJustifiedLayoutStrategy(
- JustifiedLayoutStrategy.comfortLarge,
- );
- await localSettings.resetFlexLayoutTuning();
- await localSettings.resetComfortLargeLayoutTuning();
- });
-
- tearDown(() async {
- await localSettings.setInternalUserDisabled(false);
});
testWidgets("keeps the current gallery controller after an animated swap", (
@@ -176,7 +160,6 @@ void main() {
(_) => events++,
);
addTearDown(subscription.cancel);
- await localSettings.setInternalUserDisabled(true);
for (final quickMenu in [true, false]) {
await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);
await localSettings.setPhotoGridSize(5);
@@ -261,44 +244,6 @@ void main() {
},
);
- testWidgets("Flex tuning accepts arbitrary decimals and resets one field", (
- tester,
- ) async {
- var events = 0;
- final subscription = Bus.instance.on<GalleryLayoutChangedEvent>().listen(
- (_) => events++,
- );
- addTearDown(subscription.cancel);
- await tester.pumpWidget(
- MaterialApp(
- theme: lightThemeData,
- localizationsDelegates: StringsLocalizations.localizationsDelegates,
- supportedLocales: StringsLocalizations.supportedLocales,
- home: const JustifiedLayoutTuningScreen(),
- ),
- );
-
- await tester.tap(find.text("Target height scale").first);
- await tester.pumpAndSettle();
- await tester.enterText(find.byType(TextField), "1.1375");
- await tester.tap(find.text("Save"));
- await tester.pumpAndSettle();
-
- expect(localSettings.getFlexLayoutTuning().targetHeightScale, 1.1375);
- expect(events, 1);
-
- await tester.tap(find.text("Target height scale").first);
- await tester.pumpAndSettle();
- await tester.tap(find.text("Reset to default"));
- await tester.pumpAndSettle();
-
- expect(
- localSettings.getFlexLayoutTuning().targetHeightScale,
- FlexLayoutTuning.defaults.targetHeightScale,
- );
- expect(events, 2);
- });
-
testWidgets(
"layout changes rebuild every mounted gallery without loading files",
(tester) async {
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_de.arb b/mobile/packages/strings/lib/l10n/arb/strings_de.arb
index 18de27b9d6..e0a57e7735 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_de.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_de.arb
@@ -1978,9 +1978,6 @@
"lastWeek": "Letzte Woche",
"lastYearsTrip": "Reise im letzten Jahr",
"layoutGrouped": "Gruppiert",
- "layoutJustified": "Bündig",
- "layoutJustifiedComfort": "Bündig · Komfort",
- "layoutJustifiedFlex": "Bündig · Flexibel",
"layoutMasonry": "Mauerwerk",
"layoutTrip": "Reise",
"leave": "Verlassen",
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 8a0ebc3d0a..6310e36428 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -2165,9 +2165,6 @@
"lastYearsTrip": "Last year's trip",
"layout": "Layout",
"layoutGrouped": "Grouped",
- "layoutJustified": "Justified",
- "layoutJustifiedComfort": "Justified · Comfort",
- "layoutJustifiedFlex": "Justified · Flex",
"layoutMasonry": "Masonry",
"layoutTrip": "Trip",
"leave": "Leave",
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_ru.arb b/mobile/packages/strings/lib/l10n/arb/strings_ru.arb
index 99d38fcd2a..9b2f60f7ab 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_ru.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_ru.arb
@@ -2037,9 +2037,6 @@
"lastYearsTrip": "Прошлогодняя поездка",
"layout": "Макет",
"layoutGrouped": "Сгруппированные",
- "layoutJustified": "По ширине",
- "layoutJustifiedComfort": "По ширине · Комфортно",
- "layoutJustifiedFlex": "Выровнено · Гибко",
"layoutMasonry": "Плитка",
"layoutTrip": "Путешествие",
"leave": "Покинуть",
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_sv.arb b/mobile/packages/strings/lib/l10n/arb/strings_sv.arb
index 39a2426192..2427384ae5 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_sv.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_sv.arb
@@ -2121,9 +2121,6 @@
"lastYearsTrip": "Förra årets resa",
"layout": "Layout",
"layoutGrouped": "Grupperad",
- "layoutJustified": "Justerad",
- "layoutJustifiedComfort": "Justifierad · Bekväm",
- "layoutJustifiedFlex": "Justifierad · Flexibel",
"layoutMasonry": "Mosaik",
"layoutTrip": "Resa",
"leave": "Lämna",
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_vi.arb b/mobile/packages/strings/lib/l10n/arb/strings_vi.arb
index 2d4a57a811..c95e225d2c 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_vi.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_vi.arb
@@ -1956,9 +1956,6 @@
"lastYearsTrip": "Phượt năm ngoái",
"layout": "Bố cục",
"layoutGrouped": "Đã phân nhóm",
- "layoutJustified": "Căn đều",
- "layoutJustifiedComfort": "Căn đều · Thoải mái",
- "layoutJustifiedFlex": "Căn đều · Linh hoạt",
"layoutTrip": "Chuyến đi",
"leave": "Rời",
"leaveAlbum": "Rời khỏi album",