Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add functionality for managing album participants and sharing settings

AmanRajSinghMouryabbbdd96c9ef3
diff --git a/mobile/apps/locker/lib/services/collections/collections_api_client.dart b/mobile/apps/locker/lib/services/collections/collections_api_client.dart
index c4ae5fe04c..9867e3880b 100644
--- a/mobile/apps/locker/lib/services/collections/collections_api_client.dart
+++ b/mobile/apps/locker/lib/services/collections/collections_api_client.dart
@@ -509,6 +509,30 @@ class CollectionApiClient {
rethrow;
}
}
+
+ Future<List<User>> unshare(int collectionID, String email) async {
+ try {
+ final response = await _enteDio.post(
+ "/collections/unshare",
+ data: {
+ "collectionID": collectionID,
+ "email": email,
+ },
+ );
+ final sharees = <User>[];
+ for (final user in response.data["sharees"]) {
+ sharees.add(User.fromMap(user));
+ }
+ final collection = CollectionService.instance.getFromCache(collectionID);
+ final updatedCollection = collection!.copyWith(sharees: sharees);
+ CollectionService.instance.updateCollectionCache(updatedCollection);
+ unawaited(_db.updateCollections([updatedCollection]));
+ return sharees;
+ } catch (e) {
+ _logger.severe(e);
+ rethrow;
+ }
+ }
}
class CreateRequest {
diff --git a/mobile/apps/locker/lib/ui/sharing/add_participant_page.dart b/mobile/apps/locker/lib/ui/sharing/add_participant_page.dart
new file mode 100644
index 0000000000..ea2a4e4a11
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/sharing/add_participant_page.dart
@@ -0,0 +1,466 @@
+import 'package:email_validator/email_validator.dart';
+import "package:ente_ui/components/buttons/button_widget.dart";
+import "package:ente_ui/components/buttons/models/button_type.dart";
+import "package:ente_ui/components/captioned_text_widget.dart";
+import "package:ente_ui/components/divider_widget.dart";
+import "package:ente_ui/components/menu_item_widget.dart";
+import "package:ente_ui/components/menu_section_description_widget.dart";
+import "package:ente_ui/components/menu_section_title.dart";
+import "package:ente_ui/components/separators.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_ui/utils/toast_util.dart";
+import 'package:flutter/material.dart';
+import "package:locker/extensions/user_extension.dart";
+import "package:locker/l10n/l10n.dart";
+import "package:locker/services/collections/collections_service.dart";
+import "package:locker/services/collections/models/collection.dart";
+import "package:locker/services/collections/models/user.dart";
+import "package:locker/ui/sharing/user_avator_widget.dart";
+import "package:locker/ui/sharing/verify_identity_dialog.dart";
+import "package:locker/utils/collection_actions.dart";
+
+enum ActionTypesToShow {
+ addViewer,
+ addCollaborator,
+}
+
+class AddParticipantPage extends StatefulWidget {
+ /// Cannot be empty
+ final List<ActionTypesToShow> actionTypesToShow;
+ final List<Collection> collections;
+
+ AddParticipantPage(
+ this.collections,
+ this.actionTypesToShow, {
+ super.key,
+ }) : assert(
+ actionTypesToShow.isNotEmpty,
+ 'actionTypesToShow cannot be empty',
+ );
+
+ @override
+ State<StatefulWidget> createState() => _AddParticipantPage();
+}
+
+class _AddParticipantPage extends State<AddParticipantPage> {
+ final _selectedEmails = <String>{};
+ String _newEmail = '';
+ bool _emailIsValid = false;
+ bool isKeypadOpen = false;
+ late List<User> _suggestedUsers;
+
+ // Focus nodes are necessary
+ final textFieldFocusNode = FocusNode();
+ final _textController = TextEditingController();
+
+ late CollectionActions collectionActions;
+
+ @override
+ void initState() {
+ super.initState();
+ _suggestedUsers = _getSuggestedUser();
+ collectionActions = CollectionActions();
+ }
+
+ @override
+ void dispose() {
+ _textController.dispose();
+ textFieldFocusNode.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final filterSuggestedUsers = _suggestedUsers
+ .where(
+ (element) => (element.displayName ?? element.email).toLowerCase().contains(
+ _textController.text.trim().toLowerCase(),
+ ),
+ )
+ .toList();
+ isKeypadOpen = MediaQuery.viewInsetsOf(context).bottom > 100;
+ final enteTextTheme = getEnteTextTheme(context);
+ final enteColorScheme = getEnteColorScheme(context);
+ return Scaffold(
+ resizeToAvoidBottomInset: isKeypadOpen,
+ appBar: AppBar(
+ title: Text(
+ _getTitle(),
+ ),
+ ),
+ body: Column(
+ mainAxisAlignment: MainAxisAlignment.start,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 12),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: Text(
+ context.l10n.addANewEmail,
+ style: enteTextTheme.small
+ .copyWith(color: enteColorScheme.textMuted),
+ ),
+ ),
+ const SizedBox(height: 4),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: _enterEmailField(),
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: Column(
+ children: [
+ filterSuggestedUsers.isNotEmpty
+ ? MenuSectionTitle(
+ title: context.l10n.orPickAnExistingOne,
+ )
+ : const SizedBox.shrink(),
+ Expanded(
+ child: ListView.builder(
+ physics: const BouncingScrollPhysics(),
+ itemBuilder: (context, index) {
+ if (index >= filterSuggestedUsers.length) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(
+ vertical: 8.0,
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ filterSuggestedUsers.isNotEmpty
+ ? MenuSectionDescriptionWidget(
+ content: context.l10n
+ .longPressAnEmailToVerifyEndToEndEncryption,
+ )
+ : const SizedBox.shrink(),
+ widget.actionTypesToShow.contains(
+ ActionTypesToShow.addCollaborator,
+ )
+ ? MenuSectionDescriptionWidget(
+ content: context.l10n
+ .collaboratorsCanAddFilesToTheSharedCollection,
+ )
+ : const SizedBox.shrink(),
+ ],
+ ),
+ );
+ }
+ final currentUser = filterSuggestedUsers[index];
+ return Column(
+ children: [
+ MenuItemWidget(
+ key: ValueKey(
+ currentUser.displayName ?? currentUser.email,
+ ),
+ captionedTextWidget: CaptionedTextWidget(
+ title: currentUser.displayName ??
+ currentUser.email,
+ ),
+ leadingIconSize: 24.0,
+ leadingIconWidget: UserAvatarWidget(
+ currentUser,
+ type: AvatarType.mini,
+ ),
+ menuItemColor:
+ getEnteColorScheme(context).fillFaint,
+ pressedColor:
+ getEnteColorScheme(context).fillFaint,
+ trailingIcon:
+ (_selectedEmails.contains(currentUser.email))
+ ? Icons.check
+ : null,
+ onTap: () async {
+ textFieldFocusNode.unfocus();
+ if (_selectedEmails
+ .contains(currentUser.email)) {
+ _selectedEmails.remove(currentUser.email);
+ } else {
+ _selectedEmails.add(currentUser.email);
+ }
+
+ setState(() => {});
+ // showShortToast(context, "yet to implement");
+ },
+ onLongPress: () {
+ showDialog(
+ useRootNavigator: false,
+ context: context,
+ builder: (BuildContext context) {
+ return VerifyIdentifyDialog(
+ self: false,
+ email: currentUser.email,
+ );
+ },
+ );
+ },
+ isTopBorderRadiusRemoved: index > 0,
+ isBottomBorderRadiusRemoved:
+ index < (filterSuggestedUsers.length - 1),
+ ),
+ (index == (filterSuggestedUsers.length - 1))
+ ? const SizedBox.shrink()
+ : DividerWidget(
+ dividerType: DividerType.menu,
+ bgColor:
+ getEnteColorScheme(context).fillFaint,
+ ),
+ ],
+ );
+ },
+ itemCount: filterSuggestedUsers.length + 1,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ SafeArea(
+ child: Padding(
+ padding: const EdgeInsets.only(
+ top: 8,
+ bottom: 8,
+ left: 16,
+ right: 16,
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ children: [
+ const SizedBox(height: 8),
+ ..._actionButtons(),
+ const SizedBox(height: 12),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ List<Widget> _actionButtons() {
+ final widgets = <Widget>[];
+ if (widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)) {
+ widgets.add(
+ ButtonWidget(
+ buttonType: ButtonType.primary,
+ buttonSize: ButtonSize.large,
+ labelText: context.l10n.addViewers(_selectedEmails.length),
+ isDisabled: _selectedEmails.isEmpty,
+ onTap: () async {
+ final results = <bool>[];
+ final collections = widget.collections;
+
+ for (String email in _selectedEmails) {
+ bool result = false;
+ for (Collection collection in collections) {
+ result = await collectionActions.addEmailToCollection(
+ context,
+ collection,
+ email,
+ CollectionParticipantRole.viewer,
+ );
+ }
+ results.add(result);
+ }
+
+ final noOfSuccessfullAdds = results.where((e) => e).length;
+ showToast(
+ context,
+ context.l10n.viewersSuccessfullyAdded(noOfSuccessfullAdds),
+ );
+
+ if (!results.any((e) => e == false) && mounted) {
+ Navigator.of(context).pop(true);
+ }
+ },
+ ),
+ );
+ }
+ if (widget.actionTypesToShow.contains(
+ ActionTypesToShow.addCollaborator,
+ )) {
+ widgets.add(
+ ButtonWidget(
+ buttonType:
+ widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)
+ ? ButtonType.neutral
+ : ButtonType.primary,
+ buttonSize: ButtonSize.large,
+ labelText: context.l10n.addCollaborators(_selectedEmails.length),
+ isDisabled: _selectedEmails.isEmpty,
+ onTap: () async {
+ // TODO: This is not currently designed for best UX for action on
+ // multiple collections and emails, especially if some operations
+ // fail. Can be improved by using a different 'addEmailToCollection'
+ // that accepts list of emails and list of collections.
+ final results = <bool>[];
+ final collections = widget.collections;
+
+ for (String email in _selectedEmails) {
+ bool result = false;
+ for (Collection collection in collections) {
+ result = await collectionActions.addEmailToCollection(
+ context,
+ collection,
+ email,
+ CollectionParticipantRole.collaborator,
+ );
+ }
+ results.add(result);
+ }
+
+ final noOfSuccessfullAdds = results.where((e) => e).length;
+ showToast(
+ context,
+ context.l10n.collaboratorsSuccessfullyAdded(noOfSuccessfullAdds),
+ );
+
+ if (!results.any((e) => e == false) && mounted) {
+ Navigator.of(context).pop(true);
+ }
+ },
+ ),
+ );
+ }
+ final widgetsWithSpaceBetween = addSeparators(
+ widgets,
+ const SizedBox(
+ height: 8,
+ ),
+ );
+ return widgetsWithSpaceBetween;
+ }
+
+ void clearFocus() {
+ _textController.clear();
+ _newEmail = _textController.text;
+ _emailIsValid = false;
+ textFieldFocusNode.unfocus();
+ setState(() => {});
+ }
+
+ Widget _enterEmailField() {
+ return Row(
+ children: [
+ Expanded(
+ child: TextFormField(
+ controller: _textController,
+ focusNode: textFieldFocusNode,
+ style: getEnteTextTheme(context).body,
+ autofillHints: const [AutofillHints.email],
+ decoration: InputDecoration(
+ focusedBorder: OutlineInputBorder(
+ borderRadius: const BorderRadius.all(Radius.circular(4.0)),
+ borderSide:
+ BorderSide(color: getEnteColorScheme(context).strokeMuted),
+ ),
+ fillColor: getEnteColorScheme(context).fillFaint,
+ filled: true,
+ hintText: context.l10n.enterEmail,
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 14,
+ ),
+ border: UnderlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(4),
+ ),
+ prefixIcon: Icon(
+ Icons.email_outlined,
+ color: getEnteColorScheme(context).strokeMuted,
+ ),
+ suffixIcon: _newEmail == ''
+ ? null
+ : IconButton(
+ onPressed: clearFocus,
+ icon: Icon(
+ Icons.cancel,
+ color: getEnteColorScheme(context).strokeMuted,
+ ),
+ ),
+ ),
+ onChanged: (value) {
+ _newEmail = value.trim();
+ _emailIsValid = EmailValidator.validate(_newEmail);
+ setState(() {});
+ },
+ autocorrect: false,
+ keyboardType: TextInputType.emailAddress,
+ //initialValue: _email,
+ textInputAction: TextInputAction.next,
+ ),
+ ),
+ const SizedBox(width: 8),
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ buttonSize: ButtonSize.small,
+ labelText: context.l10n.add,
+ isDisabled: !_emailIsValid,
+ onTap: () async {
+ if (_emailIsValid) {
+ final result = await collectionActions.doesEmailHaveAccount(
+ context,
+ _newEmail,
+ );
+ if (result && mounted) {
+ setState(() {
+ for (var suggestedUser in _suggestedUsers) {
+ if (suggestedUser.email == _newEmail) {
+ _selectedEmails.add(suggestedUser.email);
+ clearFocus();
+
+ return;
+ }
+ }
+ _suggestedUsers.insert(0, User(email: _newEmail));
+ _selectedEmails.add(_newEmail);
+ clearFocus();
+ });
+ }
+ }
+ },
+ ),
+ ],
+ );
+ }
+
+ List<User> _getSuggestedUser() {
+ final Set<String> existingEmails = {};
+ final collections = widget.collections;
+ if (collections.isEmpty) {
+ return [];
+ }
+
+ for (final Collection collection in collections) {
+ for (final User u in collection.sharees) {
+ if (u.id != null && u.email.isNotEmpty) {
+ existingEmails.add(u.email);
+ }
+ }
+ }
+
+ final List<User> suggestedUsers = CollectionService.instance.getRelevantContacts();
+
+ if (_textController.text.trim().isNotEmpty) {
+ suggestedUsers.removeWhere(
+ (element) => !(element.displayName ?? element.email)
+ .toLowerCase()
+ .contains(_textController.text.trim().toLowerCase()),
+ );
+ }
+ suggestedUsers.sort((a, b) => a.email.compareTo(b.email));
+
+ return suggestedUsers;
+ }
+
+ String _getTitle() {
+ if (widget.actionTypesToShow.length > 1) {
+ return context.l10n.addParticipants;
+ } else if (widget.actionTypesToShow.first == ActionTypesToShow.addViewer) {
+ return context.l10n.addViewer;
+ } else {
+ return context.l10n.addCollaborator;
+ }
+ }
+}
diff --git a/mobile/apps/locker/lib/ui/sharing/album_participants_page.dart b/mobile/apps/locker/lib/ui/sharing/album_participants_page.dart
new file mode 100644
index 0000000000..db9c341dc9
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/sharing/album_participants_page.dart
@@ -0,0 +1,308 @@
+import "package:ente_ui/components/captioned_text_widget.dart";
+import "package:ente_ui/components/divider_widget.dart";
+import "package:ente_ui/components/menu_item_widget.dart";
+import "package:ente_ui/components/menu_section_title.dart";
+import "package:ente_ui/components/title_bar_title_widget.dart";
+import "package:ente_ui/components/title_bar_widget.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_utils/navigation_util.dart";
+import 'package:flutter/material.dart';
+import "package:locker/extensions/list.dart";
+import "package:locker/extensions/user_extension.dart";
+import "package:locker/l10n/l10n.dart";
+import "package:locker/services/collections/models/collection.dart";
+import "package:locker/services/collections/models/user.dart";
+import "package:locker/services/configuration.dart";
+import "package:locker/ui/sharing/add_participant_page.dart";
+import "package:locker/ui/sharing/manage_album_participant.dart";
+import "package:locker/ui/sharing/user_avator_widget.dart";
+
+class AlbumParticipantsPage extends StatefulWidget {
+ final Collection collection;
+
+ const AlbumParticipantsPage(
+ this.collection, {
+ super.key,
+ });
+
+ @override
+ State<AlbumParticipantsPage> createState() => _AlbumParticipantsPageState();
+}
+
+class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {
+ late int currentUserID;
+
+ @override
+ void initState() {
+ currentUserID = Configuration.instance.getUserID()!;
+ super.initState();
+ }
+
+ Future<void> _navigateToManageUser(User user) async {
+ if (user.id == currentUserID) {
+ return;
+ }
+ await routeToPage(
+ context,
+ ManageIndividualParticipant(collection: widget.collection, user: user),
+ );
+ if (mounted) {
+ setState(() => {});
+ }
+ }
+
+ Future<void> _navigateToAddUser(bool addingViewer) async {
+ await routeToPage(
+ context,
+ AddParticipantPage(
+ [widget.collection],
+ addingViewer
+ ? [ActionTypesToShow.addViewer]
+ : [ActionTypesToShow.addCollaborator],
+ ),
+ );
+ if (mounted) {
+ setState(() => {});
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final isOwner =
+ widget.collection.owner.id == Configuration.instance.getUserID();
+ final colorScheme = getEnteColorScheme(context);
+ final currentUserID = Configuration.instance.getUserID()!;
+ final int participants = 1 + widget.collection.getSharees().length;
+ final User owner = widget.collection.owner;
+ if (owner.id == currentUserID && owner.email == "") {
+ owner.email = Configuration.instance.getEmail()!;
+ }
+ final splitResult =
+ widget.collection.getSharees().splitMatch((x) => x.isViewer);
+ final List<User> viewers = splitResult.matched;
+ viewers.sort((a, b) => a.email.compareTo(b.email));
+ final List<User> collaborators = splitResult.unmatched;
+ collaborators.sort((a, b) => a.email.compareTo(b.email));
+
+ return Scaffold(
+ body: CustomScrollView(
+ primary: false,
+ slivers: <Widget>[
+ TitleBarWidget(
+ flexibleSpaceTitle: TitleBarTitleWidget(
+ title: widget.collection.name,
+ ),
+ flexibleSpaceCaption:
+ context.l10n.albumParticipantsCount(participants),
+ ),
+ SliverList(
+ delegate: SliverChildBuilderDelegate(
+ (context, index) {
+ return Padding(
+ padding: const EdgeInsets.only(top: 20, left: 16, right: 16),
+ child: Column(
+ children: [
+ Column(
+ children: [
+ MenuSectionTitle(
+ title: context.l10n.albumOwner,
+ iconData: Icons.admin_panel_settings_outlined,
+ ),
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: isOwner
+ ? context.l10n.you
+ : _nameIfAvailableElseEmail(
+ widget.collection.owner,
+ ),
+ makeTextBold: isOwner,
+ ),
+ leadingIconWidget: UserAvatarWidget(
+ owner,
+ currentUserID: currentUserID,
+ ),
+ leadingIconSize: 24,
+ menuItemColor: colorScheme.fillFaint,
+ singleBorderRadius: 8,
+ isGestureDetectorDisabled: true,
+ ),
+ ],
+ ),
+ ],
+ ),
+ );
+ },
+ childCount: 1,
+ ),
+ ),
+ SliverPadding(
+ padding: const EdgeInsets.only(top: 20, left: 16, right: 16),
+ sliver: SliverList(
+ delegate: SliverChildBuilderDelegate(
+ (context, index) {
+ if (index == 0 && (isOwner || collaborators.isNotEmpty)) {
+ return MenuSectionTitle(
+ title: context.l10n.collaborator,
+ iconData: Icons.edit_outlined,
+ );
+ } else if (index > 0 && index <= collaborators.length) {
+ final listIndex = index - 1;
+ final currentUser = collaborators[listIndex];
+ final isSameAsLoggedInUser =
+ currentUserID == currentUser.id;
+ final isLastItem =
+ !isOwner && index == collaborators.length;
+ return Column(
+ children: [
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: isSameAsLoggedInUser
+ ? context.l10n.you
+ : _nameIfAvailableElseEmail(currentUser),
+ makeTextBold: isSameAsLoggedInUser,
+ ),
+ leadingIconSize: 24.0,
+ leadingIconWidget: UserAvatarWidget(
+ currentUser,
+ type: AvatarType.mini,
+ currentUserID: currentUserID,
+ ),
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ trailingIcon: isOwner ? Icons.chevron_right : null,
+ trailingIconIsMuted: true,
+ onTap: isOwner
+ ? () async {
+ if (isOwner) {
+ // ignore: unawaited_futures
+ _navigateToManageUser(currentUser);
+ }
+ }
+ : null,
+ isTopBorderRadiusRemoved: listIndex > 0,
+ isBottomBorderRadiusRemoved: !isLastItem,
+ singleBorderRadius: 8,
+ ),
+ isLastItem
+ ? const SizedBox.shrink()
+ : DividerWidget(
+ dividerType: DividerType.menu,
+ bgColor: getEnteColorScheme(context).fillFaint,
+ ),
+ ],
+ );
+ } else if (index == (1 + collaborators.length) && isOwner) {
+ return MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: collaborators.isNotEmpty
+ ? context.l10n.addMore
+ : context.l10n.addCollaborator,
+ makeTextBold: true,
+ ),
+ leadingIcon: Icons.add_outlined,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ onTap: () async {
+ // ignore: unawaited_futures
+ _navigateToAddUser(false);
+ },
+ isTopBorderRadiusRemoved: collaborators.isNotEmpty,
+ singleBorderRadius: 8,
+ );
+ }
+ return const SizedBox.shrink();
+ },
+ childCount: 1 + collaborators.length + 1,
+ ),
+ ),
+ ),
+ SliverPadding(
+ padding: const EdgeInsets.only(top: 24, left: 16, right: 16),
+ sliver: SliverList(
+ delegate: SliverChildBuilderDelegate(
+ (context, index) {
+ if (index == 0 && (isOwner || viewers.isNotEmpty)) {
+ return MenuSectionTitle(
+ title: context.l10n.viewer,
+ iconData: Icons.photo_outlined,
+ );
+ } else if (index > 0 && index <= viewers.length) {
+ final listIndex = index - 1;
+ final currentUser = viewers[listIndex];
+ final isSameAsLoggedInUser =
+ currentUserID == currentUser.id;
+ final isLastItem = !isOwner && index == viewers.length;
+ return Column(
+ children: [
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: isSameAsLoggedInUser
+ ? context.l10n.you
+ : _nameIfAvailableElseEmail(currentUser),
+ makeTextBold: isSameAsLoggedInUser,
+ ),
+ leadingIconSize: 24.0,
+ leadingIconWidget: UserAvatarWidget(
+ currentUser,
+ type: AvatarType.mini,
+ currentUserID: currentUserID,
+ ),
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ trailingIcon: isOwner ? Icons.chevron_right : null,
+ trailingIconIsMuted: true,
+ onTap: isOwner
+ ? () async {
+ if (isOwner) {
+ // ignore: unawaited_futures
+ _navigateToManageUser(currentUser);
+ }
+ }
+ : null,
+ isTopBorderRadiusRemoved: listIndex > 0,
+ isBottomBorderRadiusRemoved: !isLastItem,
+ singleBorderRadius: 8,
+ ),
+ isLastItem
+ ? const SizedBox.shrink()
+ : DividerWidget(
+ dividerType: DividerType.menu,
+ bgColor: getEnteColorScheme(context).fillFaint,
+ ),
+ ],
+ );
+ } else if (index == (1 + viewers.length) && isOwner) {
+ return MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: viewers.isNotEmpty
+ ? context.l10n.addMore
+ : context.l10n.addViewer,
+ makeTextBold: true,
+ ),
+ leadingIcon: Icons.add_outlined,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ onTap: () async {
+ // ignore: unawaited_futures
+ _navigateToAddUser(true);
+ },
+ isTopBorderRadiusRemoved: viewers.isNotEmpty,
+ singleBorderRadius: 8,
+ );
+ }
+ return const SizedBox.shrink();
+ },
+ childCount: 1 + viewers.length + 1,
+ ),
+ ),
+ ),
+ const SliverToBoxAdapter(child: SizedBox(height: 72)),
+ ],
+ ),
+ );
+ }
+
+ String _nameIfAvailableElseEmail(User user) {
+ final name = user.displayName;
+ if (name != null && name.isNotEmpty) {
+ return name;
+ }
+ return user.email;
+ }
+}
diff --git a/mobile/apps/locker/lib/ui/sharing/album_share_info_widget.dart b/mobile/apps/locker/lib/ui/sharing/album_share_info_widget.dart
new file mode 100644
index 0000000000..0cc82b985c
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/sharing/album_share_info_widget.dart
@@ -0,0 +1,102 @@
+import "dart:math";
+
+import "package:flutter/material.dart";
+import "package:locker/services/collections/models/user.dart";
+import "package:locker/ui/sharing/more_count_badge.dart";
+import "package:locker/ui/sharing/user_avator_widget.dart";
+
+class AlbumSharesIcons extends StatelessWidget {
+ final List<User> sharees;
+ final int limitCountTo;
+ final AvatarType type;
+ final bool removeBorder;
+ final EdgeInsets padding;
+ final Widget? trailingWidget;
+ final Alignment stackAlignment;
+
+ const AlbumSharesIcons({
+ super.key,
+ required this.sharees,
+ this.type = AvatarType.tiny,
+ this.limitCountTo = 2,
+ this.removeBorder = true,
+ this.trailingWidget,
+ this.padding = const EdgeInsets.only(left: 10.0, top: 10, bottom: 10),
+ this.stackAlignment = Alignment.topLeft,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final displayCount = min(sharees.length, limitCountTo);
+ final hasMore = sharees.length > limitCountTo;
+ final double overlapPadding = getOverlapPadding(type);
+ final widgets = List<Widget>.generate(
+ displayCount,
+ (index) => Positioned(
+ left: overlapPadding * index,
+ child: UserAvatarWidget(
+ sharees[index],
+ thumbnailView: removeBorder,
+ type: type,
+ ),
+ ),
+ );
+
+ if (hasMore) {
+ widgets.add(
+ Positioned(
+ left: (overlapPadding * displayCount),
+ child: MoreCountWidget(
+ sharees.length - displayCount,
+ type: moreCountTypeFromAvatarType(type),
+ thumbnailView: removeBorder,
+ ),
+ ),
+ );
+ }
+ if (trailingWidget != null) {
+ widgets.add(
+ Positioned(
+ left: (overlapPadding * (displayCount + (hasMore ? 1 : 0))) +
+ (displayCount > 0 ? 12 : 0),
+ child: trailingWidget!,
+ ),
+ );
+ }
+
+ return Padding(
+ padding: padding,
+ child: Stack(
+ alignment: stackAlignment,
+ clipBehavior: Clip.none,
+ children: widgets,
+ ),
+ );
+ }
+}
+
+double getOverlapPadding(AvatarType type) {
+ switch (type) {
+ case AvatarType.extra:
+ return 14.0;
+ case AvatarType.tiny:
+ return 14.0;
+ case AvatarType.mini:
+ return 20.0;
+ case AvatarType.small:
+ return 28.0;
+ }
+}
+
+MoreCountType moreCountTypeFromAvatarType(AvatarType type) {
+ switch (type) {
+ case AvatarType.extra:
+ return MoreCountType.extra;
+ case AvatarType.tiny:
+ return MoreCountType.tiny;
+ case AvatarType.mini:
+ return MoreCountType.mini;
+ case AvatarType.small:
+ return MoreCountType.small;
+ }
+}
diff --git a/mobile/apps/locker/lib/ui/sharing/manage_album_participant.dart b/mobile/apps/locker/lib/ui/sharing/manage_album_participant.dart
new file mode 100644
index 0000000000..905688eec8
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/sharing/manage_album_participant.dart
@@ -0,0 +1,188 @@
+import "package:ente_ui/components/buttons/button_widget.dart";
+import "package:ente_ui/components/captioned_text_widget.dart";
+import "package:ente_ui/components/divider_widget.dart";
+import "package:ente_ui/components/menu_item_widget.dart";
+import "package:ente_ui/components/menu_section_description_widget.dart";
+import "package:ente_ui/components/menu_section_title.dart";
+import "package:ente_ui/components/title_bar_title_widget.dart";
+import "package:ente_ui/theme/colors.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:ente_ui/utils/dialog_util.dart";
+import 'package:flutter/material.dart';
+import "package:locker/extensions/user_extension.dart";
+import "package:locker/l10n/l10n.dart";
+import "package:locker/services/collections/models/collection.dart";
+import "package:locker/services/collections/models/user.dart";
+import "package:locker/utils/collection_actions.dart";
+
+class ManageIndividualParticipant extends StatefulWidget {
+ final Collection collection;
+ final User user;
+
+ const ManageIndividualParticipant({
+ super.key,
+ required this.collection,
+ required this.user,
+ });
+
+ @override
+ State<StatefulWidget> createState() => _ManageIndividualParticipantState();
+}
+
+class _ManageIndividualParticipantState
+ extends State<ManageIndividualParticipant> {
+ late CollectionActions collectionActions;
+
+ @override
+ void initState() {
+ super.initState();
+ collectionActions = CollectionActions();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ bool isConvertToViewSuccess = false;
+ return Scaffold(
+ appBar: AppBar(),
+ body: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.start,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SafeArea(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(
+ height: 12,
+ ),
+ TitleBarTitleWidget(
+ title: context.l10n.manage,
+ ),
+ Text(
+ widget.user.email,
+ textAlign: TextAlign.left,
+ style:
+ textTheme.small.copyWith(color: colorScheme.textMuted),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 12),
+ MenuSectionTitle(title: context.l10n.addedAs),
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.collaborator,
+ ),
+ leadingIcon: Icons.edit_outlined,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ trailingIcon: widget.user.isCollaborator ? Icons.check : null,
+ onTap: widget.user.isCollaborator
+ ? null
+ : () async {
+ final result =
+ await collectionActions.addEmailToCollection(
+ context,
+ widget.collection,
+ widget.user.email,
+ CollectionParticipantRole.collaborator,
+ );
+ if (result && mounted) {
+ widget.user.role = CollectionParticipantRole
+ .collaborator
+ .toStringVal();
+ setState(() => {});
+ }
+ },
+ isBottomBorderRadiusRemoved: true,
+ ),
+ DividerWidget(
+ dividerType: DividerType.menu,
+ bgColor: getEnteColorScheme(context).fillFaint,
+ ),
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.viewer,
+ ),
+ leadingIcon: Icons.photo_outlined,
+ leadingIconColor: getEnteColorScheme(context).strokeBase,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ trailingIcon: widget.user.isViewer ? Icons.check : null,
+ showOnlyLoadingState: true,
+ onTap: widget.user.isViewer
+ ? null
+ : () async {
+ final actionResult = await showChoiceActionSheet(
+ context,
+ title: context.l10n.changePermissions,
+ firstButtonLabel: context.l10n.yesConvertToViewer,
+ body:
+ context.l10n.cannotAddMoreFilesAfterBecomingViewer(
+ widget.user.displayName ?? widget.user.email,
+ ),
+ isCritical: true,
+ );
+ if (actionResult?.action != null) {
+ if (actionResult!.action == ButtonAction.first) {
+ try {
+ isConvertToViewSuccess =
+ await collectionActions.addEmailToCollection(
+ context,
+ widget.collection,
+ widget.user.email,
+ CollectionParticipantRole.viewer,
+ );
+ } catch (e) {
+ await showGenericErrorDialog(
+ context: context,
+ error: e,
+ );
+ }
+ if (isConvertToViewSuccess && mounted) {
+ // reset value
+ isConvertToViewSuccess = false;
+ widget.user.role =
+ CollectionParticipantRole.viewer.toStringVal();
+ setState(() => {});
+ }
+ }
+ }
+ },
+ isTopBorderRadiusRemoved: true,
+ ),
+ MenuSectionDescriptionWidget(
+ content: context.l10n.collaboratorsCanAddFilesToTheSharedAlbum,
+ ),
+ const SizedBox(height: 24),
+ MenuSectionTitle(title: context.l10n.removeParticipant),
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.remove,
+ textColor: warning500,
+ makeTextBold: true,
+ ),
+ leadingIcon: Icons.not_interested_outlined,
+ leadingIconColor: warning500,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ surfaceExecutionStates: false,
+ onTap: () async {
+ final result = await collectionActions.removeParticipant(
+ context,
+ widget.collection,
+ widget.user,
+ );
+
+ if ((result) && mounted) {
+ Navigator.of(context).pop(true);
+ }
+ },
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/locker/lib/ui/sharing/more_count_badge.dart b/mobile/apps/locker/lib/ui/sharing/more_count_badge.dart
new file mode 100644
index 0000000000..6ff660e9ff
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/sharing/more_count_badge.dart
@@ -0,0 +1,79 @@
+import "package:ente_ui/theme/colors.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import 'package:flutter/material.dart';
+import 'package:tuple/tuple.dart';
+
+enum MoreCountType { small, mini, tiny, extra }
+
+class MoreCountWidget extends StatelessWidget {
+ final MoreCountType type;
+ final bool thumbnailView;
+ final int count;
+
+ const MoreCountWidget(
+ this.count, {
+ super.key,
+ this.type = MoreCountType.mini,
+ this.thumbnailView = false,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final displayChar = "+$count";
+ final Color decorationColor = thumbnailView
+ ? backgroundElevated2Light
+ : colorScheme.backgroundElevated2;
+
+ final avatarStyle = getAvatarStyle(context, type);
+ final double size = avatarStyle.item1;
+ final TextStyle textStyle = thumbnailView
+ ? avatarStyle.item2.copyWith(color: textFaintLight)
+ : avatarStyle.item2.copyWith(color: Colors.white);
+ return Container(
+ padding: const EdgeInsets.all(0.5),
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ border: Border.all(
+ color: thumbnailView
+ ? strokeMutedDark
+ : getEnteColorScheme(context).strokeMuted,
+ width: 1.0,
+ strokeAlign: BorderSide.strokeAlignOutside,
+ ),
+ ),
+ child: SizedBox(
+ height: size,
+ width: size,
+ child: CircleAvatar(
+ backgroundColor: decorationColor,
+ child: Transform.scale(
+ scale: 0.85,
+ child: Text(
+ displayChar.toUpperCase(),
+ // fixed color
+ style: textStyle,
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ Tuple2<double, TextStyle> getAvatarStyle(
+ BuildContext context,
+ MoreCountType type,
+ ) {
+ final enteTextTheme = getEnteTextTheme(context);
+ switch (type) {
+ case MoreCountType.small:
+ return Tuple2(32.0, enteTextTheme.small);
+ case MoreCountType.mini:
+ return Tuple2(24.0, enteTextTheme.mini);
+ case MoreCountType.tiny:
+ return Tuple2(18.0, enteTextTheme.tiny);
+ case MoreCountType.extra:
+ return Tuple2(18.0, enteTextTheme.tiny);
+ }
+ }
+}