Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add recipient access selection sheet

AmanRajSinghMouryaee0d38249a15
diff --git a/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart b/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart
new file mode 100644
index 0000000000..6783f92ccc
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart
@@ -0,0 +1,186 @@
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:flutter/material.dart";
+import "package:photos/models/api/collection/user.dart";
+import "package:photos/models/collection/collection.dart";
+import "package:photos/ui/components/collection_share_badge.dart";
+import "package:photos/ui/sharing/share_components.dart";
+import "package:photos/ui/sharing/verify_identity_dialog.dart";
+import "package:photos/ui/sharing/widgets/selected_person_chip.dart";
+import "package:photos/ui/sharing/widgets/sharing_role.dart";
+
+Future<CollectionParticipantRole?> showChooseAccessSheet(
+ BuildContext context, {
+ required List<UserSuggestion> selected,
+ required CollectionParticipantRole initialRole,
+}) {
+ return showBottomSheetComponent<CollectionParticipantRole>(
+ context: context,
+ builder: (sheetContext) =>
+ _ChooseAccessSheet(selected: selected, initialRole: initialRole),
+ );
+}
+
+class _ChooseAccessSheet extends StatefulWidget {
+ const _ChooseAccessSheet({required this.selected, required this.initialRole});
+
+ final List<UserSuggestion> selected;
+ final CollectionParticipantRole initialRole;
+
+ @override
+ State<_ChooseAccessSheet> createState() => _ChooseAccessSheetState();
+}
+
+class _ChooseAccessSheetState extends State<_ChooseAccessSheet> {
+ final _selectedPeopleScrollController = ScrollController();
+ late CollectionParticipantRole _role;
+
+ @override
+ void initState() {
+ super.initState();
+ _role = widget.initialRole;
+ }
+
+ @override
+ void dispose() {
+ _selectedPeopleScrollController.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return ConstrainedBox(
+ constraints: BoxConstraints(
+ maxHeight: MediaQuery.sizeOf(context).height * 0.95,
+ ),
+ child: BottomSheetComponent(
+ title: context.strings.chooseAccess,
+ content: Flexible(
+ fit: FlexFit.loose,
+ child: SingleChildScrollView(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SelectedRecipientChips(
+ suggestions: widget.selected,
+ scrollController: _selectedPeopleScrollController,
+ onRemove: _removeSuggestion,
+ onLongPress: (suggestion) => showVerifyIdentitySheet(
+ context,
+ self: false,
+ email: suggestion.email,
+ ),
+ ),
+ ShareSectionTitle(context.strings.permissions),
+ ShareMenuGroup(
+ items: [
+ _PermissionRow(
+ label: context.strings.viewer,
+ description: context.strings.viewerRoleDescription,
+ icon: sharingRoleIcon(CollectionParticipantRole.viewer),
+ selected: _role == CollectionParticipantRole.viewer,
+ onTap: () => setState(
+ () => _role = CollectionParticipantRole.viewer,
+ ),
+ ),
+ _PermissionRow(
+ label: context.strings.collaborator,
+ description: context.strings.collaboratorRoleDescription,
+ icon: sharingRoleIcon(
+ CollectionParticipantRole.collaborator,
+ ),
+ selected: _role == CollectionParticipantRole.collaborator,
+ onTap: () => setState(
+ () => _role = CollectionParticipantRole.collaborator,
+ ),
+ ),
+ _PermissionRow(
+ label: context.strings.admin,
+ description: context.strings.adminRoleDescription,
+ icon: sharingRoleIcon(CollectionParticipantRole.admin),
+ selected: _role == CollectionParticipantRole.admin,
+ onTap: () => setState(
+ () => _role = CollectionParticipantRole.admin,
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ ),
+ actions: [
+ ButtonComponent(
+ label: _buttonLabel(context),
+ variant: ButtonComponentVariant.primary,
+ size: ButtonComponentSize.large,
+ isDisabled: widget.selected.isEmpty,
+ onTap: () => Navigator.of(context).pop(_role),
+ ),
+ ],
+ ),
+ );
+ }
+
+ void _removeSuggestion(UserSuggestion suggestion) {
+ setState(() {
+ widget.selected.removeWhere(
+ (selected) =>
+ selected.email.trim().toLowerCase() ==
+ suggestion.email.trim().toLowerCase(),
+ );
+ });
+ }
+
+ String _buttonLabel(BuildContext context) {
+ return switch (_role) {
+ CollectionParticipantRole.viewer => context.strings.addAsViewers(
+ count: widget.selected.length,
+ ),
+ CollectionParticipantRole.collaborator =>
+ context.strings.addAsCollaborators(count: widget.selected.length),
+ CollectionParticipantRole.admin => context.strings.addAsAdmins(
+ count: widget.selected.length,
+ ),
+ CollectionParticipantRole.unknown || CollectionParticipantRole.owner =>
+ context.strings.addAsViewers(count: widget.selected.length),
+ };
+ }
+}
+
+class _PermissionRow extends StatelessWidget {
+ const _PermissionRow({
+ required this.label,
+ required this.description,
+ required this.icon,
+ required this.selected,
+ required this.onTap,
+ });
+
+ final String label;
+ final String description;
+ final List<List<dynamic>> icon;
+ final bool selected;
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ return ShareMenuItem(
+ title: label,
+ subtitle: description,
+ icon: icon,
+ trailing: selected
+ ? const CollectionSelectedBadge()
+ : SizedBox.square(
+ dimension: IconSizes.small,
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ border: Border.all(color: context.componentColors.strokeDark),
+ ),
+ ),
+ ),
+ onTap: onTap,
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/sharing/widgets/selected_person_chip.dart b/mobile/apps/photos/lib/ui/sharing/widgets/selected_person_chip.dart
new file mode 100644
index 0000000000..772e94ad6c
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/sharing/widgets/selected_person_chip.dart
@@ -0,0 +1,226 @@
+import "dart:math" as math;
+
+import "package:ente_components/ente_components.dart";
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:photos/models/api/collection/user.dart";
+import "package:photos/services/contacts/contact_identity_resolver.dart";
+import "package:photos/ui/sharing/user_avator_widget.dart";
+
+class SelectedRecipientChips extends StatelessWidget {
+ const SelectedRecipientChips({
+ super.key,
+ required this.suggestions,
+ required this.scrollController,
+ this.onRemove,
+ this.onLongPress,
+ this.maxVisibleRows = 3,
+ });
+
+ static double chipExtent(BuildContext context) {
+ return FilterChipComponent.heightForTextScale(context);
+ }
+
+ final List<UserSuggestion> suggestions;
+ final ValueChanged<UserSuggestion>? onRemove;
+ final ValueChanged<UserSuggestion>? onLongPress;
+ final ScrollController scrollController;
+ final int maxVisibleRows;
+
+ @override
+ Widget build(BuildContext context) {
+ final chipExtent = SelectedRecipientChips.chipExtent(context);
+ final maxViewportHeight =
+ maxVisibleRows * chipExtent + (maxVisibleRows - 1) * Spacing.sm;
+
+ return AnimatedSize(
+ duration: Motion.standard,
+ curve: Curves.easeOutCubic,
+ alignment: AlignmentDirectional.topStart,
+ child: suggestions.isEmpty
+ ? const SizedBox.shrink()
+ : Padding(
+ padding: const EdgeInsets.only(bottom: Spacing.xl),
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final viewportMaxHeight = constraints.hasBoundedHeight
+ ? math.min(maxViewportHeight, constraints.maxHeight)
+ : maxViewportHeight;
+ if (viewportMaxHeight <= 0) {
+ return const SizedBox.shrink();
+ }
+ final colors = context.componentColors;
+ return ConstrainedBox(
+ constraints: BoxConstraints(
+ minWidth: constraints.maxWidth,
+ maxHeight: viewportMaxHeight,
+ ),
+ child: RawScrollbar(
+ key: const ValueKey("selected-people-scrollbar"),
+ controller: scrollController,
+ thumbVisibility: true,
+ trackVisibility: true,
+ interactive: true,
+ thickness: 5,
+ radius: const Radius.circular(3),
+ trackRadius: const Radius.circular(3),
+ thumbColor: colors.fillDarkest,
+ trackColor: colors.fillDark,
+ padding: EdgeInsets.zero,
+ child: SingleChildScrollView(
+ key: const ValueKey("selected-people-scroll"),
+ controller: scrollController,
+ primary: false,
+ padding: const EdgeInsetsDirectional.only(
+ end: Spacing.md,
+ ),
+ child: Wrap(
+ spacing: Spacing.sm,
+ runSpacing: Spacing.sm,
+ children: [
+ for (final suggestion in suggestions)
+ SelectedPersonChip(
+ key: ValueKey(
+ suggestion.email.trim().toLowerCase(),
+ ),
+ suggestion: suggestion,
+ onRemove: onRemove == null
+ ? null
+ : () => onRemove!(suggestion),
+ onLongPress: onLongPress == null
+ ? null
+ : () => onLongPress!(suggestion),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ },
+ ),
+ ),
+ );
+ }
+}
+
+class SelectedPersonChip extends StatefulWidget {
+ const SelectedPersonChip({
+ super.key,
+ required this.suggestion,
+ this.onRemove,
+ this.onLongPress,
+ });
+
+ final UserSuggestion suggestion;
+ final VoidCallback? onRemove;
+ final VoidCallback? onLongPress;
+
+ @override
+ State<SelectedPersonChip> createState() => _SelectedPersonChipState();
+}
+
+class _SelectedPersonChipState extends State<SelectedPersonChip>
+ with SingleTickerProviderStateMixin {
+ late final AnimationController _controller;
+ late final Animation<double> _animation;
+ bool _isRemoving = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _controller = AnimationController(vsync: this, duration: Motion.standard);
+ _animation = CurvedAnimation(
+ parent: _controller,
+ curve: Curves.easeOutCubic,
+ );
+ _controller.forward();
+ }
+
+ @override
+ void dispose() {
+ _controller.dispose();
+ super.dispose();
+ }
+
+ Future<void> _remove() async {
+ if (_isRemoving || widget.onRemove == null) {
+ return;
+ }
+ _isRemoving = true;
+ await _controller.reverse();
+ if (mounted) {
+ widget.onRemove!();
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final label = resolveSuggestionDisplayName(widget.suggestion);
+ return AnimatedBuilder(
+ key: ValueKey(
+ "selected-person-chip-${widget.suggestion.email.trim().toLowerCase()}",
+ ),
+ animation: _animation,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onLongPress: widget.onLongPress,
+ child: Container(
+ constraints: BoxConstraints(
+ minHeight: SelectedRecipientChips.chipExtent(context),
+ ),
+ padding: const EdgeInsets.symmetric(
+ horizontal: Spacing.sm,
+ vertical: Spacing.xs,
+ ),
+ decoration: BoxDecoration(
+ color: context.componentColors.fillLight,
+ borderRadius: BorderRadius.circular(Radii.button),
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ UserAvatarWidget.suggestion(
+ widget.suggestion,
+ type: AvatarType.medium,
+ ),
+ const SizedBox(width: Spacing.sm),
+ Flexible(
+ child: Text(
+ label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyles.mini,
+ ),
+ ),
+ if (widget.onRemove != null) ...[
+ const SizedBox(width: Spacing.xs),
+ GestureDetector(
+ key: ValueKey(
+ "remove-${widget.suggestion.email.trim().toLowerCase()}",
+ ),
+ behavior: HitTestBehavior.opaque,
+ onTap: _remove,
+ child: const Padding(
+ padding: EdgeInsets.all(Spacing.xs),
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: IconSizes.small,
+ ),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ),
+ builder: (context, child) => Opacity(
+ opacity: _animation.value,
+ child: Transform.scale(
+ scale: 0.96 + 0.04 * _animation.value,
+ alignment: AlignmentDirectional.centerStart,
+ child: child,
+ ),
+ ),
+ );
+ }
+}