Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Improve Android review intent viewer

laurenspriemd293bc2cb141
diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
index 79126cdd72..f59659015d 100644
--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart
+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
@@ -90,6 +90,7 @@ import "package:photos/ui/viewer/gallery/shared_public_collection_page.dart";
import "package:photos/ui/viewer/search_tab/search_tab.dart";
import "package:photos/utils/collection_util.dart";
import "package:photos/utils/dialog_util.dart";
+import "package:photos/utils/intent_util.dart";
import "package:receive_sharing_intent/receive_sharing_intent.dart";
class HomeWidget extends StatefulWidget {
@@ -122,6 +123,7 @@ class _HomeWidgetState extends State<HomeWidget> {
List<SharedMediaFile>? _sharedFiles;
bool _shouldRenderCreateCollectionSheet = false;
bool _showShowBackupHook = false;
+ bool _mediaViewFallbackNavigationScheduled = false;
bool _personSyncTriggered = false;
bool _collectionsSyncTriggered = false;
bool _isShowingChangeLog = false;
@@ -567,63 +569,7 @@ class _HomeWidgetState extends State<HomeWidget> {
_intentDataStreamSubscription =
ReceiveSharingIntent.instance.getMediaStream().listen(
(List<SharedMediaFile> value) {
- if (value.isEmpty) {
- return;
- }
- // Check if this is a public album link
- if (_isPublicAlbumUrl(value[0].path)) {
- final uri = Uri.parse(value[0].path);
- _handlePublicAlbumLink(uri, "sharedIntent.getMediaStream");
- return;
- }
-
- if (value[0].mimeType != null &&
- (value[0].mimeType!.contains("image") ||
- value[0].mimeType!.contains("video"))) {
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return AlertDialog(
- actions: [
- const SizedBox(height: 24),
- ButtonWidget(
- labelText: AppLocalizations.of(context).openFile,
- buttonType: ButtonType.primary,
- onTap: () async {
- Navigator.of(context).pop(true);
- },
- ),
- const SizedBox(height: 12),
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: AppLocalizations.of(context).backupFile,
- onTap: () async {
- Navigator.of(context).pop(false);
- },
- ),
- ],
- );
- },
- ).then((shouldOpenFile) {
- if (shouldOpenFile) {
- Navigator.pushReplacement(
- context,
- MaterialPageRoute(
- builder: (_) {
- return FileViewer(sharedMediaFile: value[0]);
- },
- ),
- );
- } else {
- if (mounted) {
- setState(() {
- _shouldRenderCreateCollectionSheet = true;
- _sharedFiles = value;
- });
- }
- }
- });
- }
+ unawaited(_handleSharedMediaStream(value));
},
onError: (err) {
_logger.severe("getIntentDataStream error: $err");
@@ -633,34 +579,164 @@ class _HomeWidgetState extends State<HomeWidget> {
ReceiveSharingIntent.instance.getInitialMedia().then((
List<SharedMediaFile> value,
) {
- if (mounted) {
- // Check if this is a public album link
- if (value.isNotEmpty && _isPublicAlbumUrl(value[0].path)) {
- final uri = Uri.parse(value[0].path);
- _handlePublicAlbumLink(uri, "sharedIntent.getInitialMedia");
- return;
- }
+ unawaited(_handleInitialSharedMedia(value));
+ });
+ }
- if (AppLifecycleService.instance.mediaExtensionAction.type ==
- MediaType.image ||
- AppLifecycleService.instance.mediaExtensionAction.type ==
- MediaType.video) {
- Navigator.pushReplacement(
- context,
- MaterialPageRoute(
- builder: (_) {
- return const FileViewer();
- },
- ),
- );
- return;
- }
+ Future<void> _handleSharedMediaStream(List<SharedMediaFile> value) async {
+ if (!mounted || value.isEmpty) {
+ return;
+ }
- setState(() {
- _sharedFiles = value;
- _shouldRenderCreateCollectionSheet = true;
- });
+ // Check if this is a public album link
+ if (_isPublicAlbumUrl(value[0].path)) {
+ final uri = Uri.parse(value[0].path);
+ unawaited(_handlePublicAlbumLink(uri, "sharedIntent.getMediaStream"));
+ return;
+ }
+
+ if (await _consumeAndroidMediaViewIntent()) {
+ _scheduleMediaViewFallbackNavigation();
+ return;
+ }
+
+ if (!mounted) {
+ return;
+ }
+ if (value[0].mimeType != null &&
+ (value[0].mimeType!.contains("image") ||
+ value[0].mimeType!.contains("video"))) {
+ unawaited(
+ showDialog<bool>(
+ context: context,
+ builder: (BuildContext context) {
+ return AlertDialog(
+ actions: [
+ const SizedBox(height: 24),
+ ButtonWidget(
+ labelText: AppLocalizations.of(context).openFile,
+ buttonType: ButtonType.primary,
+ onTap: () async {
+ Navigator.of(context).pop(true);
+ },
+ ),
+ const SizedBox(height: 12),
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ labelText: AppLocalizations.of(context).backupFile,
+ onTap: () async {
+ Navigator.of(context).pop(false);
+ },
+ ),
+ ],
+ );
+ },
+ ).then((shouldOpenFile) {
+ if (!mounted || shouldOpenFile == null) {
+ return;
+ }
+ if (shouldOpenFile) {
+ unawaited(
+ Navigator.pushReplacement(
+ context,
+ MaterialPageRoute(
+ builder: (_) {
+ return FileViewer(sharedMediaFile: value[0]);
+ },
+ ),
+ ),
+ );
+ } else {
+ setState(() {
+ _shouldRenderCreateCollectionSheet = true;
+ _sharedFiles = value;
+ });
+ }
+ }),
+ );
+ }
+ }
+
+ Future<void> _handleInitialSharedMedia(List<SharedMediaFile> value) async {
+ if (!mounted) {
+ return;
+ }
+ // Check if this is a public album link
+ if (value.isNotEmpty && _isPublicAlbumUrl(value[0].path)) {
+ final uri = Uri.parse(value[0].path);
+ unawaited(_handlePublicAlbumLink(uri, "sharedIntent.getInitialMedia"));
+ return;
+ }
+
+ if (await _consumeAndroidMediaViewIntent()) {
+ if (!mounted) {
+ return;
}
+ unawaited(
+ Navigator.pushReplacement(
+ context,
+ MaterialPageRoute(
+ builder: (_) {
+ return const FileViewer();
+ },
+ ),
+ ),
+ );
+ return;
+ }
+
+ if (value.isEmpty || !mounted) {
+ return;
+ }
+
+ setState(() {
+ _sharedFiles = value;
+ _shouldRenderCreateCollectionSheet = true;
+ });
+ }
+
+ Future<bool> _consumeAndroidMediaViewIntent() async {
+ if (!Platform.isAndroid) {
+ return false;
+ }
+
+ final mediaExtensionAction = await initIntentAction();
+ AppLifecycleService.instance.setMediaExtensionAction(mediaExtensionAction);
+
+ if (!_isMediaViewAction(mediaExtensionAction)) {
+ return false;
+ }
+
+ _logger.info("Consuming shared media callback for Android media view");
+ await ReceiveSharingIntent.instance.reset();
+ return true;
+ }
+
+ bool _isMediaViewAction(MediaExtentionAction action) {
+ return action.action == IntentAction.view &&
+ (action.type == MediaType.image || action.type == MediaType.video);
+ }
+
+ void _scheduleMediaViewFallbackNavigation() {
+ if (_mediaViewFallbackNavigationScheduled) {
+ return;
+ }
+ _mediaViewFallbackNavigationScheduled = true;
+ Future<void>.delayed(const Duration(milliseconds: 200), () {
+ _mediaViewFallbackNavigationScheduled = false;
+ if (!mounted || ModalRoute.of(context)?.isCurrent != true) {
+ return;
+ }
+ unawaited(
+ Navigator.pushReplacement(
+ context,
+ MaterialPageRoute(
+ builder: (_) {
+ return const FileViewer();
+ },
+ ),
+ ),
+ );
});
}
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
index 7c65540502..9dc251d8c5 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_viewer.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
import "dart:io";
+import "dart:math" as math;
import "package:chewie/chewie.dart";
import "package:flutter/material.dart";
@@ -10,7 +11,11 @@ import "package:media_extension/media_extension_action_types.dart";
import "package:photo_manager/photo_manager.dart";
import "package:photo_manager_image_provider/photo_manager_image_provider.dart";
import "package:photo_view/photo_view.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/models/gallery_type.dart";
+import "package:photos/models/metadata/file_magic.dart";
import "package:photos/services/app_lifecycle_service.dart";
+import "package:photos/ui/viewer/file/detail_page.dart";
import "package:photos/utils/exif_util.dart";
import "package:receive_sharing_intent/receive_sharing_intent.dart";
import "package:video_player/video_player.dart";
@@ -26,12 +31,18 @@ class FileViewer extends StatefulWidget {
}
class FileViewerState extends State<FileViewer> {
+ static const int _reviewGalleryWindowSize = 80;
+ static const int _reviewGallerySearchPageSize = 200;
+
final action = AppLifecycleService.instance.mediaExtensionAction;
ChewieController? controller;
VideoPlayerController? videoController;
final Logger _logger = Logger("FileViewer");
double? aspectRatio;
Future<AssetEntity?>? mediaStoreAssetFuture;
+ Future<DetailPageConfiguration?>? reviewGalleryConfigFuture;
+ bool _isInitializingVideoController = false;
+ bool _isClosingViewer = false;
bool get _isExternalView =>
widget.sharedMediaFile == null &&
action.action == IntentAction.view &&
@@ -52,17 +63,35 @@ class FileViewerState extends State<FileViewer> {
void initState() {
_logger.info("Initializing FileViewer");
super.initState();
+ if (_isExternalView) {
+ mediaStoreAssetFuture = _loadMediaStoreAsset(action.data);
+ reviewGalleryConfigFuture = _loadReviewGalleryConfig();
+ }
if (action.type == MediaType.video ||
widget.sharedMediaFile?.type == SharedMediaType.video) {
- _initializeVideoController();
- } else if (action.type == MediaType.image) {
+ if (!_isExternalView) {
+ _initializeVideoController();
+ }
+ } else if (action.type == MediaType.image &&
+ mediaStoreAssetFuture == null) {
mediaStoreAssetFuture = _loadMediaStoreAsset(action.data);
}
}
Future<void> _initializeVideoController() async {
- await _fetchAspectRatio();
- initController();
+ if (_isInitializingVideoController || controller != null) {
+ return;
+ }
+ _isInitializingVideoController = true;
+ try {
+ await _fetchAspectRatio();
+ if (!mounted) {
+ return;
+ }
+ initController();
+ } finally {
+ _isInitializingVideoController = false;
+ }
}
Future<void> _fetchAspectRatio() async {
@@ -170,6 +199,190 @@ class FileViewerState extends State<FileViewer> {
return null;
}
+ Future<DetailPageConfiguration?> _loadReviewGalleryConfig() async {
+ final assetFuture = mediaStoreAssetFuture;
+ if (assetFuture == null) {
+ return null;
+ }
+ final targetAsset = await assetFuture;
+ if (targetAsset == null) {
+ return null;
+ }
+
+ try {
+ final source = await _findReviewGallerySource(targetAsset);
+ if (source == null) {
+ _logger.info("Could not find containing gallery for ${targetAsset.id}");
+ return null;
+ }
+ final assets = await _reviewGalleryWindow(source);
+ var selectedIndex =
+ assets.indexWhere((asset) => asset.id == targetAsset.id);
+ if (selectedIndex < 0) {
+ assets.insert(0, targetAsset);
+ selectedIndex = 0;
+ }
+ final files = <EnteFile>[];
+ var fileSelectedIndex = selectedIndex;
+ for (var index = 0; index < assets.length; index++) {
+ try {
+ if (index == selectedIndex) {
+ fileSelectedIndex = files.length;
+ }
+ files.add(await _fileFromAsset(source.path.name, assets[index]));
+ } catch (e, s) {
+ if (index == selectedIndex) {
+ rethrow;
+ }
+ _logger.warning("Skipping adjacent review asset", e, s);
+ }
+ }
+ if (files.isEmpty) {
+ return null;
+ }
+ return DetailPageConfiguration(
+ files,
+ fileSelectedIndex,
+ "external_review_gallery",
+ isLocalOnlyContext: true,
+ showEditAction: false,
+ galleryType: GalleryType.localFolder,
+ onBackPressed: (_) => _closeViewer(),
+ );
+ } catch (e, s) {
+ _logger.warning("Failed to load review gallery", e, s);
+ return null;
+ }
+ }
+
+ Future<_ReviewGallerySource?> _findReviewGallerySource(
+ AssetEntity targetAsset,
+ ) async {
+ final source = await _findReviewGallerySourceInPaths(
+ targetAsset,
+ paths: await _reviewGalleryPaths(hasAll: false),
+ );
+ if (source != null) {
+ return source;
+ }
+ return _findReviewGallerySourceInPaths(
+ targetAsset,
+ paths: await _reviewGalleryPaths(hasAll: true),
+ );
+ }
+
+ Future<List<AssetPathEntity>> _reviewGalleryPaths({
+ required bool hasAll,
+ }) {
+ return PhotoManager.getAssetPathList(
+ hasAll: hasAll,
+ type: RequestType.common,
+ filterOption: _reviewGalleryFilterOption(),
+ );
+ }
+
+ Future<_ReviewGallerySource?> _findReviewGallerySourceInPaths(
+ AssetEntity targetAsset, {
+ required List<AssetPathEntity> paths,
+ }) async {
+ final preferredName = _preferredPathName(targetAsset);
+ paths.sort((a, b) {
+ final aMatches = a.name == preferredName;
+ final bMatches = b.name == preferredName;
+ if (aMatches == bMatches) {
+ return 0;
+ }
+ return aMatches ? -1 : 1;
+ });
+
+ for (final path in paths) {
+ final count = await path.assetCountAsync;
+ final index = await _indexOfAsset(path, targetAsset.id, count);
+ if (index != null) {
+ return _ReviewGallerySource(
+ path: path,
+ targetIndex: index,
+ count: count,
+ );
+ }
+ }
+ return null;
+ }
+
+ FilterOptionGroup _reviewGalleryFilterOption() {
+ final filterOptionGroup = FilterOptionGroup();
+ const assetOption = FilterOption(
+ needTitle: true,
+ sizeConstraint: SizeConstraint(ignoreSize: true),
+ );
+ filterOptionGroup.setOption(AssetType.image, assetOption);
+ filterOptionGroup.setOption(AssetType.video, assetOption);
+ filterOptionGroup.createTimeCond = DateTimeCond.def().copyWith(
+ ignore: true,
+ );
+ filterOptionGroup.addOrderOption(
+ const OrderOption(type: OrderOptionType.createDate, asc: false),
+ );
+ return filterOptionGroup;
+ }
+
+ String? _preferredPathName(AssetEntity asset) {
+ final relativePath = asset.relativePath;
+ if (relativePath == null || relativePath.isEmpty) {
+ return null;
+ }
+ final segments = relativePath
+ .split("/")
+ .where((segment) => segment.trim().isNotEmpty)
+ .toList(growable: false);
+ if (segments.isEmpty) {
+ return null;
+ }
+ return segments.last;
+ }
+
+ Future<int?> _indexOfAsset(
+ AssetPathEntity path,
+ String assetId,
+ int count,
+ ) async {
+ for (var start = 0; start < count; start += _reviewGallerySearchPageSize) {
+ final end = math.min(count, start + _reviewGallerySearchPageSize);
+ final assets = await path.getAssetListRange(start: start, end: end);
+ final index = assets.indexWhere((asset) => asset.id == assetId);
+ if (index >= 0) {
+ return start + index;
+ }
+ }
+ return null;
+ }
+
+ Future<List<AssetEntity>> _reviewGalleryWindow(
+ _ReviewGallerySource source,
+ ) async {
+ const halfWindow = _reviewGalleryWindowSize ~/ 2;
+ final initialEnd =
+ math.min(source.count, source.targetIndex + halfWindow + 1);
+ final start = math.max(
+ 0,
+ math.min(
+ source.targetIndex - halfWindow,
+ initialEnd - _reviewGalleryWindowSize,
+ ),
+ );
+ final end = math.min(source.count, start + _reviewGalleryWindowSize);
+ return source.path.getAssetListRange(start: start, end: end);
+ }
+
+ Future<EnteFile> _fileFromAsset(String pathName, AssetEntity asset) async {
+ final file = await EnteFile.fromAsset(pathName, asset);
+ file.pubMagicMetadata = PubMagicMetadata(
+ w: asset.orientatedWidth,
+ h: asset.orientatedHeight,
+ );
+ return file;
+ }
+
Widget _buildImageViewer() {
final sharedMediaPath = widget.sharedMediaFile?.path;
if (sharedMediaPath != null) {
@@ -208,10 +421,16 @@ class FileViewerState extends State<FileViewer> {
return _boundedPhotoView(MemoryImage(base64Decode(data)));
}
- @override
- Widget build(BuildContext context) {
- _logger.info("Building FileViewer");
- final scaffold = Scaffold(
+ Widget _buildVideoViewer() {
+ if (controller != null) {
+ return Chewie(controller: controller!);
+ }
+ unawaited(_initializeVideoController());
+ return const CircularProgressIndicator();
+ }
+
+ Widget _buildSingleFileScaffold() {
+ return Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: _closeViewer,
@@ -228,9 +447,7 @@ class FileViewerState extends State<FileViewer> {
return _buildImageViewer();
} else if (action.type == MediaType.video ||
widget.sharedMediaFile?.type == SharedMediaType.video) {
- return controller != null
- ? Chewie(controller: controller!)
- : const CircularProgressIndicator();
+ return _buildVideoViewer();
} else {
_logger.severe(
'unsupported file type ${action.type} or ${widget.sharedMediaFile?.type}',
@@ -243,21 +460,70 @@ class FileViewerState extends State<FileViewer> {
],
),
);
+ }
+
+ Widget _buildReviewGalleryOrFallback() {
+ final configFuture = reviewGalleryConfigFuture;
+ if (configFuture == null) {
+ return _buildSingleFileScaffold();
+ }
+ return FutureBuilder<DetailPageConfiguration?>(
+ future: configFuture,
+ builder: (context, snapshot) {
+ final config = snapshot.data;
+ if (config != null) {
+ return DetailPage(config);
+ }
+ if (snapshot.connectionState != ConnectionState.done) {
+ return const Scaffold(
+ backgroundColor: Colors.black,
+ body: Center(child: CircularProgressIndicator()),
+ );
+ }
+ return _buildSingleFileScaffold();
+ },
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ _logger.info("Building FileViewer");
+ final scaffold = _isExternalView
+ ? _buildReviewGalleryOrFallback()
+ : _buildSingleFileScaffold();
if (!_isExternalView) {
return scaffold;
}
return PopScope(
canPop: false,
- onPopInvokedWithResult: (didPop, _) {
- if (!didPop) {
- unawaited(_closeViewer());
- }
+ onPopInvokedWithResult: (didPop, result) {
+ unawaited(_closeViewer());
},
child: scaffold,
);
}
Future<void> _closeViewer() async {
- await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
+ if (_isClosingViewer) {
+ return;
+ }
+ _isClosingViewer = true;
+ try {
+ await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
+ } finally {
+ _isClosingViewer = false;
+ }
}
}
+
+class _ReviewGallerySource {
+ final AssetPathEntity path;
+ final int targetIndex;
+ final int count;
+
+ const _ReviewGallerySource({
+ required this.path,
+ required this.targetIndex,
+ required this.count,
+ });
+}
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 b8ed101db2..bcc6e622ca 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -48,7 +48,9 @@ class DetailPageConfiguration {
final String tagPrefix;
final DetailPageMode mode;
final bool isLocalOnlyContext;
+ final bool showEditAction;
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.
@@ -60,7 +62,9 @@ class DetailPageConfiguration {
this.tagPrefix, {
this.mode = DetailPageMode.full,
this.isLocalOnlyContext = false,
+ this.showEditAction = true,
this.galleryType,
+ this.onBackPressed,
this.onPageReady,
});
@@ -69,15 +73,23 @@ class DetailPageConfiguration {
GalleryLoader? asyncLoader,
int? selectedIndex,
String? tagPrefix,
+ DetailPageMode? mode,
bool? isLocalOnlyContext,
+ bool? showEditAction,
GalleryType? galleryType,
+ FutureOr<void> Function(BuildContext context)? onBackPressed,
+ void Function(BuildContext context)? onPageReady,
}) {
return DetailPageConfiguration(
files ?? this.files,
selectedIndex ?? this.selectedIndex,
tagPrefix ?? this.tagPrefix,
+ mode: mode ?? this.mode,
isLocalOnlyContext: isLocalOnlyContext ?? this.isLocalOnlyContext,
+ showEditAction: showEditAction ?? this.showEditAction,
galleryType: galleryType ?? this.galleryType,
+ onBackPressed: onBackPressed ?? this.onBackPressed,
+ onPageReady: onPageReady ?? this.onPageReady,
);
}
}
@@ -235,6 +247,8 @@ class _BodyState extends State<_Body> {
.enableFullScreenNotifier,
galleryType: widget.config.galleryType,
mode: widget.config.mode,
+ showEditAction: widget.config.showEditAction,
+ onBackPressed: widget.config.onBackPressed,
);
},
valueListenable: _selectedIndexNotifier,
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 c1b13c6ea2..374983f1ce 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
@@ -52,6 +52,8 @@ class FileAppBar extends StatefulWidget {
final ValueNotifier<bool> enableFullScreenNotifier;
final GalleryType? galleryType;
final DetailPageMode mode;
+ final bool showEditAction;
+ final FutureOr<void> Function(BuildContext context)? onBackPressed;
const FileAppBar(
this.file,
@@ -60,6 +62,8 @@ class FileAppBar extends StatefulWidget {
required this.enableFullScreenNotifier,
this.galleryType,
this.mode = DetailPageMode.full,
+ this.showEditAction = true,
+ this.onBackPressed,
super.key,
});
@@ -83,7 +87,8 @@ class FileAppBarState extends State<FileAppBar> {
void didUpdateWidget(FileAppBar oldWidget) {
super.didUpdateWidget(oldWidget);
if (detailPageFileIdentifier(oldWidget.file) !=
- detailPageFileIdentifier(widget.file)) {
+ detailPageFileIdentifier(widget.file) ||
+ oldWidget.showEditAction != widget.showEditAction) {
_getActions();
}
}
@@ -206,6 +211,11 @@ class FileAppBarState extends State<FileAppBar> {
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
+ final onBackPressed = widget.onBackPressed;
+ if (onBackPressed != null && !isGuestView) {
+ unawaited(Future.sync(() => onBackPressed(context)));
+ return;
+ }
isGuestView
? _requestAuthentication()
: Navigator.of(context).pop();
@@ -367,9 +377,10 @@ class FileAppBarState extends State<FileAppBar> {
}
}
// Edit option for images, live photos, and videos
- if (widget.file.fileType == FileType.image ||
- widget.file.fileType == FileType.livePhoto ||
- widget.file.fileType == FileType.video) {
+ if (widget.showEditAction &&
+ (widget.file.fileType == FileType.image ||
+ widget.file.fileType == FileType.livePhoto ||
+ widget.file.fileType == FileType.video)) {
items.add(
EntePopupMenuItem(
AppLocalizations.of(context).edit,
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 3e4602780b..c65cd97350 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_widget.dart
@@ -36,8 +36,7 @@ class FileWidget extends StatelessWidget {
// Specify key to ensure that the widget is rebuilt when the file changes
// Before changing this, ensure that file deletes are handled properly
- final String fileKey =
- "file_genID_${file.generatedID}___file_id_${file.uploadedFileID}";
+ final String fileKey = _fileWidgetKey(file);
if (file.fileType == FileType.livePhoto ||
file.fileType == FileType.image) {
return ZoomableLiveImageNew(
@@ -76,3 +75,17 @@ class FileWidget extends StatelessWidget {
}
}
}
+
+String _fileWidgetKey(EnteFile file) {
+ final baseKey =
+ "file_genID_${file.generatedID}___file_id_${file.uploadedFileID}";
+ if (file.generatedID != null || file.uploadedFileID != null) {
+ return baseKey;
+ }
+
+ final localID = file.localID;
+ if (localID == null || localID.isEmpty) {
+ return baseKey;
+ }
+ return "${baseKey}___local_id_$localID";
+}