Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Add offline link file selection UI - P1 (#12920)

aman-pilot2f67ab1c3c41
diff --git a/mobile/apps/photos/lib/ui/sharing/offline_link_selection_sheet.dart b/mobile/apps/photos/lib/ui/sharing/offline_link_selection_sheet.dart
new file mode 100644
index 0000000000..68e9b29565
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/sharing/offline_link_selection_sheet.dart
@@ -0,0 +1,131 @@
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/models/file_load_result.dart";
+import "package:photos/ui/viewer/gallery/gallery.dart";
+import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
+import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
+
+class OfflineLinkSelectionSheet extends StatelessWidget {
+ const OfflineLinkSelectionSheet({
+ super.key,
+ required this.files,
+ this.onCreateLink,
+ });
+ final List<EnteFile> files;
+ final Future<void> Function(List<EnteFile>)? onCreateLink;
+
+ @override
+ Widget build(BuildContext context) => FractionallySizedBox(
+ heightFactor: 0.86,
+ alignment: Alignment.bottomCenter,
+ child: GalleryBoundariesProvider(
+ child: Container(
+ clipBehavior: Clip.antiAlias,
+ decoration: BoxDecoration(
+ color: context.componentColors.backgroundBase,
+ borderRadius: const BorderRadius.vertical(
+ top: Radius.circular(Radii.bottomSheet),
+ ),
+ ),
+ child: SafeArea(
+ top: false,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const _SelectionHeader(),
+ const SizedBox(height: Spacing.lg),
+ Expanded(
+ child: GalleryFilesState(
+ child: Gallery(
+ initialFiles: files,
+ asyncLoader: (_, _, {limit, asc}) async =>
+ FileLoadResult(files, false),
+ tagPrefix: "offline_link_selection",
+ enableFileGrouping: false,
+ showSelectAll: false,
+ disablePinnedGroupHeader: true,
+ disableVerticalPaddingForScrollbar: true,
+ footer: const SizedBox.shrink(),
+ emptyState: Center(
+ child: Padding(
+ padding: const EdgeInsets.all(Spacing.xl),
+ child: Text(
+ pendingTranslation(
+ "No selected files are available on this device.",
+ ),
+ textAlign: TextAlign.center,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ Center(
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 428),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(
+ Spacing.xl,
+ Spacing.lg,
+ Spacing.xl,
+ Spacing.sm,
+ ),
+ child: ButtonComponent(
+ key: const ValueKey("offline-link-create-option"),
+ label: pendingTranslation("Create link"),
+ shouldSurfaceExecutionStates: false,
+ leading: const HugeIcon(
+ icon: HugeIcons.strokeRoundedLink02,
+ size: IconSizes.small,
+ ),
+ isDisabled: files.isEmpty,
+ // Remains disabled until real link creation is wired.
+ onTap: onCreateLink == null
+ ? null
+ : () => onCreateLink!(files),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+}
+
+class _SelectionHeader extends StatelessWidget {
+ const _SelectionHeader();
+
+ @override
+ Widget build(BuildContext context) => Padding(
+ padding: const EdgeInsets.fromLTRB(Spacing.xl, Spacing.xl, Spacing.xl, 0),
+ child: Row(
+ children: [
+ Expanded(
+ child: Text(
+ pendingTranslation("Share link"),
+ style: TextStyles.h2.copyWith(
+ color: context.componentColors.textBase,
+ ),
+ ),
+ ),
+ const SizedBox(width: Spacing.md),
+ IconButtonComponent(
+ tooltip: context.strings.close,
+ variant: IconButtonComponentVariant.circular,
+ shouldSurfaceExecutionStates: false,
+ icon: const HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: IconSizes.small,
+ ),
+ onTap: () => Navigator.of(context).pop(),
+ ),
+ ],
+ ),
+ );
+}
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
index 03e5c20235..cd5cc523a4 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
@@ -1,6 +1,7 @@
import "dart:async";
import "dart:io";
+import "package:ente_components/ente_components.dart";
import "package:ente_icons/ente_icons.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:ente_strings/ente_strings.dart";
@@ -46,6 +47,7 @@ import "package:photos/ui/components/bottom_action_bar/selection_action_button_w
import 'package:photos/ui/components/buttons/button_widget.dart';
import 'package:photos/ui/components/models/button_type.dart';
import 'package:photos/ui/notification/toast.dart';
+import "package:photos/ui/sharing/offline_link_selection_sheet.dart";
import "package:photos/ui/tools/collage/collage_creator_page.dart";
import "package:photos/ui/viewer/actions/suggest_delete_sheet.dart";
import "package:photos/ui/viewer/date/edit_date_sheet.dart";
@@ -227,6 +229,16 @@ class _FileSelectionActionsWidgetState
);
}
+ if (_canShowOfflineLinkOption(widget.selectedFiles.files)) {
+ items.add(
+ SelectionActionButton(
+ hugeIcon: HugeIcons.strokeRoundedLink02,
+ labelText: pendingTranslation("(i) Offline link"),
+ onTap: _showOfflineLinkShareSheet,
+ ),
+ );
+ }
+
if (widget.type.showCreateLink()) {
if (_cachedCollectionForSharedLink != null && anyUploadedFiles) {
items.add(
@@ -628,6 +640,24 @@ class _FileSelectionActionsWidgetState
widget.selectedFiles.clearAll();
}
+ Future<void> _showOfflineLinkShareSheet() async {
+ final files = widget.selectedFiles.files
+ .where((file) => file.localID != null)
+ .toList(growable: false);
+ await showBottomSheetComponent<void>(
+ context: context,
+ enableDrag: false,
+ builder: (_) => OfflineLinkSelectionSheet(files: files),
+ );
+ }
+
+ bool _canShowOfflineLinkOption(Iterable<EnteFile> files) {
+ // TODO: Move this entry point to local-gallery mode when the feature is ready.
+ return flagService.offlineLinkSharing &&
+ !isLocalGalleryMode &&
+ Configuration.instance.hasConfiguredAccount();
+ }
+
Future<void> _moveFiles() async {
if (split.pendingUploads.isNotEmpty || split.ownedByOtherUsers.isNotEmpty) {
widget.selectedFiles.unSelectAll(
diff --git a/mobile/packages/feature_flag/lib/src/flag_service.dart b/mobile/packages/feature_flag/lib/src/flag_service.dart
index 9428a2f1b3..dcf64bbc9c 100644
--- a/mobile/packages/feature_flag/lib/src/flag_service.dart
+++ b/mobile/packages/feature_flag/lib/src/flag_service.dart
@@ -53,6 +53,8 @@ class FlagService {
return (flags.internalUser || kDebugMode) && !isDisabled;
}
+ bool get offlineLinkSharing => internalUser;
+
bool get librarySharing =>
internalUser || _isServerFlagEnabled(_librarySharingFlag);