π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Show thumbnail fallback indicator for unsupported image formats
ashilknb4808d83620f
diff --git a/mobile/apps/photos/lib/states/detail_page_state.dart b/mobile/apps/photos/lib/states/detail_page_state.dartindex 59204df5e8..0b9b19ee66 100644--- a/mobile/apps/photos/lib/states/detail_page_state.dart+++ b/mobile/apps/photos/lib/states/detail_page_state.dart@@ -14,6 +14,7 @@ typedef FullScreenRequestCallback = void Function(class InheritedDetailPageState extends InheritedWidget {final ValueNotifier<bool> enableFullScreenNotifier;final ValueNotifier<bool> isInSharedCollectionNotifier;+ final ValueNotifier<bool> showingThumbnailFallbackNotifier;// Cannot be const because we accept a ValueNotifier instance at runtime// ignore: prefer_const_constructors_in_immutablesInheritedDetailPageState({@@ -21,6 +22,7 @@ class InheritedDetailPageState extends InheritedWidget {required super.child,required this.enableFullScreenNotifier,required this.isInSharedCollectionNotifier,+ required this.showingThumbnailFallbackNotifier,});static InheritedDetailPageState of(BuildContext context) =>@@ -69,5 +71,7 @@ class InheritedDetailPageState extends InheritedWidget {@overridebool updateShouldNotify(InheritedDetailPageState oldWidget) =>oldWidget.enableFullScreenNotifier != enableFullScreenNotifier ||- oldWidget.isInSharedCollectionNotifier != isInSharedCollectionNotifier;+ oldWidget.isInSharedCollectionNotifier != isInSharedCollectionNotifier ||+ oldWidget.showingThumbnailFallbackNotifier !=+ showingThumbnailFallbackNotifier;}diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dartindex 5c4dba6053..26e4a45764 100644--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart@@ -86,11 +86,13 @@ class DetailPage extends StatefulWidget {class _DetailPageState extends State<DetailPage> {final _enableFullScreenNotifier = ValueNotifier(false);final _isInSharedCollectionNotifier = ValueNotifier(false);+ final _showingThumbnailFallbackNotifier = ValueNotifier(false);@overridevoid dispose() {_enableFullScreenNotifier.dispose();_isInSharedCollectionNotifier.dispose();+ _showingThumbnailFallbackNotifier.dispose();super.dispose();}@@ -102,6 +104,7 @@ class _DetailPageState extends State<DetailPage> {return InheritedDetailPageState(enableFullScreenNotifier: _enableFullScreenNotifier,isInSharedCollectionNotifier: _isInSharedCollectionNotifier,+ showingThumbnailFallbackNotifier: _showingThumbnailFallbackNotifier,child: _Body(widget.config),);}@@ -371,6 +374,10 @@ class _BodyState extends State<_Body> {}Bus.instance.fire(GuestViewEvent(isGuestView, swipeLocked));_updateSharedCollectionState(_files![index]);+ // Reset thumbnail fallback state for new photo+ InheritedDetailPageState.maybeOf(context)+ ?.showingThumbnailFallbackNotifier+ .value = false;},physics: _shouldDisableScroll || swipeLocked? const NeverScrollableScrollPhysics()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.dartindex d522511660..98204eadf9 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@@ -26,6 +26,7 @@ import 'package:photos/services/hidden_service.dart';import "package:photos/services/local_authentication_service.dart";import "package:photos/services/video_preview_service.dart";import "package:photos/states/detail_page_state.dart";+import "package:photos/theme/colors.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/actions/file/file_actions.dart";import 'package:photos/ui/collections/collection_action_sheet.dart';@@ -86,11 +87,15 @@ class FileAppBarState extends State<FileAppBar> {});});- // Listen to shared collection changes to rebuild actions+ // Listen to shared collection and thumbnail fallback changes to rebuild actionsWidgetsBinding.instance.addPostFrameCallback((_) {- final notifier = InheritedDetailPageState.maybeOf(context)+ final sharedNotifier = InheritedDetailPageState.maybeOf(context)?.isInSharedCollectionNotifier;- notifier?.addListener(_onSharedCollectionChanged);+ sharedNotifier?.addListener(_onSharedCollectionChanged);++ final fallbackNotifier = InheritedDetailPageState.maybeOf(context)+ ?.showingThumbnailFallbackNotifier;+ fallbackNotifier?.addListener(_onThumbnailFallbackChanged);});}@@ -102,11 +107,22 @@ class FileAppBarState extends State<FileAppBar> {}}+ void _onThumbnailFallbackChanged() {+ if (mounted) {+ setState(() {+ _reloadActions = true;+ });+ }+ }+@overridevoid dispose() {InheritedDetailPageState.maybeOf(context)?.isInSharedCollectionNotifier.removeListener(_onSharedCollectionChanged);+ InheritedDetailPageState.maybeOf(context)+ ?.showingThumbnailFallbackNotifier+ .removeListener(_onThumbnailFallbackChanged);_guestViewEventSubscription.cancel();super.dispose();}@@ -181,6 +197,41 @@ class FileAppBarState extends State<FileAppBar> {List<Widget> _getActions() {_actions.clear();++ // Show info icon when thumbnail fallback is active (leftmost position)+ final showingFallback = InheritedDetailPageState.maybeOf(context)+ ?.showingThumbnailFallbackNotifier+ .value ??+ false;+ if (showingFallback) {+ _actions.add(+ Tooltip(+ message:+ "Your device doesn't support this image format. Showing a preview instead.",+ triggerMode: TooltipTriggerMode.tap,+ showDuration: const Duration(seconds: 4),+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),+ margin: const EdgeInsets.symmetric(horizontal: 16),+ decoration: BoxDecoration(+ color: backgroundElevated2Dark,+ borderRadius: BorderRadius.circular(8),+ ),+ textStyle: const TextStyle(+ color: Colors.white,+ fontSize: 14,+ ),+ preferBelow: true,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ child: const Padding(+ padding: EdgeInsets.all(12.0),+ child: Icon(Icons.info_outline),+ ),+ ),+ ),+ );+ }+final bool isOwnedByUser = widget.file.isOwner;final bool isFileUploaded = widget.file.isUploaded;final int? collectionID = widget.file.collectionID;@@ -476,6 +527,7 @@ class FileAppBarState extends State<FileAppBar> {),);}+return _actions;}diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dartindex fd0350cad5..5f21a8b19b 100644--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart@@ -22,6 +22,7 @@ import "package:photos/theme/colors.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/actions/file/file_actions.dart";import 'package:photos/ui/common/loading_widget.dart';+import 'package:photos/ui/viewer/file/thumbnail_widget.dart';import 'package:photos/utils/file_util.dart';import 'package:photos/utils/image_util.dart';import 'package:photos/utils/thumbnail_util.dart';@@ -60,6 +61,7 @@ class _ZoomableImageState extends State<ZoomableImage> {bool _loadingFinalImage = false;bool _loadedFinalImage = false;bool _convertToSupportedFormat = false;+ bool _showingThumbnailFallback = false;ValueChanged<PhotoViewScaleState>? _scaleStateChangedCallback;bool _isZooming = false;PhotoViewController _photoViewController = PhotoViewController();@@ -181,6 +183,15 @@ class _ZoomableImageState extends State<ZoomableImage> {},),);+ } else if (_showingThumbnailFallback) {+ content = Center(+ child: ThumbnailWidget(+ _photo,+ rawThumbnail: true,+ thumbnailSize: thumbnailLargeSize,+ fit: BoxFit.contain,+ ),+ );} else {content = const EnteLoadingWidget(color: Colors.white,@@ -411,18 +422,10 @@ class _ZoomableImageState extends State<ZoomableImage> {imageProvider,context,onError: (exception, s) async {- if (exception.toString().contains(- "Codec failed to produce an image, possibly due to invalid image data",- ) ||- exception.toString().contains(- "Could not decompress image.",- )) {- unawaited(_loadInSupportedFormat(file, e));- } else {- _logger.warning(- "Failed to load image ${_photo.displayName} with error: $exception",- );- }+ _logger.warning(+ "Failed to load image ${_photo.displayName} with error: $exception, attempting fallback",+ );+ unawaited(_loadInSupportedFormat(file, exception));},).then((value) {if (mounted && !_loadedFinalImage && !_convertToSupportedFormat) {@@ -476,10 +479,53 @@ class _ZoomableImageState extends State<ZoomableImage> {bool _isGIF() => _photo.displayName.toLowerCase().endsWith(".gif");+ bool _isRawFile() {+ final extension = _photo.displayName.toLowerCase().split('.').last;+ const rawExtensions = {+ 'arw', // Sony+ 'cr2', 'cr3', // Canon+ 'nef', 'nrw', // Nikon+ 'dng', // Adobe/generic+ 'orf', // Olympus+ 'raf', // Fuji+ 'rw2', // Panasonic+ 'pef', // Pentax+ 'srw', // Samsung+ '3fr', 'fff', // Hasselblad+ 'rwl', // Leica+ 'x3f', // Sigma+ 'iiq', // Phase One+ 'kdc', 'dcr', // Kodak+ 'mrw', // Minolta+ 'erf', // Epson+ 'mef', // Mamiya+ 'raw', // Generic+ };+ return rawExtensions.contains(extension);+ }+Future<void> _loadInSupportedFormat(File file,Object unsupportedErr,) async {+ // Skip compression for RAW files - FlutterImageCompress cannot process them+ // and will crash. Go directly to thumbnail fallback.+ if (_isRawFile()) {+ _logger.info(+ "Skipping compression for RAW file ${_photo.displayName}, using thumbnail fallback",+ );+ _convertToSupportedFormat = true;+ if (mounted) {+ setState(() {+ _showingThumbnailFallback = true;+ });+ InheritedDetailPageState.maybeOf(context)+ ?.showingThumbnailFallbackNotifier+ .value = true;+ }+ return;+ }+_logger.info("Compressing ${_photo.displayName} to viewable format due to $unsupportedErr",);@@ -523,6 +569,14 @@ class _ZoomableImageState extends State<ZoomableImage> {_logger.severe("Failed to compress image ${_photo.displayName} to viewable format",);+ if (mounted) {+ setState(() {+ _showingThumbnailFallback = true;+ });+ InheritedDetailPageState.maybeOf(context)+ ?.showingThumbnailFallbackNotifier+ .value = true;+ }}}}diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dartindex c447112a1f..d39920379a 100644--- a/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file_details/favorite_widget.dart@@ -172,7 +172,7 @@ class _FavoriteWidgetState extends State<FavoriteWidget> {onTap: _onTap,behavior: HitTestBehavior.opaque,child: Container(- padding: const EdgeInsets.all(4),+ padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 4),width: 34,height: 30,child: rive.RiveWidgetBuilder(