Skip to content

armgit / ente

Public Imported from GitHub
0

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

Improve album participant controls

AmanRajSinghMourya9631ab37aaf6
diff --git a/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart b/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart
index 6783f92ccc..f926f9cbd6 100644
--- a/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart
+++ b/mobile/apps/photos/lib/ui/sharing/choose_access_sheet.dart
@@ -3,7 +3,6 @@ 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";
@@ -74,35 +73,17 @@ class _ChooseAccessSheetState extends State<_ChooseAccessSheet> {
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,
+ for (final role in shareableCollectionRoles)
+ ShareMenuItem(
+ title: shareableRoleLabel(context, role),
+ subtitle: shareableRoleDescription(context, role),
+ icon: albumSharingRoleIcon(role),
+ trailing: RadioComponent(
+ selected: _role == role,
+ onChanged: (_) => _selectRole(role),
+ ),
+ onTap: () => _selectRole(role),
),
- ),
- _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,
- ),
- ),
],
),
],
@@ -126,12 +107,16 @@ class _ChooseAccessSheetState extends State<_ChooseAccessSheet> {
setState(() {
widget.selected.removeWhere(
(selected) =>
- selected.email.trim().toLowerCase() ==
- suggestion.email.trim().toLowerCase(),
+ normalizedSharingEmail(selected.email) ==
+ normalizedSharingEmail(suggestion.email),
);
});
}
+ void _selectRole(CollectionParticipantRole role) {
+ setState(() => _role = role);
+ }
+
String _buttonLabel(BuildContext context) {
return switch (_role) {
CollectionParticipantRole.viewer => context.strings.addAsViewers(
@@ -147,40 +132,3 @@ class _ChooseAccessSheetState extends State<_ChooseAccessSheet> {
};
}
}
-
-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/participant_role_row.dart b/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_row.dart
index 4cef95f3e8..acaed5b5d6 100644
--- a/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_row.dart
+++ b/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_row.dart
@@ -64,11 +64,16 @@ class _ParticipantRoleRowState extends State<ParticipantRoleRow> {
onSelected: (action) => action == _ParticipantRoleAction.remove
? _removeParticipant()
: _changeRole(action.role!),
- child: HugeIcon(
- icon: sharingRoleIcon(role),
- color: context.componentColors.textBase,
- size: IconSizes.small,
- strokeWidth: 1.6,
+ child: SizedBox.square(
+ dimension: kMinInteractiveDimension,
+ child: Center(
+ child: HugeIcon(
+ icon: albumSharingRoleIcon(role),
+ color: context.componentColors.textBase,
+ size: IconSizes.small,
+ strokeWidth: 1.6,
+ ),
+ ),
),
),
);
@@ -78,31 +83,23 @@ class _ParticipantRoleRowState extends State<ParticipantRoleRow> {
BuildContext context,
) {
final colors = context.componentColors;
+ final activeRole = widget.collection.getRole(widget.user.id);
return [
- EntePopupMenuOption(
- value: _ParticipantRoleAction.viewer,
- label: context.strings.viewer,
- leadingWidget: HugeIcon(
- icon: sharingRoleIcon(CollectionParticipantRole.viewer),
- size: IconSizes.small,
- ),
- ),
- EntePopupMenuOption(
- value: _ParticipantRoleAction.collaborator,
- label: context.strings.collaborator,
- leadingWidget: HugeIcon(
- icon: sharingRoleIcon(CollectionParticipantRole.collaborator),
- size: IconSizes.small,
- ),
- ),
- EntePopupMenuOption(
- value: _ParticipantRoleAction.admin,
- label: context.strings.admin,
- leadingWidget: HugeIcon(
- icon: sharingRoleIcon(CollectionParticipantRole.admin),
- size: IconSizes.small,
- ),
- ),
+ for (final action in _ParticipantRoleAction.values)
+ if (action.role case final role?)
+ EntePopupMenuOption(
+ value: action,
+ label: shareableRoleLabel(context, role),
+ leadingWidget: HugeIcon(
+ icon: albumSharingRoleIcon(role),
+ size: IconSizes.small,
+ ),
+ isActive: role == activeRole,
+ activeTrailingWidget: const HugeIcon(
+ icon: HugeIcons.strokeRoundedTick02,
+ size: IconSizes.small,
+ ),
+ ),
EntePopupMenuOption(
value: _ParticipantRoleAction.remove,
label: context.strings.remove,
diff --git a/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart b/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart
index 0f97218f33..2033fb975c 100644
--- a/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart
+++ b/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart
@@ -34,17 +34,36 @@ class _ScrollableParticipantRosterState
@override
Widget build(BuildContext context) {
const maxVisibleRows = 3;
+ final rowExtent = _rowExtent(context);
+ final hasMultipleRows = widget.rows.length > 1;
+ final itemSpacing = hasMultipleRows ? Spacing.xs : 0.0;
+ final groupPadding = hasMultipleRows ? Spacing.sm : 0.0;
final visibleRows = math.min(widget.rows.length, maxVisibleRows);
- final viewportHeight = _groupHeight(context, visibleRows);
+ final viewportHeight =
+ visibleRows * rowExtent +
+ groupPadding * 2 +
+ math.max(0, visibleRows - 1) * itemSpacing;
final showScrollbar = widget.rows.length > maxVisibleRows;
final roster = ClipRRect(
key: const ValueKey("participant-roster-clip"),
borderRadius: BorderRadius.circular(Radii.button),
- child: SingleChildScrollView(
- key: const ValueKey("participant-roster-scroll"),
- controller: _scrollController,
- primary: false,
- child: ShareMenuGroup(items: widget.rows),
+ child: ColoredBox(
+ color: context.componentColors.fillLight,
+ child: ListView.builder(
+ key: const ValueKey("participant-roster-scroll"),
+ controller: _scrollController,
+ primary: false,
+ padding: EdgeInsets.only(
+ top: groupPadding,
+ bottom: groupPadding - itemSpacing,
+ ),
+ itemCount: widget.rows.length,
+ itemExtent: rowExtent + itemSpacing,
+ itemBuilder: (context, index) => Padding(
+ padding: EdgeInsets.only(bottom: itemSpacing),
+ child: widget.rows[index],
+ ),
+ ),
),
);
return SizedBox(
@@ -63,15 +82,12 @@ class _ScrollableParticipantRosterState
);
}
- double _groupHeight(BuildContext context, int itemCount) {
+ double _rowExtent(BuildContext context) {
const textStyle = TextStyles.body;
final textExtent =
MediaQuery.textScalerOf(context).scale(textStyle.fontSize!) *
textStyle.height!;
- final rowExtent = math.max(60.0, textExtent + 20.0);
- return itemCount * rowExtent +
- (itemCount > 1 ? Spacing.sm * 2 : 0) +
- math.max(0, itemCount - 1) * Spacing.xs;
+ return math.max(kMinInteractiveDimension, textExtent) + 20.0;
}
}
@@ -101,7 +117,7 @@ class ParticipantRow extends StatelessWidget {
trailing:
trailing ??
HugeIcon(
- icon: sharingRoleIcon(role),
+ icon: albumSharingRoleIcon(role),
color: colors.textLightest,
size: IconSizes.small,
strokeWidth: 1.6,
diff --git a/mobile/apps/photos/lib/ui/sharing/widgets/sharing_role.dart b/mobile/apps/photos/lib/ui/sharing/widgets/sharing_role.dart
index d3fe1a7761..ece1138e45 100644
--- a/mobile/apps/photos/lib/ui/sharing/widgets/sharing_role.dart
+++ b/mobile/apps/photos/lib/ui/sharing/widgets/sharing_role.dart
@@ -1,7 +1,15 @@
+import "package:ente_strings/ente_strings.dart";
+import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
import "package:photos/models/api/collection/user.dart";
import "package:photos/models/collection/collection.dart";
+const shareableCollectionRoles = [
+ CollectionParticipantRole.viewer,
+ CollectionParticipantRole.collaborator,
+ CollectionParticipantRole.admin,
+];
+
List<List<dynamic>> sharingRoleIcon(CollectionParticipantRole role) {
return switch (role) {
CollectionParticipantRole.owner ||
@@ -12,6 +20,51 @@ List<List<dynamic>> sharingRoleIcon(CollectionParticipantRole role) {
};
}
+List<List<dynamic>> albumSharingRoleIcon(CollectionParticipantRole role) {
+ return switch (role) {
+ CollectionParticipantRole.owner ||
+ CollectionParticipantRole.admin => HugeIcons.strokeRoundedCrown03,
+ _ => sharingRoleIcon(role),
+ };
+}
+
+String normalizedSharingEmail(String email) => email.trim().toLowerCase();
+
+bool collectionNeedsShare(Collection collection, String email) {
+ final normalized = normalizedSharingEmail(email);
+ return normalizedSharingEmail(collection.owner.email) != normalized &&
+ !collection.sharees.any(
+ (sharee) => normalizedSharingEmail(sharee.email) == normalized,
+ );
+}
+
+String shareableRoleLabel(
+ BuildContext context,
+ CollectionParticipantRole role,
+) {
+ return switch (role) {
+ CollectionParticipantRole.viewer => context.strings.viewer,
+ CollectionParticipantRole.collaborator => context.strings.collaborator,
+ CollectionParticipantRole.admin => context.strings.admin,
+ CollectionParticipantRole.owner ||
+ CollectionParticipantRole.unknown => context.strings.viewer,
+ };
+}
+
+String shareableRoleDescription(
+ BuildContext context,
+ CollectionParticipantRole role,
+) {
+ return switch (role) {
+ CollectionParticipantRole.viewer => context.strings.viewerRoleDescription,
+ CollectionParticipantRole.collaborator =>
+ context.strings.collaboratorRoleDescription,
+ CollectionParticipantRole.admin => context.strings.adminRoleDescription,
+ CollectionParticipantRole.owner ||
+ CollectionParticipantRole.unknown => context.strings.viewerRoleDescription,
+ };
+}
+
int sharingRoleRank(CollectionParticipantRole role) {
return switch (role) {
CollectionParticipantRole.owner => -1,
diff --git a/mobile/apps/photos/test/ui/sharing/sharing_helpers_test.dart b/mobile/apps/photos/test/ui/sharing/sharing_helpers_test.dart
new file mode 100644
index 0000000000..9fa9933eee
--- /dev/null
+++ b/mobile/apps/photos/test/ui/sharing/sharing_helpers_test.dart
@@ -0,0 +1,134 @@
+import 'package:ente_components/ente_components.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:photos/models/api/collection/user.dart';
+import 'package:photos/models/collection/collection.dart';
+import 'package:photos/ui/sharing/share_components.dart';
+import 'package:photos/ui/sharing/widgets/participant_row.dart';
+import 'package:photos/ui/sharing/widgets/sharing_role.dart';
+
+void main() {
+ test('normalizes sharing emails for identity comparisons', () {
+ expect(
+ normalizedSharingEmail(' [email protected] '),
+ );
+ });
+
+ group('collectionNeedsShare', () {
+ final collection = _collection([
+ User(
+ id: 2,
+ email: ' [email protected] ',
+ role: CollectionParticipantRole.collaborator.toStringVal(),
+ ),
+ ]);
+
+ test('rejects the owner and existing sharees after normalization', () {
+ expect(collectionNeedsShare(collection, ' [email protected] '), isFalse);
+ expect(
+ collectionNeedsShare(collection, '[email protected]'),
+ isFalse,
+ );
+ });
+
+ test('accepts a recipient without access', () {
+ expect(collectionNeedsShare(collection, '[email protected]'), isTrue);
+ });
+ });
+
+ test('sorts sharees by role and then email', () {
+ final collection = _collection([
+ User(id: 4, email: '[email protected]'),
+ User(
+ id: 3,
+ email: '[email protected]',
+ role: CollectionParticipantRole.collaborator.toStringVal(),
+ ),
+ User(
+ id: 2,
+ email: '[email protected]',
+ role: CollectionParticipantRole.admin.toStringVal(),
+ ),
+ User(
+ id: 5,
+ email: '[email protected]',
+ role: CollectionParticipantRole.admin.toStringVal(),
+ ),
+ ]);
+
+ expect(sortedCollectionSharees(collection).map((user) => user.id), [
+ 5,
+ 2,
+ 3,
+ 4,
+ ]);
+ });
+
+ testWidgets('participant roster builds rows lazily', (tester) async {
+ final builtRows = <int>{};
+
+ await tester.pumpWidget(
+ _testApp(
+ ScrollableParticipantRoster(
+ rows: [
+ for (var index = 0; index < 60; index++)
+ Builder(
+ builder: (context) {
+ builtRows.add(index);
+ return ShareMenuItem(
+ key: ValueKey('participant-$index'),
+ title: 'Participant $index',
+ trailing: const SizedBox.square(
+ dimension: kMinInteractiveDimension,
+ ),
+ isDisabled: true,
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ );
+
+ expect(builtRows.length, lessThan(60));
+ expect(find.byKey(const ValueKey('participant-59')), findsNothing);
+
+ await tester.drag(
+ find.byKey(const ValueKey('participant-roster-scroll')),
+ const Offset(0, -5000),
+ );
+ await tester.pumpAndSettle();
+
+ expect(find.byKey(const ValueKey('participant-59')), findsOneWidget);
+ });
+}
+
+Widget _testApp(Widget child) {
+ return MaterialApp(
+ theme: ComponentTheme.lightTheme(),
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: SizedBox(width: 400, child: child),
+ ),
+ ),
+ );
+}
+
+Collection _collection(List<User> sharees) {
+ return Collection(
+ 1,
+ User(id: 1, email: '[email protected]'),
+ '',
+ null,
+ 'Album',
+ null,
+ null,
+ CollectionType.album,
+ CollectionAttributes(),
+ sharees,
+ [],
+ 1,
+ );
+}