Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prune Photos viewer comments

Manav Rathi584b0008bcf4
diff --git a/mobile/apps/photos/lib/ui/common/touch_cross_detector.dart b/mobile/apps/photos/lib/ui/common/touch_cross_detector.dart
index 5b2da837d2..44988c89a4 100644
--- a/mobile/apps/photos/lib/ui/common/touch_cross_detector.dart
+++ b/mobile/apps/photos/lib/ui/common/touch_cross_detector.dart
@@ -2,18 +2,8 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
-/// A widget that detects when a touch pointer crosses its boundaries during a drag.
-///
-/// This widget solves the problem where on touch platforms, only the widget that
-/// receives the initial touch gets subsequent drag events. TouchCrossDetector uses
-/// a global listener to track all pointer movements and performs hit testing to
-/// determine when pointers enter or exit widget boundaries.
-///
-/// Note: onEnter, onHover and onPointerDown callbacks are not only triggered
-/// when the pointer is dragged into the widget, but also when the pointer
-/// is initially pressed down within the widget's bounds. Same applies for onExit
-/// when the pointer is released within the widget's bounds.
-
+// Flutter sends a drag only to the widget where it began. Track the pointer
+// globally so widgets can detect it crossing their boundaries.
class TouchCrossDetector extends SingleChildRenderObjectWidget {
const TouchCrossDetector({
super.key,
@@ -117,7 +107,6 @@ class RenderTouchCrossDetector extends RenderProxyBox {
if (isInside) {
_activePointers.add(event.pointer);
_onPointerDown?.call(event);
- // Also trigger enter event for initial touch
_onEnter?.call(
PointerEnterEvent(
position: event.position,
@@ -188,7 +177,6 @@ class RenderTouchCrossDetector extends RenderProxyBox {
}
}
-/// Global tracker for RenderObject-based implementation
class _TouchCrossRenderTracker {
_TouchCrossRenderTracker._() {
GestureBinding.instance.pointerRouter.addGlobalRoute(_handlePointerEvent);
@@ -210,7 +198,6 @@ class _TouchCrossRenderTracker {
void _handlePointerEvent(PointerEvent event) {
if (event is PointerDownEvent) {
_activePointers.add(event.pointer);
- // Handle pointer down to initialize swipe selection
for (final renderObject in _trackedRenderObjects) {
renderObject.handlePointerDown(event);
}
@@ -220,7 +207,6 @@ class _TouchCrossRenderTracker {
if (event is PointerUpEvent) {
renderObject.handlePointerUp(event);
} else if (event is PointerCancelEvent) {
- // Also handle cancel events to ensure cleanup
renderObject.handlePointerCancel(event);
}
}
diff --git a/mobile/apps/photos/lib/ui/extents_page_view.dart b/mobile/apps/photos/lib/ui/extents_page_view.dart
index 17ffd41bdd..6743b5ce5a 100644
--- a/mobile/apps/photos/lib/ui/extents_page_view.dart
+++ b/mobile/apps/photos/lib/ui/extents_page_view.dart
@@ -2,45 +2,12 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart' hide PageView;
-/// This is copy-pasted from the Flutter framework with a support added for building
-/// pages off screen using [Viewport.cacheExtents] and a [LayoutBuilder]
-///
-/// Based on commit 3932ffb1cd5dfa0c3891c60977ee4f9cd70ade66 on channel dev
+// Copied from Flutter commit 3932ffb1cd5dfa0c3891c60977ee4f9cd70ade66.
+// This version uses Viewport.cacheExtent to build pages off screen.
const PageScrollPhysics _kPagePhysics = PageScrollPhysics();
-/// A scrollable list that works page by page.
-///
-/// Each child of a page view is forced to be the same size as the viewport.
-///
-/// You can use a [PageController] to control which page is visible in the view.
-/// In addition to being able to control the pixel offset of the content inside
-/// the [PageView], a [PageController] also lets you control the offset in terms
-/// of pages, which are increments of the viewport size.
-///
-/// The [PageController] can also be used to control the
-/// [PageController.initialPage], which determines which page is shown when the
-/// [PageView] is first constructed, and the [PageController.viewportFraction],
-/// which determines the size of the pages as a fraction of the viewport size.
-///
-/// {@youtube 560 315 https://www.youtube.com/watch?v=J1gE9xvph-A}
-///
-/// See also:
-///
-/// * [PageController], which controls which page is visible in the view.
-/// * [SingleChildScrollView], when you need to make a single child scrollable.
-/// * [ListView], for a scrollable list of boxes.
-/// * [GridView], for a scrollable grid of boxes.
-/// * [ScrollNotification] and [NotificationListener], which can be used to watch
-/// the scroll position without using a [ScrollController].
class ExtentsPageView extends StatefulWidget {
- /// Creates a scrollable list that works page by page from an explicit [List]
- /// of widgets.
- ///
- /// This constructor is appropriate for page views with a small number of
- /// children because constructing the [List] requires doing work for every
- /// child that could possibly be displayed in the page view, instead of just
- /// those children that are actually visible.
ExtentsPageView({
super.key,
this.scrollDirection = Axis.horizontal,
@@ -55,22 +22,6 @@ class ExtentsPageView extends StatefulWidget {
}) : childrenDelegate = SliverChildListDelegate(children),
extents = children.length;
- /// Creates a scrollable list that works page by page using widgets that are
- /// created on demand.
- ///
- /// This constructor is appropriate for page views with a large (or infinite)
- /// number of children because the builder is called only for those children
- /// that are actually visible.
- ///
- /// Providing a non-null [itemCount] lets the [PageView] compute the maximum
- /// scroll extent.
- ///
- /// [itemBuilder] will be called only with indices greater than or equal to
- /// zero and less than [itemCount].
- ///
- /// [PageView.builder] by default does not support child reordering. If
- /// you are planning to change child order at a later time, consider using
- /// [PageView] or [PageView.custom].
ExtentsPageView.builder({
super.key,
this.scrollDirection = Axis.horizontal,
@@ -109,86 +60,6 @@ class ExtentsPageView extends StatefulWidget {
addRepaintBoundaries: false,
);
- /// Creates a scrollable list that works page by page with a custom child
- /// model.
- ///
- /// {@tool sample}
- ///
- /// This [PageView] uses a custom [SliverChildBuilderDelegate] to support child
- /// reordering.
- ///
- /// ```dart
- /// class MyPageView extends StatefulWidget {
- /// @override
- /// _MyPageView> createState() => _MyPageViewState();
- /// }
- ///
- /// class _MyPageViewState extends State<MyPageView> {
- /// List<String> items = <String>['1', '2', '3', '4', '5'];
- ///
- /// void _reverse() {
- /// setState(() {
- /// items = items.reversed.toList();
- /// });
- /// }
- ///
- /// @override
- /// Widget build(BuildContext context) {
- /// return Scaffold(
- /// body: SafeArea(
- /// child: PageView.custom(
- /// childrenDelegate: SliverChildBuilderDelegate(
- /// (BuildContext context, int index) {
- /// return KeepAlive(
- /// data: items[index],
- /// key: ValueKey<String>(items[index]),
- /// );
- /// },
- /// childCount: items.length,
- /// findChildIndexCallback: (Key key) {
- /// final ValueKey valueKey = key;
- /// final String data = valueKey.value;
- /// return items.indexOf(data);
- /// }
- /// ),
- /// ),
- /// ),
- /// bottomNavigationBar: BottomAppBar(
- /// child: Row(
- /// mainAxisAlignment: MainAxisAlignment.center,
- /// children: <Widget>[
- /// FlatButton(
- /// onPressed: () => _reverse(),
- /// child: Text('Reverse items'),
- /// ),
- /// ],
- /// ),
- /// ),
- /// );
- /// }
- /// }
- ///
- /// class KeepAlive extends StatefulWidget {
- /// const KeepAlive({Key key, this.data}) : super(key: key);
- ///
- /// final String data;
- ///
- /// @override
- /// _KeepAlive> createState() => _KeepAliveState();
- /// }
- ///
- /// class _KeepAliveState extends State<KeepAlive> with AutomaticKeepAliveClientMixin{
- /// @override
- /// bool get wantKeepAlive => true;
- ///
- /// @override
- /// Widget build(BuildContext context) {
- /// super.build(context);
- /// return Text(widget.data);
- /// }
- /// }
- /// ```
- /// {@end-tool}
const ExtentsPageView.custom({
super.key,
this.scrollDirection = Axis.horizontal,
@@ -202,67 +73,16 @@ class ExtentsPageView extends StatefulWidget {
this.openDrawer,
}) : extents = 0;
- /// The number of pages to build off screen.
- ///
- /// For example, a value of `1` builds one page ahead and one page behind,
- /// for a total of three built pages.
- ///
- /// This is especially useful for making sure heavyweight widgets have a chance
- /// to load off-screen before the user pulls it into the viewport.
final int extents;
-
- /// The axis along which the page view scrolls.
- ///
- /// Defaults to [Axis.horizontal].
final Axis scrollDirection;
-
- /// Whether the page view scrolls in the reading direction.
- ///
- /// For example, if the reading direction is left-to-right and
- /// [scrollDirection] is [Axis.horizontal], then the page view scrolls from
- /// left to right when [reverse] is false and from right to left when
- /// [reverse] is true.
- ///
- /// Similarly, if [scrollDirection] is [Axis.vertical], then the page view
- /// scrolls from top to bottom when [reverse] is false and from bottom to top
- /// when [reverse] is true.
- ///
- /// Defaults to false.
final bool reverse;
-
- /// An object that can be used to control the position to which this page
- /// view is scrolled.
final PageController controller;
-
- /// How the page view should respond to user input.
- ///
- /// For example, determines how the page view continues to animate after the
- /// user stops dragging the page view.
- ///
- /// The physics are modified to snap to page boundaries using
- /// [PageScrollPhysics] prior to being used.
- ///
- /// Defaults to matching platform conventions.
final ScrollPhysics? physics;
-
- /// Set to false to disable page snapping, useful for custom scroll behavior.
final bool pageSnapping;
-
- /// Called whenever the page in the center of the viewport changes.
final ValueChanged<int>? onPageChanged;
-
- /// A delegate that provides the children for the [PageView].
- ///
- /// The [PageView.custom] constructor lets you specify this delegate
- /// explicitly. The [PageView] and [PageView.builder] constructors create a
- /// [childrenDelegate] that wraps the given [List] and [IndexedWidgetBuilder],
- /// respectively.
final SliverChildDelegate childrenDelegate;
-
- /// {@macro flutter.widgets.scrollable.dragStartBehavior}
final DragStartBehavior dragStartBehavior;
-
- final Function? openDrawer; //nullable
+ final Function? openDrawer;
@override
State<ExtentsPageView> createState() => _PageViewState();
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
index 620a4ea0e9..885ddc90f5 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -63,8 +63,6 @@ class DetailPageConfiguration {
final GalleryType? galleryType;
final FutureOr<void> Function(BuildContext context)? onBackPressed;
- /// Callback invoked with the page context after the page is ready.
- /// Useful for showing bottom sheets or dialogs after navigation completes.
final void Function(BuildContext context)? onPageReady;
DetailPageConfiguration(
@@ -133,9 +131,8 @@ class _DetailPageState extends State<DetailPage> {
@override
Widget build(BuildContext context) {
- // Separating body to a different widget to avoid
- // unnecessary reinitialization of the InheritedDetailPageState
- // when the body is rebuilt, which can reset state stored in it.
+ // Keep InheritedDetailPageState above the rebuilding body so its state
+ // survives body rebuilds.
return InheritedDetailPageState(
enableFullScreenNotifier: _enableFullScreenNotifier,
isInSharedCollectionNotifier: _isInSharedCollectionNotifier,
@@ -203,7 +200,6 @@ class _BodyState extends State<_Body> {
_qrHelper = QrCodeDetectionHelper();
}
- // Update shared collection state after first frame
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
final selectedFile = _selectedFile;
@@ -510,8 +506,7 @@ class _BodyState extends State<_Body> {
if (kDebugMode) {
debugPrint("onPageChanged called with same index $index");
}
- // always notify listeners when the index is the same because
- // the total number of files might have changed
+ // The file count may have changed even when the index did not.
// ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
_selectedIndexNotifier.notifyListeners();
} else {
@@ -557,8 +552,7 @@ class _BodyState extends State<_Body> {
if (!mounted || _files == null) return;
final totalFiles = _files!.length;
if (totalFiles == 1) {
- // Deleted the only file
- Navigator.of(context).pop(); // Close pageview
+ Navigator.of(context).pop();
return;
}
setState(() {
@@ -673,8 +667,7 @@ class _BodyState extends State<_Body> {
fileID,
);
- // Guard: Only update if still showing the same file
- // (user may have swiped to a different file while awaiting)
+ // Ignore results for a file the user swiped away from while awaiting.
if (_selectedFile?.uploadedFileID == fileID) {
notifier.value = isShared;
}
@@ -801,7 +794,7 @@ class _GalleryFileViewerBottomOverlay extends StatelessWidget {
}
}
-/// Must remain under a [Stack] because this widget builds a [Positioned].
+// This widget returns Positioned, so its parent must be a Stack.
class _GallerySocialOverlay extends StatelessWidget {
final EnteFile file;
final DetailPageMode mode;
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
index 1baf3cdbb5..190124a704 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
@@ -137,8 +137,7 @@ class FileAppBarState extends State<FileAppBar> {
Widget build(BuildContext context) {
_logger.info("building app bar ${widget.file.generatedID?.toString()}");
- //When the widget is initialized, the actions are not available.
- //Cannot call _getActions() in initState.
+ // _getActions reads inherited state, so it cannot run in initState.
if (_actions.isEmpty || _reloadActions) {
_getActions();
_reloadActions = false;
@@ -217,7 +216,6 @@ class FileAppBarState extends State<FileAppBar> {
List<Widget> _getActions() {
_actions.clear();
- // Show info icon when thumbnail fallback is active for THIS file
final fallbackFileId = InheritedDetailPageState.maybeOf(
context,
)?.showingThumbnailFallbackNotifier.value;
@@ -329,7 +327,6 @@ class FileAppBarState extends State<FileAppBar> {
);
}
}
- // Edit option for images, live photos, and videos
if (widget.showEditAction &&
(widget.file.fileType == FileType.image ||
widget.file.fileType == FileType.livePhoto ||
@@ -342,7 +339,6 @@ class FileAppBarState extends State<FileAppBar> {
),
);
}
- // options for files owned by the user
if (isOwnedByUser && !isFileHidden && isFileUploaded) {
final bool isArchived =
widget.file.magicMetadata.visibility == archiveVisibility;
@@ -416,7 +412,6 @@ class FileAppBarState extends State<FileAppBar> {
}
if (widget.file.isVideo && !restrictFileActions) {
- // Video streaming options
if (_shouldShowCreateStreamOption()) {
items.add(
_fileMenuOption(
@@ -758,13 +753,11 @@ class FileAppBarState extends State<FileAppBar> {
}
bool _shouldShowCreateStreamOption() {
- // Show "Create Stream" option for uploaded video files without streams
return _ensureBasicRequirements() &&
!fileDataService.previewIds.containsKey(widget.file.uploadedFileID!);
}
bool _shouldShowRecreateStreamOption() {
- // Show "Recreate Stream" option for uploaded video files with existing streams
return _ensureBasicRequirements() &&
fileDataService.previewIds.containsKey(widget.file.uploadedFileID!);
}
@@ -788,7 +781,6 @@ class FileAppBarState extends State<FileAppBar> {
);
if (!wasAdded) {
- // File was already in queue
if (!mounted) return;
showToast(context, context.strings.videoAlreadyInQueue);
return;
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
index fbcb2e3056..170c2d0b41 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
@@ -153,8 +153,6 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
final bool isFileOwner =
file.ownerID == null || file.ownerID == _currentUserID;
- //Make sure the bottom most tile is always the same one, that is it should
- //not be rendered only if a condition is met.
final fileDetailsTiles = <Widget>[];
final bool canEditCaption = isFileOwner && !file.isTrash;
fileDetailsTiles.add(
@@ -369,12 +367,8 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
);
}
- //This code is for updating the location of files in which location data is
- //missing and the EXIF has location data. This is only happens for a
- //certain specific minority of devices.
+ // Some devices leave file location empty even when EXIF contains it.
Future<void> _updateLocationFromExif(Location? locationDataFromExif) async {
- // If the file is not uploaded or the file is not owned by the current user
- // then we don't need to update the location.
if (!widget.file.isUploaded || widget.file.ownerID == null) {
return;
}
@@ -452,10 +446,6 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
return value.toStringAsFixed(2).replaceFirst(RegExp(r"\.?0+$"), "");
}
- /// Formats exposure time from EXIF data into a human-readable string.
- ///
- /// For shutter speeds >= 1 second, displays as decimal with 's' suffix (e.g., "1.3s")
- /// For shutter speeds < 1 second, displays as a fraction (e.g., "1/100")
String _formatExposureTime(IfdTag exposureTimeTag) {
final values = exposureTimeTag.values.toList();
if (values.isEmpty) {
@@ -477,14 +467,11 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
final double seconds = numerator / denominator;
if (seconds >= 1) {
- // For exposures >= 1 second, show as decimal seconds
if (seconds == seconds.roundToDouble()) {
return "${seconds.toInt()}s";
}
return "${seconds.toStringAsFixed(1)}s";
} else {
- // For exposures < 1 second, always convert to 1/x format
- // e.g., 529/200000 β†’ 1/378
final reciprocal = (1 / seconds).round();
return "1/$reciprocal";
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart
index 3882d29ad2..2ceb5e84a9 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_icons_widget.dart
@@ -212,24 +212,14 @@ class FileOverlayText extends StatelessWidget {
text,
style: Theme.of(context).textTheme.titleSmall!.copyWith(
color: Colors.white,
- ), //same for both themes
+ ),
),
);
}
}
-// Base variations
-
-/// Icon overlay in the bottom left.
-///
-/// This usually indicates ente specific state of a file, e.g. if it is
-/// favorited/archived.
class _BottomLeftOverlayIcon extends StatelessWidget {
final IconData icon;
-
- /// Overriddable default size. This is just the initial hint, the actual size
- /// is dynamic based on the widget's width (so that we show smaller icons in
- /// smaller thumbnails).
final double baseSize;
const _BottomLeftOverlayIcon(this.icon, {this.baseSize = 24});
@@ -277,16 +267,8 @@ class _BottomLeftOverlayIcon extends StatelessWidget {
}
}
-/// Icon overlay in the bottom right.
-///
-/// This usually indicates information about the file itself, e.g. whether it is
-/// a live photo, or the duration of the video.
class _BottomRightOverlayIcon extends StatelessWidget {
final IconData icon;
-
- /// Overriddable default size. This is just the initial hint, the actual size
- /// is dynamic based on the widget's width (so that we show smaller icons in
- /// smaller thumbnails).
final double baseSize;
const _BottomRightOverlayIcon(this.icon, {this.baseSize = 24});
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
index c764a4180b..ad4b67c875 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
@@ -39,9 +39,7 @@ class FileWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
- // Specify key to ensure that the widget is rebuilt when the file changes
- // Before changing this, ensure that file deletes are handled properly
-
+ // Deleting a file can change the file at this index. Key by file identity.
final String fileKey = _fileWidgetKey(file);
if (file.fileType == FileType.livePhoto ||
file.fileType == FileType.image) {
diff --git a/mobile/apps/photos/lib/ui/viewer/file/panorama_view_data.dart b/mobile/apps/photos/lib/ui/viewer/file/panorama_view_data.dart
index 3d8d31ed2a..db14b8b4ed 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/panorama_view_data.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/panorama_view_data.dart
@@ -1,9 +1,7 @@
import "package:flutter/material.dart";
-/// View parameters for rendering a (possibly partial) panorama on a sphere,
-/// derived from GPano XMP metadata.
-///
-/// See https://developers.google.com/streetview/spherical-metadata
+// GPano metadata describes the image as a crop of a full equirectangular
+// canvas: https://developers.google.com/streetview/spherical-metadata
class PanoramaViewData {
const PanoramaViewData({
required this.fullWidth,
@@ -11,24 +9,11 @@ class PanoramaViewData {
required this.croppedArea,
});
- /// Width in pixels of the full equirectangular canvas.
final double fullWidth;
-
- /// Height in pixels of the full equirectangular canvas.
final double fullHeight;
-
- /// Area of the full canvas that the image actually covers, in pixels.
final Rect croppedArea;
- /// Initial camera longitude, in degrees within [-180, 180], that points the
- /// view at the horizontal center of the cropped area.
- ///
- /// The panorama widget maps the cropped area to its absolute position on the
- /// full equirectangular canvas, and its longitude 0 faces the horizontal
- /// center (u = 0.5) of that canvas. Partial panoramas (e.g. Pixel sweep
- /// panoramas) keep the compass heading of the shot, so their cropped area
- /// can sit anywhere on the canvas; without this correction the initial view
- /// often faces an empty part of the sphere.
+ // Partial panoramas may not cover longitude 0. Start at the crop's center.
double get initialLongitude {
final double uCenter =
(croppedArea.left + croppedArea.width / 2) / fullWidth;
@@ -38,15 +23,12 @@ class PanoramaViewData {
return longitude;
}
- /// Initial camera latitude that points at the vertical center of the crop.
double get initialLatitude {
final double vCenter =
(croppedArea.top + croppedArea.height / 2) / fullHeight;
return (0.5 - vCenter) * 180;
}
- /// Parses GPano attributes extracted from XMP. Returns null when the
- /// metadata is insufficient to place the image on the panorama sphere.
static PanoramaViewData? fromXmp(Map<String, String> data) {
double? cWidth = double.tryParse(
data["GPano:CroppedAreaImageWidthPixels"] ?? "",
@@ -59,13 +41,13 @@ class PanoramaViewData {
double? cLeft = double.tryParse(data["GPano:CroppedAreaLeftPixels"] ?? "");
double? cTop = double.tryParse(data["GPano:CroppedAreaTopPixels"] ?? "");
- // handle missing `fullPanoHeight` (e.g. Samsung camera app panorama mode)
+ // Samsung panoramas can omit the full height.
if (fHeight == null && fWidth != null && cHeight != null) {
fHeight = (fWidth / 2).round().toDouble();
cTop = ((fHeight - cHeight) / 2).round().toDouble();
}
- // handle inconsistent sizing (e.g. rotated image taken with OnePlus EB2103)
+ // Some rotated images report the cropped and full sizes inconsistently.
if (cWidth != null &&
cHeight != null &&
fWidth != null &&
@@ -82,7 +64,6 @@ class PanoramaViewData {
: Orientation.portrait;
var inconsistent = false;
if (croppedOrientation != fullOrientation) {
- // inconsistent orientation
inconsistent = true;
final tmp = ch;
ch = cw;
@@ -90,7 +71,6 @@ class PanoramaViewData {
}
if (cw > fw) {
- // inconsistent full/cropped width
inconsistent = true;
final tmp = fw;
fw = cw;
@@ -98,7 +78,6 @@ class PanoramaViewData {
}
if (ch > fh) {
- // inconsistent full/cropped height
inconsistent = true;
final tmp = ch;
ch = fh;
diff --git a/mobile/apps/photos/lib/ui/viewer/file/panorama_viewer_screen.dart b/mobile/apps/photos/lib/ui/viewer/file/panorama_viewer_screen.dart
index 2df0dc94d8..8d82698d04 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/panorama_viewer_screen.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/panorama_viewer_screen.dart
@@ -13,7 +13,6 @@ import "package:photos/ui/viewer/file/panorama_view_data.dart";
final _logger = Logger("PanoramaViewerScreen");
-/// Extracts XMP attributes from the file at [filePath].
typedef XmpExtractor = Future<Map<String, String>> Function(String filePath);
typedef MotionAvailabilityChecker = Future<bool> Function();
@@ -29,7 +28,6 @@ class PanoramaViewerScreen extends StatefulWidget {
final File file;
final Uint8List? thumbnail;
- /// Overridable for tests. Defaults to the Rust XMP extractor.
final XmpExtractor? xmpExtractor;
final MotionAvailabilityChecker? motionAvailabilityChecker;
diff --git a/mobile/apps/photos/lib/ui/viewer/file/qr_code_detection_helper.dart b/mobile/apps/photos/lib/ui/viewer/file/qr_code_detection_helper.dart
index 87612a6b02..f5e0b9a8f5 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/qr_code_detection_helper.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/qr_code_detection_helper.dart
@@ -81,7 +81,6 @@ class QrCodeDetectionHelper {
}
}
- /// Only notify listeners when the value actually changes.
void _clearDetections() {
if (qrDetectionsNotifier.value != null) {
qrDetectionsNotifier.value = null;
diff --git a/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart
index 451c2e7f21..6d376b59c9 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart
@@ -33,7 +33,6 @@ class ThumbnailWidget extends StatefulWidget {
final EnteFile file;
final BoxFit fit;
- /// Returns ThumbnailWidget without any overlay icons if true.
final bool rawThumbnail;
final bool shouldShowSyncStatus;
final bool showFavForAlbumOnly;
@@ -47,8 +46,6 @@ class ThumbnailWidget extends StatefulWidget {
final bool shouldShowFavoriteIcon;
final Color? placeholderColor;
- ///On video thumbnails, shows the video duration if true. If false,
- ///shows a centered play icon.
final bool shouldShowVideoDuration;
final bool shouldShowVideoOverlayIcon;
@@ -113,7 +110,6 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
smallLocalThumbnailQueue.removeTask(_localThumbnailQueueTaskId!);
}
}
- // Cancel request only if the widget has been unmounted
if (!mounted && widget.file.isRemoteOnlyFile && !_hasLoadedThumbnail) {
removePendingGetThumbnailRequestIfAny(widget.file);
}
@@ -165,8 +161,6 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
);
}
- ///Assigned dimension will be the size of a grid item. The size will be
- ///assigned to the side which is smaller in dimension.
void assignOptimizedImageDimensions() {
if (widget.file.width == 0 || widget.file.height == 0) {
return;
@@ -377,7 +371,6 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
.catchError((e) {
_errorLoadingLocalThumbnail = true;
if (e is WidgetUnmountedException) {
- // Widget was unmounted - this is expected behavior
_logger.fine(
"Thumbnail loading cancelled: widget unmounted for localID: ${widget.file.localID}",
);
@@ -396,13 +389,11 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
try {
return await _getLocalThumbnailUsingHeapPriorityQueue();
} catch (e) {
- // only retry for specific exceptions
if (e is! TaskQueueTimeoutException &&
e is! TaskQueueOverflowException &&
e is! TaskQueueCancelledException) {
rethrow;
}
- //Do not retry if the widget is not mounted
if (!mounted) {
throw WidgetUnmountedException(
"Thumbnail loading cancelled: widget unmounted",
@@ -418,7 +409,7 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
"Error getting local thumbnail for ${widget.file.displayName} (localID: ${widget.file.localID}) due to ${e.runtimeType}, retrying (attempt $retryAttempts) in ${backoff.inMilliseconds} ms",
e,
);
- await Future.delayed(backoff); // Exponential backoff
+ await Future.delayed(backoff);
} else {
rethrow;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
index 305057388a..0ce92a23cc 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
@@ -66,15 +66,13 @@ class _ZoomableImageState extends State<ZoomableImage> {
bool _loadedLargeThumbnail = false;
bool _loadingFinalImage = false;
bool _loadedFinalImage = false;
- // Set when a retry event arrives mid-flight. Since getFileFromServer
- // can't be cancelled, we record intent and trigger the retry from
- // _onFinalImageFetchFailed once the stale request finally resolves.
+ // Downloads cannot be cancelled. Defer a retry until the current attempt
+ // fails.
bool _pendingFinalImageRetry = false;
bool _convertToSupportedFormat = false;
bool _showingThumbnailFallback = false;
- // onFinalFileLoad drives memory-slideshow auto-advance; fire it once as
- // soon as any presentable frame lands (small/large thumb or final), so
- // the timer isn't gated on the full original download.
+ // Start the memory slideshow timer when any image is ready, without waiting
+ // for the original.
bool _firedOnReady = false;
ValueChanged<PhotoViewScaleState>? _scaleStateChangedCallback;
bool _isZooming = false;
@@ -89,7 +87,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
late final StreamSubscription<RetryFailedImageLoadEvent>
_retryFailedLoadSubscription;
- // This is to prevent the app from crashing when loading 200MP images
+ // Flutter can crash while decoding very large images.
// https://github.com/flutter/flutter/issues/110331
static const int _defaultMaxPixels = 100000000; // 100MP
static const int _lowRamMaxPixels = 24000000; // 24MP
@@ -146,8 +144,8 @@ class _ZoomableImageState extends State<ZoomableImage> {
.listen((_) {
if (!mounted || _loadedFinalImage) return;
if (!_loadedSmallThumbnail && _photo.isRemoteOnlyFile) {
- // Evict the stale in-flight thumbnail so the rebuild's
- // getThumbnailFromServer doesn't dedupe against the dead completer.
+ // Thumbnail requests are deduplicated. Evict the failed request
+ // before retrying.
removePendingGetThumbnailRequestIfAny(_photo);
}
if (_loadingFinalImage) {
@@ -200,11 +198,10 @@ class _ZoomableImageState extends State<ZoomableImage> {
content = PhotoViewGestureDetectorScope(
axis: Axis.vertical,
child: PhotoView(
- // Toggling ValueKey on _loadedFinalImage tears down PhotoView when
- // the full file replaces the thumbnail, briefly exposing the layer
- // underneath (the memory blur backdrop). Only needed for the
- // gallery's zoom+late-load scale fix; in memory playback we never
- // zoom, so keep a stable key and let gaplessPlayback swap in place.
+ // Rebuild PhotoView when the original replaces a zoomed thumbnail so
+ // the adjusted zoom takes effect. Memories do not zoom; a stable key
+ // lets gaplessPlayback replace the image without flashing the layer
+ // underneath.
key: widget.isFromMemories ? null : ValueKey(_loadedFinalImage),
imageProvider: _imageProvider,
controller: _photoViewController,
@@ -220,8 +217,8 @@ class _ZoomableImageState extends State<ZoomableImage> {
),
backgroundDecoration: widget.backgroundDecoration as BoxDecoration?,
loadingBuilder: (context, event) {
- // This is to make sure the hero anitmation animates and fits in the
- //dimensions of the image on screen.
+ // Match the loading state to the image's on-screen size during the
+ // hero animation.
final screenDimensions = MediaQuery.sizeOf(context);
late final double screenRelativeImageWidth;
late final double screenRelativeImageHeight;
@@ -289,9 +286,8 @@ class _ZoomableImageState extends State<ZoomableImage> {
);
}
- // Deferred via microtask so synchronous callers inside build() (the
- // cached-thumbnail branches of _loadNetworkImage / _loadLocalImage) don't
- // mutate parent state during the current build phase.
+ // Cached images can call this during build. Defer the parent callback until
+ // the build is complete.
void _notifyReadyOnce() {
if (_firedOnReady) return;
_firedOnReady = true;
@@ -347,10 +343,6 @@ class _ZoomableImageState extends State<ZoomableImage> {
if (file != null) {
_onFileLoaded(file);
} else {
- // getFileFromServer resolves null (not throw) on most network
- // failures because downloadAndDecrypt is called with
- // throwOnFailure=false here β€” route through the same helper as
- // catchError below.
_onFinalImageFetchFailed();
}
})
@@ -445,10 +437,8 @@ class _ZoomableImageState extends State<ZoomableImage> {
}
void _onFileLoaded(File file) {
- // On Android, the platform HEIC decoder can silently produce glitched
- // output without throwing an error. Use Rust when dimensions are known
- // and safely under the large-image guard.
-
+ // Android's HEIC decoder can produce a glitched image without throwing.
+ // Use Rust when the image dimensions make it safe.
if (_isAndroidHeic()) {
unawaited(_loadAndroidHeic(file));
return;
@@ -467,11 +457,8 @@ class _ZoomableImageState extends State<ZoomableImage> {
return;
}
- // Image.file -> Android BitmapFactory does not apply EXIF orientation
- // for HEIC. If the file declares a non-trivial orientation, route through
- // _loadInSupportedFormat which uses FlutterImageCompress with
- // autoCorrectionAngle=true (reads EXIF via ExifInterface and rotates the
- // bitmap before returning bytes).
+ // Android's HEIC decoder ignores EXIF orientation. Rotate through
+ // FlutterImageCompress when needed.
if (await _heicNeedsExifRotation(file)) {
await _loadInSupportedFormat(file, "HEIC requires EXIF rotation");
return;
@@ -612,12 +599,10 @@ class _ZoomableImageState extends State<ZoomableImage> {
_initialScale = null;
}
_subscribeToZoomStream();
- // Fix for auto-zooming when final image is loaded after double tapping
- //twice.
+ // Prevent auto-zoom when the original loads after two double taps.
_scaleStateController.scaleState = PhotoViewScaleState.zoomedIn;
}
final bool canUpdateMetadata = _photo.canEditMetaInfo;
- // forcefully get finalImageInfo is dimensions are not available in metadata
if (finalImageInfo == null && canUpdateMetadata && !_photo.hasDimensions) {
finalImageInfo = await getImageInfo(finalImageProvider);
}
@@ -708,8 +693,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
Object unsupportedErr, {
bool skipRustDecoder = false,
}) async {
- // Skip compression for RAW files - FlutterImageCompress cannot process them
- // and will crash. Go directly to thumbnail fallback.
+ // FlutterImageCompress crashes on RAW files. Show the thumbnail instead.
if (_isRawFile()) {
_logger.info(
"Skipping compression for RAW file ${_photo.displayName}, using thumbnail fallback",
@@ -748,7 +732,6 @@ class _ZoomableImageState extends State<ZoomableImage> {
}
}
- // Fallback to FlutterImageCompress (platform-based decoder).
Uint8List? compressedFile;
if (isTooLargeImage) {
_logger.info(
@@ -806,8 +789,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
}
}
-// Suppresses the spinner for a short window so fast loads (common in the
-// memory viewer thanks to prefetch) never paint a flash between advances.
+// Delay the spinner so prefetched memory images do not flash it between slides.
class _DelayedLoadingIndicator extends StatefulWidget {
const _DelayedLoadingIndicator();
diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
index 3dcff74d30..b38e57535a 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_live_image_new.dart
@@ -85,8 +85,6 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
});
}
- /// Check if a local position (relative to this widget) falls within any
- /// detected QR code bounding box.
bool _isPositionInQrRegion(Offset localPosition) {
final detections = widget.qrDetectionsNotifier?.value?.forFile(
widget.enteFile,
@@ -113,7 +111,6 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
final offsetX = (size.width - displayW) / 2;
final offsetY = (size.height - displayH) / 2;
- // Normalize the tap position to image coordinates (0-1)
final normX = (localPosition.dx - offsetX) / displayW;
final normY = (localPosition.dy - offsetY) / displayH;
@@ -129,8 +126,6 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
}
bool _isLongPressInVisibleQrRegion(Offset localPosition) {
- // If pressing within a QR code region, let the QR overlay handle it,
- // but only when the overlay is actually visible (not in fullscreen mode).
final isQrOverlayVisible =
!(InheritedDetailPageState.maybeOf(
context,
@@ -271,9 +266,8 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
}
Future<MotionPhotoAvailability> _loadLiveVideoOnce() async {
- // For non-live photo, with fileType as Image, we still call _getMotionPhoto
- // to check if it is a motion photo. This is needed to handle earlier
- // uploads and upload from desktop.
+ // Older and desktop uploads can be motion photos without the live-photo
+ // file type.
final _MotionPhotoVideoResult result;
if (_enteFile.isLivePhoto) {
result = _MotionPhotoVideoResult(
@@ -345,7 +339,6 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
if (imageFile != null) {
final index = await getMotionVideoIndex(filePath: imageFile.path);
if (index != null) {
- // Update the metadata if it is not updated
if (!_enteFile.isMotionPhoto && _enteFile.canEditMetaInfo) {
FileMagicService.instance
.updatePublicMagicMetadata(
@@ -409,7 +402,6 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
return;
}
- // If long-press has already ended by this point, don't keep playback running.
if (!_showVideo) {
await _player.pause();
}