Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move Add to Album to popup menu when social icons are shown

ashilknf77d21bcb9f5
diff --git a/mobile/apps/photos/lib/states/detail_page_state.dart b/mobile/apps/photos/lib/states/detail_page_state.dart
index bcfdf3560a..59204df5e8 100644
--- a/mobile/apps/photos/lib/states/detail_page_state.dart
+++ b/mobile/apps/photos/lib/states/detail_page_state.dart
@@ -13,12 +13,14 @@ typedef FullScreenRequestCallback = void Function(
class InheritedDetailPageState extends InheritedWidget {
final ValueNotifier<bool> enableFullScreenNotifier;
+ final ValueNotifier<bool> isInSharedCollectionNotifier;
// Cannot be const because we accept a ValueNotifier instance at runtime
// ignore: prefer_const_constructors_in_immutables
InheritedDetailPageState({
super.key,
required super.child,
required this.enableFullScreenNotifier,
+ required this.isInSharedCollectionNotifier,
});
static InheritedDetailPageState of(BuildContext context) =>
@@ -66,5 +68,6 @@ class InheritedDetailPageState extends InheritedWidget {
@override
bool updateShouldNotify(InheritedDetailPageState oldWidget) =>
- oldWidget.enableFullScreenNotifier != enableFullScreenNotifier;
+ oldWidget.enableFullScreenNotifier != enableFullScreenNotifier ||
+ oldWidget.isInSharedCollectionNotifier != isInSharedCollectionNotifier;
}
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 940003a18c..97fafc9a08 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -15,6 +15,7 @@ import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/file/file_type.dart";
import "package:photos/service_locator.dart";
+import "package:photos/services/collections_service.dart";
import "package:photos/services/local_authentication_service.dart";
import "package:photos/states/detail_page_state.dart";
import "package:photos/ui/common/fast_scroll_physics.dart";
@@ -79,10 +80,12 @@ class DetailPage extends StatefulWidget {
class _DetailPageState extends State<DetailPage> {
final _enableFullScreenNotifier = ValueNotifier(false);
+ final _isInSharedCollectionNotifier = ValueNotifier(false);
@override
void dispose() {
_enableFullScreenNotifier.dispose();
+ _isInSharedCollectionNotifier.dispose();
super.dispose();
}
@@ -93,6 +96,7 @@ class _DetailPageState extends State<DetailPage> {
// when the body is rebuilt, which can reset state stored in it.
return InheritedDetailPageState(
enableFullScreenNotifier: _enableFullScreenNotifier,
+ isInSharedCollectionNotifier: _isInSharedCollectionNotifier,
child: _Body(widget.config),
);
}
@@ -132,6 +136,11 @@ class _BodyState extends State<_Body> {
swipeLocked = event.swipeLocked;
});
});
+
+ // Update shared collection state after first frame
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ _updateSharedCollectionState(_files![_selectedIndexNotifier.value]);
+ });
}
@override
@@ -354,6 +363,7 @@ class _BodyState extends State<_Body> {
_selectedIndexNotifier.value = index;
}
Bus.instance.fire(GuestViewEvent(isGuestView, swipeLocked));
+ _updateSharedCollectionState(_files![index]);
},
physics: _shouldDisableScroll || swipeLocked
? const NeverScrollableScrollPhysics()
@@ -480,4 +490,26 @@ class _BodyState extends State<_Body> {
"Please authenticate to view more photos and videos.",
);
}
+
+ Future<void> _updateSharedCollectionState(EnteFile file) async {
+ final fileID = file.uploadedFileID;
+ final notifier =
+ InheritedDetailPageState.maybeOf(context)?.isInSharedCollectionNotifier;
+
+ if (notifier == null) return;
+
+ if (fileID == null) {
+ notifier.value = false;
+ return;
+ }
+
+ final isShared =
+ await CollectionsService.instance.isFileInSharedCollection(fileID);
+
+ // Guard: Only update if still showing the same file
+ // (user may have swiped to a different file while awaiting)
+ if (_files![_selectedIndexNotifier.value].uploadedFileID == fileID) {
+ notifier.value = isShared;
+ }
+ }
}
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 d6eb6aef67..ccd7fe713e 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
@@ -1,6 +1,7 @@
import "dart:async";
import 'dart:io';
+import "package:ente_icons/ente_icons.dart";
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import "package:flutter_svg/flutter_svg.dart";
@@ -23,6 +24,7 @@ import 'package:photos/services/collections_service.dart';
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/ente_theme.dart";
import "package:photos/ui/actions/file/file_actions.dart";
import 'package:photos/ui/collections/collection_action_sheet.dart';
@@ -81,10 +83,28 @@ class FileAppBarState extends State<FileAppBar> {
isGuestView = event.isGuestView;
});
});
+
+ // Listen to shared collection changes to rebuild actions
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ final notifier = InheritedDetailPageState.maybeOf(context)
+ ?.isInSharedCollectionNotifier;
+ notifier?.addListener(_onSharedCollectionChanged);
+ });
+ }
+
+ void _onSharedCollectionChanged() {
+ if (mounted) {
+ setState(() {
+ _reloadActions = true;
+ });
+ }
}
@override
void dispose() {
+ InheritedDetailPageState.maybeOf(context)
+ ?.isInSharedCollectionNotifier
+ .removeListener(_onSharedCollectionChanged);
_guestViewEventSubscription.cancel();
super.dispose();
}
@@ -161,6 +181,10 @@ class FileAppBarState extends State<FileAppBar> {
_actions.clear();
final bool isOwnedByUser = widget.file.isOwner;
final bool isFileUploaded = widget.file.isUploaded;
+ final isInSharedCollection = InheritedDetailPageState.maybeOf(context)
+ ?.isInSharedCollectionNotifier
+ .value ??
+ false;
bool isFileHidden = false;
if (isOwnedByUser && isFileUploaded) {
isFileHidden = CollectionsService.instance
@@ -234,6 +258,18 @@ class FileAppBarState extends State<FileAppBar> {
),
);
}
+ // Add to Album option - shown when file is in shared collection
+ // (moved from bottom bar to make room for social icons)
+ if (isInSharedCollection && isFileUploaded && !isFileHidden) {
+ items.add(
+ EntePopupMenuItem(
+ AppLocalizations.of(context).addToAlbum,
+ value: 10,
+ icon: EnteIcons.addToAlbum,
+ iconColor: Theme.of(context).iconTheme.color,
+ ),
+ );
+ }
// options for files owned by the user
if (isOwnedByUser && !isFileHidden && isFileUploaded) {
final bool isArchived =
@@ -405,6 +441,14 @@ class FileAppBarState extends State<FileAppBar> {
widget.onEditRequested(widget.file);
} else if (value == 12) {
await showDetailsSheet(context, widget.file);
+ } else if (value == 10) {
+ final selectedFiles = SelectedFiles();
+ selectedFiles.files.add(widget.file);
+ showCollectionActionSheet(
+ context,
+ selectedFiles: selectedFiles,
+ actionType: CollectionActionType.addFiles,
+ );
}
},
),
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
index 68b8e29fab..f9263314ff 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
@@ -18,6 +18,7 @@ import "package:photos/models/file/trash_file.dart";
import "package:photos/models/selected_files.dart";
import "package:photos/models/social/social_data_provider.dart";
import "package:photos/services/collections_service.dart";
+import "package:photos/states/detail_page_state.dart";
import "package:photos/ui/actions/file/file_actions.dart";
import "package:photos/ui/collections/collection_action_sheet.dart";
import "package:photos/ui/notification/toast.dart";
@@ -54,14 +55,12 @@ class FileBottomBarState extends State<FileBottomBar> {
bool isGuestView = false;
late final StreamSubscription<GuestViewEvent> _guestViewEventSubscription;
int? lastFileGenID;
- bool _isInSharedCollection = false;
bool _hasLiked = false;
int _commentCount = 0;
@override
void initState() {
super.initState();
- _updateSharedCollectionState();
_updateSocialState();
_guestViewEventSubscription =
Bus.instance.on<GuestViewEvent>().listen((event) {
@@ -75,30 +74,10 @@ class FileBottomBarState extends State<FileBottomBar> {
void didUpdateWidget(FileBottomBar oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.file.uploadedFileID != widget.file.uploadedFileID) {
- _updateSharedCollectionState();
_updateSocialState();
}
}
- Future<void> _updateSharedCollectionState() async {
- final fileID = widget.file.uploadedFileID;
- if (fileID == null) {
- _isInSharedCollection = false;
- safeRefresh();
- return;
- }
-
- final isShared =
- await CollectionsService.instance.isFileInSharedCollection(fileID);
-
- // Guard: Only update if still showing the same file
- // (user may have swiped to a different file while awaiting)
- if (widget.file.uploadedFileID == fileID) {
- _isInSharedCollection = isShared;
- safeRefresh();
- }
- }
-
Future<void> _updateSocialState({bool sync = false}) async {
if (widget.file.uploadedFileID == null) {
_hasLiked = false;
@@ -146,7 +125,17 @@ class FileBottomBarState extends State<FileBottomBar> {
}
}
- return _getBottomBar();
+ final sharedCollectionNotifier =
+ InheritedDetailPageState.maybeOf(context)?.isInSharedCollectionNotifier;
+
+ if (sharedCollectionNotifier == null) {
+ return _getBottomBar();
+ }
+
+ return ValueListenableBuilder<bool>(
+ valueListenable: sharedCollectionNotifier,
+ builder: (context, _, __) => _getBottomBar(),
+ );
}
void safeRefresh() {
@@ -159,6 +148,11 @@ class FileBottomBarState extends State<FileBottomBar> {
Logger("FileBottomBar")
.fine("building bottom bar ${widget.file.generatedID}");
+ final isInSharedCollection = InheritedDetailPageState.maybeOf(context)
+ ?.isInSharedCollectionNotifier
+ .value ??
+ false;
+
final List<Widget> children = [];
final bool isOwnedByUser =
widget.file.ownerID == null || widget.file.ownerID == widget.userID;
@@ -217,7 +211,8 @@ class FileBottomBarState extends State<FileBottomBar> {
);
// Add to album button for uploaded, non-hidden files
- if (widget.file.isUploaded && !isFileHidden) {
+ // Hide when in shared collection (moved to app bar popup menu)
+ if (widget.file.isUploaded && !isFileHidden && !isInSharedCollection) {
children.add(
Tooltip(
message: AppLocalizations.of(context).addToAlbum,
@@ -245,7 +240,7 @@ class FileBottomBarState extends State<FileBottomBar> {
}
// Add social icons (heart, comment) if file is in a shared collection
- if (_isInSharedCollection) {
+ if (isInSharedCollection) {
children.add(_buildHeartIcon());
children.add(_buildCommentIcon());
}