Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Refresh captions in file viewers

ashilkn7d23e43f1354
diff --git a/mobile/apps/photos/changes/memory-captions.md b/mobile/apps/photos/changes/memory-captions.md
new file mode 100644
index 0000000000..07bc5ab68a
--- /dev/null
+++ b/mobile/apps/photos/changes/memory-captions.md
@@ -0,0 +1 @@
+- Added captions to photo and video memories.
diff --git a/mobile/apps/photos/changes/refresh-gallery-photo-captions.md b/mobile/apps/photos/changes/refresh-gallery-photo-captions.md
new file mode 100644
index 0000000000..4fdec89deb
--- /dev/null
+++ b/mobile/apps/photos/changes/refresh-gallery-photo-captions.md
@@ -0,0 +1 @@
+- Refreshed photo and live photo captions in the gallery viewer for a cleaner, more compact presentation.
diff --git a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
index 4678b398b3..0b7cb920ca 100644
--- a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
@@ -13,6 +13,7 @@ import "package:hugeicons/hugeicons.dart";
import "package:photos/core/configuration.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/details_sheet_event.dart";
+import "package:photos/events/file_caption_updated_event.dart";
import "package:photos/events/pause_video_event.dart";
import "package:photos/events/reset_zoom_of_photo_view_event.dart";
import "package:photos/events/resume_video_event.dart";
@@ -44,6 +45,10 @@ import "package:photos/utils/share_util.dart";
const _socialRightInset = 24.0;
const _socialToActionBarGap = 38.0;
+const _memoryCaptionHorizontalInset = 16.0;
+const _memoryCaptionActionBarGap = 4.0;
+const _memoryCaptionLineHeight = 16.0;
+const _memoryCaptionScrimTopPadding = 12.0;
//There are two states of variables that FullScreenMemory depends on:
//1. The list of memories
@@ -372,6 +377,8 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
late final StreamSubscription<DetailsSheetEvent>
_detailSheetEventSubscription;
+ late final StreamSubscription<FileCaptionUpdatedEvent>
+ _captionUpdatedSubscription;
@override
void initState() {
@@ -400,12 +407,28 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
}
},
);
+ _captionUpdatedSubscription = Bus.instance
+ .on<FileCaptionUpdatedEvent>()
+ .listen((event) {
+ if (!mounted) return;
+ final inheritedData = FullScreenMemoryData.of(context);
+ if (inheritedData == null) return;
+ final index = inheritedData.indexNotifier.value;
+ if (!_isValidMemoryIndex(index, inheritedData.memories.length)) {
+ return;
+ }
+ if (inheritedData.memories[index].file.generatedID ==
+ event.fileGeneratedID) {
+ setState(() {});
+ }
+ });
}
@override
void dispose() {
hasPointerOnScreenNotifier.removeListener(_hasPointerListener);
_detailSheetEventSubscription.cancel();
+ _captionUpdatedSubscription.cancel();
_socialControlsVisible.dispose();
super.dispose();
}
@@ -750,7 +773,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
);
},
),
- _MemoryViewerScrims(socialControlsVisible: _socialControlsVisible),
+ _MemoryViewerOverlays(
+ socialControlsVisible: _socialControlsVisible,
+ ),
ValueListenableBuilder<int>(
valueListenable: inheritedData.indexNotifier,
builder: (context, index, _) {
@@ -1161,70 +1186,123 @@ class _MemoryDateChevronPainter extends CustomPainter {
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
-class _MemoryViewerScrims extends StatelessWidget {
+class _MemoryViewerOverlays extends StatelessWidget {
final ValueListenable<bool> socialControlsVisible;
- const _MemoryViewerScrims({required this.socialControlsVisible});
+ const _MemoryViewerOverlays({required this.socialControlsVisible});
@override
Widget build(BuildContext context) {
- final topHeight = MediaQuery.paddingOf(context).top + 104;
- return IgnorePointer(
- child: Stack(
- fit: StackFit.expand,
- children: [
- Align(
- alignment: Alignment.topCenter,
- child: SizedBox(
- width: double.infinity,
- height: topHeight,
- child: const DecoratedBox(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [
- Color(0xB8000000),
- Color(0x70000000),
- Colors.transparent,
- ],
- stops: [0, 0.6, 1],
+ final inheritedData = FullScreenMemoryData.of(context);
+ if (inheritedData == null || inheritedData.memories.isEmpty) {
+ return const SizedBox.shrink();
+ }
+ final fullScreenState = context
+ .findAncestorStateOfType<_FullScreenMemoryState>()!;
+ final safePadding = MediaQuery.paddingOf(context);
+ return ValueListenableBuilder<int>(
+ valueListenable: inheritedData.indexNotifier,
+ builder: (context, index, _) {
+ final safeIndex = _clampedMemoryIndex(
+ index,
+ inheritedData.memories.length,
+ );
+ if (safeIndex == null) return const SizedBox.shrink();
+ final file = inheritedData.memories[safeIndex].file;
+ final caption = file.caption;
+ final captionText = caption == null || caption.isEmpty
+ ? null
+ : '"$caption"';
+ return Stack(
+ fit: StackFit.expand,
+ children: [
+ IgnorePointer(
+ child: Align(
+ alignment: Alignment.topCenter,
+ child: SizedBox(
+ width: double.infinity,
+ height: safePadding.top + 104,
+ child: const DecoratedBox(
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [
+ Color(0xB8000000),
+ Color(0x70000000),
+ Colors.transparent,
+ ],
+ stops: [0, 0.6, 1],
+ ),
+ ),
),
),
),
),
- ),
- Align(
- alignment: Alignment.bottomCenter,
- child: ValueListenableBuilder<bool>(
- valueListenable: socialControlsVisible,
- builder: (context, isVisible, _) {
- final bottomInset = MediaQuery.paddingOf(context).bottom;
- return AnimatedContainer(
- duration: const Duration(milliseconds: 200),
- curve: Curves.easeOut,
- width: double.infinity,
- height: isVisible
- ? kMemorySocialScrimHeight
- : bottomInset + kMemoryBottomActionBarHeight,
- decoration: const BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.bottomCenter,
- end: Alignment.topCenter,
- colors: [
- Color.fromARGB(97, 0, 0, 0),
- Color.fromARGB(42, 0, 0, 0),
- Colors.transparent,
- ],
- stops: [0, 0.5, 1],
+ IgnorePointer(
+ child: Align(
+ alignment: Alignment.bottomCenter,
+ child: ValueListenableBuilder<bool>(
+ valueListenable: socialControlsVisible,
+ builder: (context, socialControlsVisible, _) {
+ return AnimatedContainer(
+ duration: const Duration(milliseconds: 200),
+ curve: Curves.easeOut,
+ width: double.infinity,
+ height: socialControlsVisible
+ ? kMemorySocialScrimHeight
+ : safePadding.bottom +
+ kMemoryBottomActionBarHeight +
+ (captionText == null
+ ? 0
+ : _memoryCaptionActionBarGap +
+ _memoryCaptionLineHeight +
+ _memoryCaptionScrimTopPadding),
+ decoration: const BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.bottomCenter,
+ end: Alignment.topCenter,
+ colors: [
+ Color.fromARGB(97, 0, 0, 0),
+ Color.fromARGB(42, 0, 0, 0),
+ Colors.transparent,
+ ],
+ stops: [0, 0.5, 1],
+ ),
+ ),
+ );
+ },
+ ),
+ ),
+ ),
+ if (captionText != null)
+ Positioned(
+ left: safePadding.left + _memoryCaptionHorizontalInset,
+ right: safePadding.right + _memoryCaptionHorizontalInset,
+ bottom:
+ safePadding.bottom +
+ kMemoryBottomActionBarHeight +
+ _memoryCaptionActionBarGap,
+ child: Align(
+ alignment: Alignment.centerLeft,
+ child: GestureDetector(
+ onTap: () => fullScreenState._runWithViewerPaused(
+ () => showDetailsSheet(context, file),
+ ),
+ child: Text(
+ captionText,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: component.TextStyles.mini.copyWith(
+ color: Colors.white.withValues(alpha: 0.8),
+ ),
),
),
- );
- },
- ),
- ),
- ],
- ),
+ ),
+ ),
+ ],
+ );
+ },
);
}
}
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 3c6caa0b56..a0d91e460f 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -13,6 +13,7 @@ import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/errors.dart';
import "package:photos/core/event_bus.dart";
+import "package:photos/events/file_caption_updated_event.dart";
import "package:photos/events/guest_view_event.dart";
import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
@@ -24,6 +25,9 @@ import "package:photos/module/download/thumbnail.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/collections_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/common/fast_scroll_physics.dart";
import 'package:photos/ui/notification/toast.dart';
import "package:photos/ui/social/widgets/file_social_overlay.dart";
@@ -41,6 +45,10 @@ import 'package:photos/utils/dialog_util.dart';
const _socialRightInset = 24.0;
const _socialBottomBarClearance = 130.0;
+const _galleryBottomBarHeight = 60.0;
+const _galleryCaptionGap = 12.0;
+const _galleryCaptionLineHeight = 16.0;
+const _galleryCaptionScrimTopPadding = 12.0;
enum DetailPageMode { minimalistic, full }
@@ -158,6 +166,8 @@ class _BodyState extends State<_Body> {
bool isGuestView = false;
bool swipeLocked = false;
late final StreamSubscription<GuestViewEvent> _guestViewEventSubscription;
+ late final StreamSubscription<FileCaptionUpdatedEvent>
+ _captionUpdatedSubscription;
QrCodeDetectionHelper? _qrHelper;
final Map<String, File> _renderedFiles = {};
@@ -180,6 +190,13 @@ class _BodyState extends State<_Body> {
swipeLocked = event.swipeLocked;
});
});
+ _captionUpdatedSubscription = Bus.instance
+ .on<FileCaptionUpdatedEvent>()
+ .listen((event) {
+ if (event.fileGeneratedID == _selectedFile?.generatedID) {
+ setState(() {});
+ }
+ });
if (flagService.qrFeatureEnabled &&
widget.config.mode != DetailPageMode.minimalistic) {
_qrHelper = QrCodeDetectionHelper();
@@ -202,6 +219,7 @@ class _BodyState extends State<_Body> {
@override
void dispose() {
_guestViewEventSubscription.cancel();
+ _captionUpdatedSubscription.cancel();
_pageController.dispose();
_selectedIndexNotifier.dispose();
_qrHelper?.dispose();
@@ -294,17 +312,28 @@ class _BodyState extends State<_Body> {
),
ValueListenableBuilder(
builder: (BuildContext context, int selectedIndex, _) {
- return widget.config.mode == DetailPageMode.minimalistic
- ? const SizedBox()
- : FileBottomBar(
- _files![selectedIndex],
+ final file = _files![selectedIndex];
+ final fullScreenNotifier = InheritedDetailPageState.of(
+ context,
+ ).enableFullScreenNotifier;
+ return Stack(
+ children: [
+ _GalleryBottomOverlay(
+ file: file,
+ mode: widget.config.mode,
+ isGuestView: isGuestView,
+ enableFullScreenNotifier: fullScreenNotifier,
+ ),
+ if (widget.config.mode != DetailPageMode.minimalistic)
+ FileBottomBar(
+ file,
onFileRemoved: _onFileRemoved,
userID: Configuration.instance.getUserID(),
- enableFullScreenNotifier: InheritedDetailPageState.of(
- context,
- ).enableFullScreenNotifier,
+ enableFullScreenNotifier: fullScreenNotifier,
isLocalOnlyContext: widget.config.isLocalOnlyContext,
- );
+ ),
+ ],
+ );
},
valueListenable: _selectedIndexNotifier,
),
@@ -652,6 +681,105 @@ class _BodyState extends State<_Body> {
}
}
+class _GalleryBottomOverlay extends StatelessWidget {
+ final EnteFile file;
+ final DetailPageMode mode;
+ final bool isGuestView;
+ final ValueListenable<bool> enableFullScreenNotifier;
+
+ const _GalleryBottomOverlay({
+ required this.file,
+ required this.mode,
+ required this.isGuestView,
+ required this.enableFullScreenNotifier,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final supportsCaption =
+ file.fileType == FileType.image || file.fileType == FileType.livePhoto;
+ final caption = supportsCaption ? file.caption : null;
+ final captionText = caption == null || caption.isEmpty
+ ? null
+ : '"$caption"';
+ final hasBottomBar = mode != DetailPageMode.minimalistic && !isGuestView;
+ if (captionText == null && !hasBottomBar) {
+ return const SizedBox.shrink();
+ }
+
+ final safePadding = MediaQuery.paddingOf(context);
+ return ValueListenableBuilder<bool>(
+ valueListenable: enableFullScreenNotifier,
+ builder: (context, isFullScreen, _) {
+ return IgnorePointer(
+ ignoring: isFullScreen,
+ child: AnimatedOpacity(
+ opacity: isFullScreen ? 0 : 1,
+ duration: const Duration(milliseconds: 200),
+ child: Stack(
+ children: [
+ Align(
+ alignment: Alignment.bottomCenter,
+ child: IgnorePointer(
+ child: SizedBox(
+ width: double.infinity,
+ height:
+ safePadding.bottom +
+ _galleryBottomBarHeight +
+ (captionText == null
+ ? 0
+ : _galleryCaptionGap +
+ _galleryCaptionLineHeight +
+ _galleryCaptionScrimTopPadding),
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ gradient: LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [
+ Colors.transparent,
+ Colors.black.withValues(alpha: 0.6),
+ Colors.black.withValues(alpha: 0.72),
+ ],
+ stops: const [0, 0.8, 1],
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ if (captionText != null)
+ Positioned(
+ left: safePadding.left + 16,
+ right: safePadding.right + 16,
+ bottom:
+ safePadding.bottom +
+ _galleryBottomBarHeight +
+ _galleryCaptionGap,
+ child: Align(
+ alignment: Alignment.centerLeft,
+ child: GestureDetector(
+ onTap: () => showDetailsSheet(context, file),
+ child: Text(
+ captionText,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: getEnteTextTheme(context).mini.copyWith(
+ color: textBaseDark.withValues(alpha: 0.8),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ },
+ );
+ }
+}
+
/// Must remain under a [Stack] because this widget builds a [Positioned].
class _GallerySocialOverlay extends StatelessWidget {
final EnteFile file;
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 0b2136aac1..dde91c2739 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
@@ -206,27 +206,13 @@ class FileBottomBarState extends State<FileBottomBar> {
curve: Curves.easeInOut,
child: Align(
alignment: Alignment.bottomCenter,
- child: Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [
- Colors.transparent,
- Colors.black.withValues(alpha: 0.6),
- Colors.black.withValues(alpha: 0.72),
- ],
- stops: const [0, 0.8, 1],
- ),
- ),
- child: SafeArea(
- top: false,
- left: false,
- right: false,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: children,
- ),
+ child: SafeArea(
+ top: false,
+ left: false,
+ right: false,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceAround,
+ children: children,
),
),
),
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 33c89dbf79..4c2689b1ab 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart
@@ -11,7 +11,6 @@ import 'package:photos/core/cache/thumbnail_in_memory_cache.dart';
import 'package:photos/core/constants.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/files_db.dart';
-import "package:photos/events/file_caption_updated_event.dart";
import "package:photos/events/files_updated_event.dart";
import 'package:photos/events/local_photos_updated_event.dart';
import "package:photos/events/reset_zoom_of_photo_view_event.dart";
@@ -24,8 +23,6 @@ import "package:photos/module/metadata/exif.dart";
import "package:photos/service_locator.dart" show flagService;
import "package:photos/src/rust/api/image_processing_api.dart" as rust_image;
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/common/loading_widget.dart';
import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
@@ -88,8 +85,6 @@ class _ZoomableImageState extends State<ZoomableImage> {
// Baseline PhotoView scale for the current image/controller when the image
// is at its contained size. ZoomTransform.scale is reported relative to this.
double? _initialScale;
- late final StreamSubscription<FileCaptionUpdatedEvent>
- _captionUpdatedSubscription;
late final StreamSubscription<ResetZoomOfPhotoView> _resetZoomSubscription;
late final StreamSubscription<RetryFailedImageLoadEvent>
_retryFailedLoadSubscription;
@@ -135,16 +130,6 @@ class _ZoomableImageState extends State<ZoomableImage> {
_subscribeToZoomStream();
- _captionUpdatedSubscription = Bus.instance
- .on<FileCaptionUpdatedEvent>()
- .listen((event) {
- if (event.fileGeneratedID == _photo.generatedID) {
- if (mounted) {
- setState(() {});
- }
- }
- });
-
_resetZoomSubscription = Bus.instance.on<ResetZoomOfPhotoView>().listen((
event,
) {
@@ -197,7 +182,6 @@ class _ZoomableImageState extends State<ZoomableImage> {
_zoomStreamSubscription?.cancel();
_photoViewController.dispose();
_scaleStateController.dispose();
- _captionUpdatedSubscription.cancel();
_resetZoomSubscription.cancel();
_retryFailedLoadSubscription.cancel();
super.dispose();
@@ -301,69 +285,7 @@ class _ZoomableImageState extends State<ZoomableImage> {
};
return GestureDetector(
onVerticalDragUpdate: verticalDragCallback,
- child: widget.photo.caption?.isNotEmpty ?? false
- ? Stack(
- clipBehavior: Clip.none,
- children: [
- content,
- Positioned(
- bottom: 72 + MediaQuery.paddingOf(context).bottom,
- left: 0,
- right: 0,
- child: ValueListenableBuilder<bool>(
- valueListenable:
- InheritedDetailPageState.maybeOf(
- context,
- )?.enableFullScreenNotifier ??
- ValueNotifier(false),
- builder: (context, doNotShowCaption, _) {
- return AnimatedOpacity(
- opacity: doNotShowCaption ? 0.0 : 1.0,
- duration: const Duration(milliseconds: 200),
- child: IgnorePointer(
- ignoring: doNotShowCaption,
- child: GestureDetector(
- onTap: () {
- showDetailsSheet(context, widget.photo);
- },
- child: Container(
- color: Colors.black.withValues(alpha: 0.1),
- width: double.infinity,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Padding(
- padding: const EdgeInsets.symmetric(
- vertical: 4.0,
- horizontal: 8.0,
- ),
- child: SizedBox(
- width:
- MediaQuery.sizeOf(context).width - 16,
- child: Center(
- child: Text(
- widget.photo.caption!,
- maxLines: 3,
- overflow: TextOverflow.ellipsis,
- style: getEnteTextTheme(
- context,
- ).mini.copyWith(color: textBaseDark),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- );
- },
- ),
- ),
- ],
- )
- : content,
+ child: content,
);
}