Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add selectable memory link sharing

Neeraj Guptab46f8279a377
diff --git a/mobile/apps/photos/assets/icons/memory-share-link-icon.svg b/mobile/apps/photos/assets/icons/memory-share-link-icon.svg
deleted file mode 100644
index f4b6f6dfa3..0000000000
--- a/mobile/apps/photos/assets/icons/memory-share-link-icon.svg
+++ /dev/null
@@ -1,5 +0,0 @@
-<svg width="27" height="27" viewBox="0 0 27 27" fill="none" xmlns="http://www.w3.org/2000/svg">
-<path d="M15.6253 5.125H13.542C10.5957 5.125 9.12258 5.125 8.20728 6.04029C7.29199 6.95558 7.29199 8.42872 7.29199 11.375V13.4583C7.29199 16.4046 7.29199 17.8777 8.20728 18.793C9.12258 19.7083 10.5957 19.7083 13.542 19.7083H15.6253C18.5716 19.7083 20.0447 19.7083 20.96 18.793C21.8753 17.8777 21.8753 16.4046 21.8753 13.4583V11.375" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
-<path d="M17.708 2H21.8747C23.3478 2 24.0844 2 24.5421 2.45765C24.9997 2.91529 24.9997 3.65186 24.9997 5.125V9.29167M23.958 3.04167L14.583 12.4167" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
-<path d="M16.6667 22.9597C15.7514 23.875 14.2782 23.875 11.332 23.875H9.375C6.42872 23.875 4.95558 23.875 4.04029 22.9597C3.125 22.0444 3.125 20.5713 3.125 17.625V15.668C3.125 12.7218 3.125 11.2486 4.04029 10.3333" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
-</svg>
diff --git a/mobile/apps/photos/changes/memory-sharing.md b/mobile/apps/photos/changes/memory-sharing.md
new file mode 100644
index 0000000000..5f9aecef6a
--- /dev/null
+++ b/mobile/apps/photos/changes/memory-sharing.md
@@ -0,0 +1 @@
+- Choose photos and videos before sharing a memory link.
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arb
index e8de4c8b79..366f4f718a 100644
--- a/mobile/apps/photos/lib/l10n/intl_en.arb
+++ b/mobile/apps/photos/lib/l10n/intl_en.arb
@@ -1220,6 +1220,17 @@
"favorite": "Favorite",
"removeFromFavorite": "Remove from favorites",
"shareMemories": "Share memories",
+ "shareMemory": "Share memory",
+ "shareItemCount": "{count, plural, one{Share {count} item} other{Share {count} items}}",
+ "@shareItemCount": {
+ "description": "Action to share the selected number of memory items",
+ "placeholders": {
+ "count": {
+ "example": "3",
+ "type": "int"
+ }
+ }
+ },
"shareTheseMemories": "Share these memories",
"shareThisPhoto": "Share this photo",
"shareThisVideo": "Share this video",
diff --git a/mobile/apps/photos/lib/models/memories/smart_memory.dart b/mobile/apps/photos/lib/models/memories/smart_memory.dart
index d9fe7d94cd..ca96b71ad1 100644
--- a/mobile/apps/photos/lib/models/memories/smart_memory.dart
+++ b/mobile/apps/photos/lib/models/memories/smart_memory.dart
@@ -4,6 +4,8 @@ import "package:photos/models/memories/memory.dart";
enum MemoryType { people, trips, clip, time, filler, onThisDay }
+const int kMaxSmartMemoryItems = 100;
+
MemoryType memoryTypeFromString(String type) {
switch (type) {
case "people":
@@ -35,7 +37,7 @@ class SmartMemory {
int? lastCreationTime;
SmartMemory(
- this.memories,
+ List<Memory> memories,
this.type,
this.title,
this.firstDateToShow,
@@ -43,10 +45,17 @@ class SmartMemory {
String? id,
this.firstCreationTime,
this.lastCreationTime,
- }) {
+ }) : memories = _capMemories(memories) {
this.id = id ?? newID(type.name);
}
+ static List<Memory> _capMemories(List<Memory> memories) {
+ if (memories.length <= kMaxSmartMemoryItems) {
+ return memories;
+ }
+ return memories.take(kMaxSmartMemoryItems).toList();
+ }
+
bool get notForShow => firstDateToShow == 0 && lastDateToShow == 0;
bool isOld() {
diff --git a/mobile/apps/photos/lib/services/memory_share_service.dart b/mobile/apps/photos/lib/services/memory_share_service.dart
index 9368dfd4e8..1cda28ac63 100644
--- a/mobile/apps/photos/lib/services/memory_share_service.dart
+++ b/mobile/apps/photos/lib/services/memory_share_service.dart
@@ -32,7 +32,7 @@ class MemoryShareService {
final Logger _logger = Logger("MemoryShareService");
static const int _shortFragmentSecretLength = 12;
- static const int _maxMemoryShareFiles = 30;
+ static const int _maxMemoryShareFiles = 100;
static final RegExp _base62SecretPattern = RegExp(r'^[0-9A-Za-z]{12}$');
static List<EnteFile> uniqueUploadedFiles(List<EnteFile> files) {
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 1ce9b15a8a..9c9cd62053 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
@@ -8,8 +8,6 @@ import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
-import "package:flutter_svg/flutter_svg.dart";
-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";
@@ -18,7 +16,6 @@ import "package:photos/events/reset_zoom_of_photo_view_event.dart";
import "package:photos/events/resume_video_event.dart";
import "package:photos/events/retry_failed_image_load_event.dart";
import "package:photos/generated/l10n.dart";
-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/models/memories/memory.dart";
@@ -31,9 +28,9 @@ import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/theme/text_style.dart";
import "package:photos/ui/actions/file/file_actions.dart";
-import "package:photos/ui/components/base_bottom_sheet.dart";
import "package:photos/ui/home/memories/custom_listener.dart";
import "package:photos/ui/home/memories/memory_progress_indicator.dart";
+import "package:photos/ui/home/memories/memory_share_sheet.dart";
import "package:photos/ui/home/memories/memory_video_prefetcher.dart";
import "package:photos/ui/viewer/file/file_widget.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
@@ -1189,53 +1186,47 @@ Future<void> _shareMemory(
String memoryTitle,
) async {
if (inheritedData.memories.isEmpty) return;
- final l10n = AppLocalizations.of(context);
final currentIndex = _clampedMemoryIndex(
inheritedData.indexNotifier.value,
inheritedData.memories.length,
);
if (currentIndex == null) return;
- final currentFile = inheritedData.memories[currentIndex].file;
- final shareSingleItemLabel = currentFile.isVideo
- ? _titleCase(l10n.videoSmallCase)
- : _titleCase(l10n.photoSmallCase);
final canShowMemoryShareLinkOption =
flagService.enableMemoryShareLink &&
!(isLocalGalleryMode && !Configuration.instance.hasConfiguredAccount());
- final shouldShareLink = await showBaseBottomSheet<bool>(
+ final result = await showMemoryShareSelectionSheet(
context,
- title: l10n.shareMemories,
- child: _MemoryShareSheet(
- canShowMemoryShareLinkOption: canShowMemoryShareLinkOption,
- shareSingleItemLabel: shareSingleItemLabel,
- ),
+ memories: inheritedData.memories,
+ initialIndex: currentIndex,
+ canShareMemoryLink: canShowMemoryShareLinkOption,
);
- if (!context.mounted || shouldShareLink == null) {
+ if (!context.mounted || result == null) {
return;
}
- if (shouldShareLink) {
- final shareLinkData = await _getOrCreateMemoryLink(
- context,
- inheritedData,
- memoryTitle,
- );
- if (!context.mounted || shareLinkData == null) {
+ switch (result.action) {
+ case MemoryShareSheetAction.shareMemory:
+ final shareLinkData = await _getOrCreateMemoryLink(
+ context,
+ result.selectedMemories,
+ memoryTitle,
+ );
+ if (!context.mounted || shareLinkData == null) {
+ return;
+ }
+ await shareText(shareLinkData.$1, context: context);
return;
- }
- await shareText(shareLinkData.$1, context: context);
- return;
+ case MemoryShareSheetAction.shareItems:
+ await share(context, Memory.filesFromMemories(result.selectedMemories));
}
-
- await share(context, [currentFile]);
}
Future<(String, int)?> _getOrCreateMemoryLink(
BuildContext context,
- FullScreenMemoryData inheritedData,
+ List<Memory> memories,
String memoryTitle,
) async {
- if (inheritedData.memories.isEmpty) return null;
+ if (memories.isEmpty) return null;
final l10n = AppLocalizations.of(context);
final dialog = createProgressDialog(context, l10n.creatingLink);
await dialog.show();
@@ -1243,7 +1234,7 @@ Future<(String, int)?> _getOrCreateMemoryLink(
final normalizedTitle = memoryTitle.trim();
final shareLinkData = await MemoryShareService.instance
.getOrCreateMemoryLink(
- memories: inheritedData.memories,
+ memories: memories,
title: normalizedTitle.isNotEmpty ? normalizedTitle : l10n.memories,
);
await dialog.hide();
@@ -1256,98 +1247,3 @@ Future<(String, int)?> _getOrCreateMemoryLink(
return null;
}
}
-
-String _titleCase(String value) {
- if (value.isEmpty) return value;
- return value[0].toUpperCase() + value.substring(1);
-}
-
-class _MemoryShareSheet extends StatelessWidget {
- final bool canShowMemoryShareLinkOption;
- final String shareSingleItemLabel;
-
- const _MemoryShareSheet({
- required this.canShowMemoryShareLinkOption,
- required this.shareSingleItemLabel,
- });
-
- @override
- Widget build(BuildContext context) {
- final l10n = AppLocalizations.of(context);
- return Row(
- children: [
- if (canShowMemoryShareLinkOption)
- _MemoryShareOption(
- icon: HugeIcons.strokeRoundedLink02,
- svgAssetPath: "assets/icons/memory-share-link-icon.svg",
- label: l10n.memories,
- onTap: () => Navigator.of(context).pop(true),
- ),
- if (canShowMemoryShareLinkOption) const SizedBox(width: 24),
- _MemoryShareOption(
- icon: HugeIcons.strokeRoundedShare05,
- label: shareSingleItemLabel,
- onTap: () => Navigator.of(context).pop(false),
- ),
- ],
- );
- }
-}
-
-class _MemoryShareOption extends StatelessWidget {
- final List<List<dynamic>> icon;
- final String label;
- final VoidCallback onTap;
- final String? svgAssetPath;
-
- const _MemoryShareOption({
- required this.icon,
- required this.label,
- required this.onTap,
- this.svgAssetPath,
- });
-
- @override
- Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
-
- return Expanded(
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: onTap,
- child: Container(
- decoration: BoxDecoration(
- color: colorScheme.fillDark,
- borderRadius: BorderRadius.circular(16),
- ),
- padding: const EdgeInsets.symmetric(vertical: 16),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- if (svgAssetPath != null)
- SvgPicture.asset(
- svgAssetPath!,
- width: 26,
- height: 26,
- colorFilter: ColorFilter.mode(
- colorScheme.textBase,
- BlendMode.srcIn,
- ),
- )
- else
- HugeIcon(icon: icon, color: colorScheme.textBase, size: 24),
- const SizedBox(height: 8),
- Text(
- label,
- textAlign: TextAlign.center,
- style: textTheme.small.copyWith(color: colorScheme.textBase),
- ),
- ],
- ),
- ),
- ),
- );
- }
-}
diff --git a/mobile/apps/photos/lib/ui/home/memories/memory_share_sheet.dart b/mobile/apps/photos/lib/ui/home/memories/memory_share_sheet.dart
new file mode 100644
index 0000000000..0df715c6b2
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/home/memories/memory_share_sheet.dart
@@ -0,0 +1,327 @@
+import "dart:math" as math;
+
+import "package:ente_components/components/chip_surface.dart";
+import "package:ente_components/ente_components.dart";
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:photos/generated/l10n.dart";
+import "package:photos/models/file_load_result.dart";
+import "package:photos/models/memories/memory.dart";
+import "package:photos/models/selected_files.dart";
+import "package:photos/ui/viewer/gallery/gallery.dart";
+import "package:photos/ui/viewer/gallery/state/boundary_reporter_mixin.dart";
+import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
+import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
+
+enum MemoryShareSheetAction { shareMemory, shareItems }
+
+class MemoryShareSheetResult {
+ final MemoryShareSheetAction action;
+ final List<Memory> selectedMemories;
+
+ MemoryShareSheetResult({
+ required this.action,
+ required List<Memory> selectedMemories,
+ }) : selectedMemories = List.unmodifiable(selectedMemories);
+}
+
+Future<MemoryShareSheetResult?> showMemoryShareSelectionSheet(
+ BuildContext context, {
+ required List<Memory> memories,
+ required int initialIndex,
+ required bool canShareMemoryLink,
+}) {
+ return showBottomSheetComponent<MemoryShareSheetResult>(
+ context: context,
+ builder: (_) => _MemoryShareSelectionSheet(
+ memories: memories,
+ initialIndex: initialIndex,
+ canShareMemoryLink: canShareMemoryLink,
+ ),
+ );
+}
+
+class _MemoryShareSelectionSheet extends StatefulWidget {
+ final List<Memory> memories;
+ final int initialIndex;
+ final bool canShareMemoryLink;
+
+ const _MemoryShareSelectionSheet({
+ required this.memories,
+ required this.initialIndex,
+ required this.canShareMemoryLink,
+ });
+
+ @override
+ State<_MemoryShareSelectionSheet> createState() =>
+ _MemoryShareSelectionSheetState();
+}
+
+class _MemoryShareSelectionSheetState
+ extends State<_MemoryShareSelectionSheet> {
+ late final List<Memory> _memories = List.unmodifiable(widget.memories);
+ late final _files = _memories
+ .map((memory) => memory.file)
+ .toList(growable: false);
+ late final SelectedFiles _selectedFiles;
+
+ bool get _hasSelection => _selectedFiles.files.isNotEmpty;
+
+ bool get _areAllSelected => _files.every(_selectedFiles.isFileSelected);
+
+ List<Memory> get _orderedSelection => _memories
+ .where((memory) => _selectedFiles.isFileSelected(memory.file))
+ .toList(growable: false);
+
+ @override
+ void initState() {
+ super.initState();
+ _selectedFiles = SelectedFiles()
+ ..selectAll({_memories[widget.initialIndex].file})
+ ..addListener(_onSelectionChanged);
+ }
+
+ @override
+ void dispose() {
+ _selectedFiles.dispose();
+ super.dispose();
+ }
+
+ void _onSelectionChanged() => setState(() {});
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = AppLocalizations.of(context);
+ final screenHeight = MediaQuery.sizeOf(context).height;
+ final sheetHeight = math.min(screenHeight * 0.792, screenHeight - 80);
+
+ return SizedBox(
+ height: sheetHeight,
+ child: GalleryBoundariesProvider(
+ child: BottomSheetComponent(
+ header: _MemoryShareSheetBoundary(
+ position: BoundaryPosition.top,
+ child: _buildHeader(context, l10n),
+ ),
+ showCloseButton: false,
+ padding: const EdgeInsets.symmetric(vertical: Spacing.xl),
+ content: Expanded(
+ child: Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),
+ child: _buildSelectionControls(context, l10n),
+ ),
+ const SizedBox(height: Spacing.lg),
+ Expanded(child: _buildGrid()),
+ ],
+ ),
+ ),
+ actions: _buildActions(l10n),
+ ),
+ ),
+ );
+ }
+
+ Widget _buildHeader(BuildContext context, AppLocalizations l10n) {
+ final colors = context.componentColors;
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),
+ child: SizedBox(
+ height: 38,
+ child: Row(
+ children: [
+ Expanded(
+ child: Text(
+ l10n.shareMemory,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyles.h1.copyWith(color: colors.textBase),
+ ),
+ ),
+ const SizedBox(width: Spacing.md),
+ IconButtonComponent(
+ key: const ValueKey("memory-share-close"),
+ tooltip: l10n.close,
+ variant: IconButtonComponentVariant.circular,
+ shouldSurfaceExecutionStates: false,
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: IconSizes.small,
+ ),
+ onTap: () => Navigator.of(context).pop(),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _buildSelectionControls(BuildContext context, AppLocalizations l10n) {
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ _buildSelectionChip(
+ key: const ValueKey("memory-share-selected-count"),
+ label: l10n.selectedPhotos(count: _selectedFiles.files.length),
+ icon: HugeIcons.strokeRoundedCancel01,
+ semanticLabel: l10n.clearSelection,
+ selected: _hasSelection,
+ onTap: _hasSelection ? _clearSelection : null,
+ ),
+ _buildSelectionChip(
+ key: const ValueKey("memory-share-select-all"),
+ label: l10n.selectAll,
+ icon: HugeIcons.strokeRoundedTick02,
+ semanticLabel: l10n.selectAll,
+ selected: _areAllSelected,
+ onTap: _areAllSelected ? null : _selectAll,
+ ),
+ ],
+ );
+ }
+
+ Widget _buildSelectionChip({
+ required Key key,
+ required String label,
+ required List<List<dynamic>> icon,
+ required String semanticLabel,
+ required bool selected,
+ required VoidCallback? onTap,
+ }) {
+ final colors = context.componentColors;
+ final foreground = onTap == null ? colors.textLighter : colors.textBase;
+ return ChipSurface(
+ key: key,
+ surfaceKey: ValueKey("$key-surface"),
+ enabled: onTap != null,
+ selected: selected,
+ semanticLabel: semanticLabel,
+ minWidth: 104,
+ minHeight: 36,
+ padding: const EdgeInsets.fromLTRB(Spacing.sm, 8, Spacing.md, 8),
+ background: colors.fillLight,
+ borderRadius: BorderRadius.circular(100),
+ onTap: onTap,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox(
+ width: 66,
+ child: Text(
+ label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ style: TextStyles.mini.copyWith(color: foreground),
+ ),
+ ),
+ const SizedBox(width: Spacing.xs),
+ ChipIconSlot(
+ color: foreground,
+ size: 12,
+ slotSize: 14,
+ child: HugeIcon(icon: icon),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _buildGrid() {
+ return GalleryFilesState(
+ child: Gallery(
+ initialFiles: _files,
+ asyncLoader: (_, _, {limit, asc}) async =>
+ FileLoadResult(_files, false),
+ tagPrefix: "memory_share_gallery",
+ selectedFiles: _selectedFiles,
+ enableFileGrouping: false,
+ inSelectionMode: true,
+ showSelectAll: false,
+ disablePinnedGroupHeader: true,
+ disableVerticalPaddingForScrollbar: true,
+ footer: const SizedBox.shrink(),
+ ),
+ );
+ }
+
+ List<Widget> _buildActions(AppLocalizations l10n) {
+ return [
+ _MemoryShareSheetBoundary(
+ position: BoundaryPosition.bottom,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (widget.canShareMemoryLink) ...[
+ _buildAction(
+ l10n.shareMemory,
+ MemoryShareSheetAction.shareMemory,
+ ),
+ const SizedBox(height: Spacing.md),
+ ],
+ _buildAction(
+ l10n.shareItemCount(count: _selectedFiles.files.length),
+ MemoryShareSheetAction.shareItems,
+ variant: widget.canShareMemoryLink
+ ? ButtonComponentVariant.secondary
+ : ButtonComponentVariant.primary,
+ ),
+ ],
+ ),
+ ),
+ ];
+ }
+
+ Widget _buildAction(
+ String label,
+ MemoryShareSheetAction action, {
+ ButtonComponentVariant variant = ButtonComponentVariant.primary,
+ }) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),
+ child: ButtonComponent(
+ label: label,
+ variant: variant,
+ isDisabled: !_hasSelection,
+ shouldSurfaceExecutionStates: false,
+ onTap: _hasSelection ? () => _complete(action) : null,
+ ),
+ );
+ }
+
+ void _clearSelection() => _selectedFiles.clearAll(fireEvent: false);
+
+ void _selectAll() => _selectedFiles.replaceSelection(_files.toSet());
+
+ void _complete(MemoryShareSheetAction action) {
+ Navigator.of(context).pop(
+ MemoryShareSheetResult(
+ action: action,
+ selectedMemories: _orderedSelection,
+ ),
+ );
+ }
+}
+
+class _MemoryShareSheetBoundary extends StatefulWidget {
+ final BoundaryPosition position;
+ final Widget child;
+
+ const _MemoryShareSheetBoundary({
+ required this.position,
+ required this.child,
+ });
+
+ @override
+ State<_MemoryShareSheetBoundary> createState() =>
+ _MemoryShareSheetBoundaryState();
+}
+
+class _MemoryShareSheetBoundaryState extends State<_MemoryShareSheetBoundary>
+ with BoundaryReporter {
+ @override
+ Widget build(BuildContext context) {
+ return boundaryWidget(position: widget.position, child: widget.child);
+ }
+}