π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Make participant roles and actions discoverable
ashil-pilot195b393673d7
diff --git a/mobile/apps/photos/changes/participant-options.md b/mobile/apps/photos/changes/participant-options.mdnew file mode 100644index 0000000000..8aa0c94f9a--- /dev/null+++ b/mobile/apps/photos/changes/participant-options.md@@ -0,0 +1 @@+- Made album participants' roles visible and their sharing options easier to open.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.dartindex 1aee3774d8..e390985424 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@@ -1,7 +1,6 @@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/db/files_db.dart";import "package:photos/models/api/collection/user.dart";import "package:photos/models/collection/collection.dart";@@ -9,19 +8,8 @@ import "package:photos/services/collections_service.dart";import "package:photos/services/contacts/contact_identity_resolver.dart";import "package:photos/ui/actions/collection/collection_sharing_actions.dart";import "package:photos/ui/sharing/widgets/confirm_sheet.dart";+import "package:photos/ui/sharing/widgets/participant_role_sheet.dart";import "package:photos/ui/sharing/widgets/participant_row.dart";-import "package:photos/ui/sharing/widgets/sharing_role.dart";--enum _ParticipantRoleAction {- viewer(CollectionParticipantRole.viewer),- collaborator(CollectionParticipantRole.collaborator),- admin(CollectionParticipantRole.admin),- remove(null);-- const _ParticipantRoleAction(this.role);-- final CollectionParticipantRole? role;-}class ParticipantRoleRow extends StatefulWidget {const ParticipantRoleRow({@@ -43,7 +31,7 @@ class ParticipantRoleRow extends StatefulWidget {class _ParticipantRoleRowState extends State<ParticipantRoleRow> {bool _isChangingRole = false;- final _menuKey = GlobalKey();+ bool _isShowingOptions = false;@overrideWidget build(BuildContext context) {@@ -52,7 +40,8 @@ class _ParticipantRoleRowState extends State<ParticipantRoleRow> {user: widget.user,role: role,currentUserID: widget.currentUserID,- onLongPress: _isChangingRole ? null : _showMenu,+ onTap: _isChangingRole ? null : _showOptions,+ onLongPress: _isChangingRole ? null : _showOptions,trailing: _isChangingRole? SizedBox.square(dimension: IconSizes.small,@@ -61,67 +50,38 @@ class _ParticipantRoleRowState extends State<ParticipantRoleRow> {strokeWidth: 2,),)- : EntePopupMenuButton<_ParticipantRoleAction>(- key: _menuKey,- optionsBuilder: () => _options(context),- onSelected: _onSelected,- child: HugeIcon(- icon: albumSharingRoleIcon(role),- color: context.componentColors.textBase,- size: IconSizes.small,- strokeWidth: 1.6,- ),+ : IconButtonComponent(+ icon: const Icon(Icons.more_horiz),+ tooltip: context.strings.moreOptions,+ variant: IconButtonComponentVariant.unfilled,+ size: 48,+ shouldSurfaceExecutionStates: false,+ onTap: _showOptions,),);}- Future<void> _showMenu() async {- final action = await showEntePopupMenu<_ParticipantRoleAction>(- context: _menuKey.currentContext!,- options: _options(context),- );- if (!mounted || action == null) {- return;+ Future<void> _showOptions() async {+ if (_isShowingOptions || _isChangingRole) return;+ _isShowingOptions = true;+ try {+ final action = await showParticipantRoleSheet(+ context,+ email: widget.user.email,+ currentRole: widget.collection.getRole(widget.user.id),+ );+ if (!mounted || action == null) return;+ await _onSelected(action);+ } finally {+ _isShowingOptions = false;}- await _onSelected(action);}- Future<void> _onSelected(_ParticipantRoleAction action) =>- action == _ParticipantRoleAction.remove+ Future<void> _onSelected(ParticipantRoleAction action) =>+ action == ParticipantRoleAction.remove? _removeParticipant(): _changeRole(action.role!);- List<EntePopupMenuOption<_ParticipantRoleAction>> _options(- BuildContext context,- ) {- final colors = context.componentColors;- final activeRole = widget.collection.getRole(widget.user.id);- return [- 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,- ),- EntePopupMenuOption(- value: _ParticipantRoleAction.remove,- label: context.strings.remove,- labelColor: colors.warning,- leadingWidget: HugeIcon(- icon: HugeIcons.strokeRoundedDelete02,- color: colors.warning,- size: IconSizes.small,- ),- showDivider: false,- ),- ];- }-Future<void> _changeRole(CollectionParticipantRole role) async {if (role == widget.collection.getRole(widget.user.id)) {return;diff --git a/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_sheet.dart b/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_sheet.dartnew file mode 100644index 0000000000..5a85cd04b0--- /dev/null+++ b/mobile/apps/photos/lib/ui/sharing/widgets/participant_role_sheet.dart@@ -0,0 +1,97 @@+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/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/widgets/sharing_role.dart";++enum ParticipantRoleAction {+ viewer(CollectionParticipantRole.viewer),+ collaborator(CollectionParticipantRole.collaborator),+ admin(CollectionParticipantRole.admin),+ remove(null);++ const ParticipantRoleAction(this.role);++ final CollectionParticipantRole? role;+}++Future<ParticipantRoleAction?> showParticipantRoleSheet(+ BuildContext context, {+ required String email,+ required CollectionParticipantRole currentRole,+}) {+ return showBottomSheetComponent<ParticipantRoleAction>(+ context: context,+ builder: (sheetContext) {+ final colors = sheetContext.componentColors;+ return ConstrainedBox(+ constraints: BoxConstraints(+ maxHeight: MediaQuery.sizeOf(sheetContext).height * 0.95,+ ),+ child: BottomSheetComponent(+ title: sheetContext.strings.chooseAccess,+ content: Flexible(+ fit: FlexFit.loose,+ child: SingleChildScrollView(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ email,+ style: TextStyles.body.copyWith(color: colors.textLight),+ ),+ const SizedBox(height: Spacing.xl),+ ShareMenuGroup(+ items: [+ for (final action in ParticipantRoleAction.values)+ if (action.role case final role?)+ Semantics(+ selected: currentRole == role,+ child: ShareMenuItem(+ title: shareableRoleLabel(sheetContext, role),+ icon: albumSharingRoleIcon(role),+ trailing: currentRole == role+ ? const CollectionSelectedBadge()+ : SizedBox.square(+ dimension: IconSizes.small,+ child: DecoratedBox(+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ border: Border.all(+ color: colors.strokeDark,+ ),+ ),+ ),+ ),+ onTap: () =>+ Navigator.of(sheetContext).pop(action),+ ),+ ),+ ],+ ),+ const SizedBox(height: Spacing.lg),+ ShareMenuGroup(+ items: [+ ShareMenuItem(+ title: sheetContext.strings.removeFromAlbum,+ icon: HugeIcons.strokeRoundedDelete02,+ isDestructive: true,+ onTap: () => Navigator.of(+ sheetContext,+ ).pop(ParticipantRoleAction.remove),+ ),+ ],+ ),+ ],+ ),+ ),+ ),+ ),+ );+ },+ );+}diff --git a/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart b/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dartindex 39a45b4feb..6c04354c70 100644--- a/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart+++ b/mobile/apps/photos/lib/ui/sharing/widgets/participant_row.dart@@ -3,7 +3,6 @@ import "dart:math" as math;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/api/collection/user.dart";import "package:photos/models/collection/collection.dart";import "package:photos/services/contacts/contact_identity_resolver.dart";@@ -83,11 +82,12 @@ class _ScrollableParticipantRosterState}double _rowExtent(BuildContext context) {- const textStyle = TextStyles.body;- final textExtent =- MediaQuery.textScalerOf(context).scale(textStyle.fontSize!) *- textStyle.height!;- return math.max(60.0, textExtent + 20.0);+ final textScaler = MediaQuery.textScalerOf(context);+ final titleExtent =+ textScaler.scale(TextStyles.body.fontSize!) * TextStyles.body.height!;+ final roleExtent =+ textScaler.scale(TextStyles.mini.fontSize!) * TextStyles.mini.height!;+ return math.max(68.0, titleExtent + Spacing.xs + roleExtent + 20.0);}}@@ -98,6 +98,7 @@ class ParticipantRow extends StatelessWidget {required this.role,required this.currentUserID,this.trailing,+ this.onTap,this.onLongPress,});@@ -105,25 +106,21 @@ class ParticipantRow extends StatelessWidget {final CollectionParticipantRole role;final int currentUserID;final Widget? trailing;+ final VoidCallback? onTap;final VoidCallback? onLongPress;@overrideWidget build(BuildContext context) {- final colors = context.componentColors;return ShareMenuItem(title: user.id == currentUserID? context.strings.you: resolveDisplayName(user),titleMaxLines: 1,+ subtitle: shareableRoleLabel(context, role),+ subtitleMaxLines: 1,leading: UserAvatarWidget(user, type: AvatarType.medium),- trailing:- trailing ??- HugeIcon(- icon: albumSharingRoleIcon(role),- color: colors.textLightest,- size: IconSizes.small,- strokeWidth: 1.6,- ),+ trailing: trailing,+ onTap: onTap,onLongPress: onLongPress,);}diff --git a/mobile/apps/photos/test/ui/sharing/participant_role_sheet_test.dart b/mobile/apps/photos/test/ui/sharing/participant_role_sheet_test.dartnew file mode 100644index 0000000000..7fd8e477b4--- /dev/null+++ b/mobile/apps/photos/test/ui/sharing/participant_role_sheet_test.dart@@ -0,0 +1,81 @@+import 'package:ente_components/ente_components.dart';+import 'package:ente_strings/ente_strings.dart';+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:photos/ente_theme_data.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/widgets/participant_role_sheet.dart';++void main() {+ testWidgets(+ 'shows current role without descriptions and returns the choice',+ (tester) async {+ await tester.binding.setSurfaceSize(const Size(320, 640));+ addTearDown(() => tester.binding.setSurfaceSize(null));+ ParticipantRoleAction? result;+ await tester.pumpWidget(+ MaterialApp(+ theme: lightThemeData,+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ builder: (context, child) => MediaQuery(+ data: MediaQuery.of(+ context,+ ).copyWith(textScaler: const TextScaler.linear(2)),+ child: child!,+ ),+ home: Scaffold(+ body: Builder(+ builder: (context) => TextButton(+ onPressed: () async {+ result = await showParticipantRoleSheet(+ context,+ email: '[email protected]',+ currentRole: CollectionParticipantRole.collaborator,+ );+ },+ child: const Text('Open'),+ ),+ ),+ ),+ ),+ );++ for (final entry in {+ 'Viewer': ParticipantRoleAction.viewer,+ 'Collaborator': ParticipantRoleAction.collaborator,+ 'Admin': ParticipantRoleAction.admin,+ 'Remove from album': ParticipantRoleAction.remove,+ }.entries) {+ await tester.tap(find.text('Open'));+ await tester.pumpAndSettle();+ expect(+ find.descendant(+ of: find.widgetWithText(ShareMenuItem, 'Collaborator'),+ matching: find.byType(CollectionSelectedBadge),+ ),+ findsOneWidget,+ );+ for (final item in tester.widgetList<ShareMenuItem>(+ find.byType(ShareMenuItem),+ )) {+ expect(item.subtitle, isNull);+ }+ await tester.ensureVisible(find.text(entry.key));+ await tester.tap(find.text(entry.key));+ await tester.pumpAndSettle();+ expect(result, entry.value);+ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(tester.takeException(), isNull);+ }++ await tester.tap(find.text('Open'));+ await tester.pumpAndSettle();+ await tester.tap(find.byTooltip('Close'));+ await tester.pumpAndSettle();+ expect(result, isNull);+ },+ );+}diff --git a/mobile/apps/photos/test/ui/sharing/share_collection_page_test.dart b/mobile/apps/photos/test/ui/sharing/share_collection_page_test.dartindex 3cf4590ecb..6e94347d8d 100644--- a/mobile/apps/photos/test/ui/sharing/share_collection_page_test.dart+++ b/mobile/apps/photos/test/ui/sharing/share_collection_page_test.dart@@ -1,4 +1,5 @@import 'package:dio/dio.dart';+import 'package:ente_components/ente_components.dart';import 'package:ente_strings/ente_strings.dart';import 'package:flutter/material.dart';import 'package:flutter/services.dart';@@ -9,12 +10,14 @@ import 'package:photos/core/event_bus.dart';import 'package:photos/db/ml/base.dart';import 'package:photos/ente_theme_data.dart';import 'package:photos/events/contact_relationships_invalidated_event.dart';+import 'package:photos/models/api/collection/user.dart';import 'package:photos/models/collection/collection.dart';import 'package:photos/service_locator.dart';import 'package:photos/services/collections_service.dart';import 'package:photos/services/entity_service.dart';import 'package:photos/services/machine_learning/face_ml/person/person_service.dart';import 'package:photos/ui/sharing/share_collection_page.dart';+import 'package:photos/ui/sharing/widgets/participant_role_row.dart';import 'package:photos/ui/sharing/widgets/participant_row.dart';import 'package:shared_preferences/shared_preferences.dart';@@ -101,10 +104,7 @@ void main() {),);await tester.pumpAndSettle();- expect(- tester.widget<ParticipantRow>(find.byType(ParticipantRow)).role,- CollectionParticipantRole.admin,- );+ expect(find.text('Admin'), findsOneWidget);_updateCachedAlbum(librarySharingTestAlbum(1));await tester.pumpAndSettle();@@ -138,16 +138,90 @@ void main() {await tester.pumpAndSettle();expect(tester.takeException(), isNull);});++ testWidgets('opens participant access from row, options and long press', (+ tester,+ ) async {+ final album = librarySharingTestAlbum(+ 1,+ recipientRole: CollectionParticipantRole.viewer,+ );+ await _showPage(tester, album);+ expect(find.text('Viewer'), findsOneWidget);++ final row = find.byType(ParticipantRoleRow);+ final openActions = <Future<void> Function()>[+ () => tester.tap(find.text('[email protected]')),+ () => tester.tap(+ find.descendant(of: row, matching: find.byTooltip('More options')),+ ),+ () => tester.longPress(find.text('[email protected]')),+ ];+ for (final open in openActions) {+ await open();+ await tester.pumpAndSettle();+ expect(find.text('Choose access'), findsOneWidget);+ expect(find.byType(BottomSheetComponent), findsOneWidget);+ expect(find.text('Remove from album'), findsOneWidget);+ await tester.tap(find.text('Viewer').last);+ await tester.pumpAndSettle();+ expect(find.byType(BottomSheetComponent), findsNothing);+ expect(find.text('Viewer'), findsOneWidget);+ }+ });++ testWidgets(+ 'keeps role subtitles inside a scrollable roster with large text',+ (tester) async {+ final album = librarySharingTestAlbum(1);+ album.sharees.addAll([+ User(id: 2, email: '[email protected]', role: 'ADMIN'),+ User(id: 3, email: '[email protected]', role: 'COLLABORATOR'),+ User(id: 4, email: '[email protected]', role: 'VIEWER'),+ User(id: 5, email: '[email protected]', role: 'VIEWER'),+ ]);+ await _showPage(tester, album, size: const Size(320, 740), textScale: 2);+ for (final label in ['Admin', 'Collaborator', 'Viewer']) {+ final subtitle = find.text(label).first;+ final row = find.ancestor(+ of: subtitle,+ matching: find.byType(ParticipantRow),+ );+ expect(+ tester.getRect(subtitle).bottom,+ lessThanOrEqualTo(tester.getRect(row).bottom),+ );+ }+ await tester.drag(+ find.byKey(const ValueKey('participant-roster-scroll')),+ const Offset(0, -180),+ );+ await tester.pumpAndSettle();+ expect(find.text('[email protected]').hitTestable(), findsOneWidget);+ expect(tester.takeException(), isNull);+ },+ );}-Future<void> _showPage(WidgetTester tester, Collection album) async {- await tester.binding.setSurfaceSize(const Size(402, 874));+Future<void> _showPage(+ WidgetTester tester,+ Collection album, {+ Size size = const Size(402, 874),+ double textScale = 1,+}) async {+ await tester.binding.setSurfaceSize(size);addTearDown(() => tester.binding.setSurfaceSize(null));await tester.pumpWidget(MaterialApp(theme: darkThemeData,localizationsDelegates: StringsLocalizations.localizationsDelegates,supportedLocales: StringsLocalizations.supportedLocales,+ builder: (context, child) => MediaQuery(+ data: MediaQuery.of(+ context,+ ).copyWith(textScaler: TextScaler.linear(textScale)),+ child: child!,+ ),home: ShareCollectionPage(album),),);