Skip to content

armgit / ente

Public Imported from GitHub
0

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

Redesign album sharing page

AmanRajSinghMourya59e0e8aa9bd0
diff --git a/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart b/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart
index 3cf91fb115..76fc88c3b6 100644
--- a/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart
+++ b/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart
@@ -1,6 +1,5 @@
import 'dart:async';
-import 'package:collection/collection.dart';
import 'package:ente_components/ente_components.dart';
import 'package:ente_pure_utils/ente_pure_utils.dart';
import 'package:ente_strings/ente_strings.dart';
@@ -10,16 +9,15 @@ import 'package:photos/core/configuration.dart';
import 'package:photos/models/api/collection/user.dart';
import 'package:photos/models/collection/collection.dart';
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/add_participant_page.dart';
+import 'package:photos/ui/sharing/add_people_sheet.dart';
import 'package:photos/ui/sharing/album_participants_page.dart';
-import 'package:photos/ui/sharing/album_share_info_widget.dart';
-import 'package:photos/ui/sharing/manage_album_participant.dart';
import 'package:photos/ui/sharing/manage_links_widget.dart';
import 'package:photos/ui/sharing/public_link_enabled_actions_widget.dart';
import 'package:photos/ui/sharing/share_components.dart';
-import 'package:photos/ui/sharing/user_avator_widget.dart';
+import 'package:photos/ui/sharing/widgets/participant_role_row.dart';
+import 'package:photos/ui/sharing/widgets/participant_row.dart';
+import 'package:photos/ui/sharing/widgets/sharing_role.dart';
class ShareCollectionPage extends StatefulWidget {
final Collection collection;
@@ -32,11 +30,12 @@ class ShareCollectionPage extends StatefulWidget {
class _ShareCollectionPageState extends State<ShareCollectionPage> {
late Collection _collection;
- late List<User?> _sharees;
+ late List<User> _sharees;
final CollectionActions collectionActions = CollectionActions(
CollectionsService.instance,
);
final GlobalKey sendLinkButtonKey = GlobalKey();
+ final ScrollController _rosterScrollController = ScrollController();
bool _redirectedToParticipants = false;
@override
@@ -45,6 +44,12 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
_collection = widget.collection;
}
+ @override
+ void dispose() {
+ _rosterScrollController.dispose();
+ super.dispose();
+ }
+
Future<void> _refreshCollection() async {
try {
final latest = await CollectionsService.instance.fetchCollectionByID(
@@ -63,18 +68,8 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
}
}
- Future<void> _navigateToManageUser() async {
- if (_sharees.length == 1) {
- await routeToPage(
- context,
- ManageIndividualParticipant(
- collection: _collection,
- user: _sharees.first!,
- ),
- );
- } else {
- await routeToPage(context, AlbumParticipantsPage(_collection));
- }
+ Future<void> _navigateToAddUser() async {
+ await showAddPeopleSheet(context, [_collection]);
await _refreshCollection();
}
@@ -100,73 +95,34 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
_sharees = _collection.sharees;
final bool hasUrl = _collection.hasLink;
final bool isOwner = _collection.owner.id == userID;
- final bool canManageParticipants = isOwner;
- final children = <Widget>[
- ShareSectionTitle(
- context.strings.shareWithPeopleSectionTitle(
- numberOfPeople: _sharees.length,
- ),
- ),
- EmailItemWidget(_collection, onTap: _navigateToManageUser),
- ];
+ if (isOwner && _collection.owner.email.isEmpty) {
+ _collection.owner.email = Configuration.instance.getEmail() ?? "";
+ }
+ final sortedSharees = List<User>.from(_sharees)
+ ..sort((a, b) {
+ final rankComparison = sharingRoleRank(
+ _collection.getRole(a.id),
+ ).compareTo(sharingRoleRank(_collection.getRole(b.id)));
+ return rankComparison != 0
+ ? rankComparison
+ : a.email.toLowerCase().compareTo(b.email.toLowerCase());
+ });
+ final children = <Widget>[ShareSectionTitle(context.strings.sharedWith)];
- if (canManageParticipants) {
+ if (isOwner) {
children.addAll([
- if (_sharees.isNotEmpty) const SizedBox(height: Spacing.sm),
- ShareMenuItem(
- title: context.strings.addAdmin,
- icon: HugeIcons.strokeRoundedCrown,
- showChevron: true,
- onTap: () async {
- await routeToPage(
- context,
- AddParticipantPage(
- [_collection],
- const [ActionTypesToShow.addAdmin],
- ),
- );
- await _refreshCollection();
- },
- ),
+ if (sortedSharees.isEmpty)
+ ShareSectionDescription(context.strings.emptyAlbumShareMessage)
+ else
+ _participantRoster(userID, sortedSharees),
const SizedBox(height: Spacing.sm),
- ShareMenuItem(
- title: context.strings.addCollaborator,
- icon: HugeIcons.strokeRoundedUserGroup,
- showChevron: true,
- onTap: () async {
- unawaited(
- routeToPage(
- context,
- AddParticipantPage(
- [_collection],
- const [ActionTypesToShow.addCollaborator],
- ),
- ).then((value) {
- _refreshCollection().ignore();
- }),
- );
- },
- ),
- const SizedBox(height: Spacing.sm),
- ShareMenuItem(
- title: context.strings.addViewer,
- icon: HugeIcons.strokeRoundedView,
- showChevron: true,
- onTap: () async {
- await routeToPage(
- context,
- AddParticipantPage(
- [_collection],
- const [ActionTypesToShow.addViewer],
- ),
- );
- await _refreshCollection();
- },
+ ButtonComponent(
+ label: context.strings.addPerson,
+ variant: ButtonComponentVariant.secondary,
+ size: ButtonComponentSize.large,
+ shouldSurfaceExecutionStates: false,
+ onTap: _navigateToAddUser,
),
- if (_sharees.isEmpty && !hasUrl)
- ShareSectionDescription(
- context.strings.sharedAlbumSectionDescription,
- ),
]);
}
@@ -244,61 +200,35 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
}
}
- return ShareScaffold(title: _collection.displayName, children: children);
+ return ShareScaffold(
+ title: _collection.displayName,
+ subtitle: isOwner && (_collection.hasSharees || _collection.hasLink)
+ ? context.strings.sharedByYou
+ : null,
+ padding: const EdgeInsets.fromLTRB(
+ Spacing.lg,
+ Spacing.sm,
+ Spacing.lg,
+ Spacing.xl,
+ ),
+ children: children,
+ );
}
-}
-
-class EmailItemWidget extends StatelessWidget {
- final Collection collection;
- final Function? onTap;
-
- const EmailItemWidget(this.collection, {this.onTap, super.key});
-
- @override
- Widget build(BuildContext context) {
- if (collection.sharees.isEmpty) {
- return const SizedBox.shrink();
- } else if (collection.sharees.length == 1) {
- final User? user = collection.sharees.firstOrNull;
- final resolvedName = user == null ? '' : resolveDisplayName(user);
- return ShareMenuItem(
- title: resolvedName,
- leading: UserAvatarWidget(collection.sharees.first),
- showChevron: true,
- onTap: () async {
- if (onTap != null) {
- onTap!();
- }
- },
- );
- } else {
- final sharees = collection.sharees;
- const avatarSize = 24.0;
- final total = sharees.length;
- final limit = total > 2 ? 1 : 2;
- return ShareMenuItem(
- title: context.strings.manageParticipants,
- subtitle: context.strings.albumParticipantsCount(
- count: sharees.length + 1,
- ),
- leading: SizedBox(
- height: avatarSize,
- child: AlbumSharesIcons(
- sharees: sharees,
- padding: EdgeInsets.zero,
- limitCountTo: limit,
- type: AvatarType.medium,
- removeBorder: false,
- ),
+ Widget _participantRoster(int userID, List<User> sortedSharees) {
+ final rows = <Widget>[
+ for (final sharee in sortedSharees)
+ ParticipantRoleRow(
+ key: ValueKey(sharee.id),
+ collection: _collection,
+ user: sharee,
+ currentUserID: userID,
+ onCollectionChanged: () => setState(() {}),
),
- showChevron: true,
- onTap: () async {
- if (onTap != null) {
- onTap!();
- }
- },
- );
- }
+ ];
+ return ScrollableParticipantRoster(
+ rows: rows,
+ scrollController: _rosterScrollController,
+ );
}
}