Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add user management features to sharing collection page and actions

AmanRajSinghMouryae7d7f1cdd0ea
diff --git a/mobile/apps/locker/lib/ui/sharing/manage_links_widget.dart b/mobile/apps/locker/lib/ui/sharing/manage_links_widget.dart
index cc36954218..2d54d338ff 100644
--- a/mobile/apps/locker/lib/ui/sharing/manage_links_widget.dart
+++ b/mobile/apps/locker/lib/ui/sharing/manage_links_widget.dart
@@ -4,6 +4,7 @@ import "package:ente_crypto_dart/ente_crypto_dart.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/toggle_switch_widget.dart";
import "package:ente_ui/theme/colors.dart";
import "package:ente_ui/theme/ente_theme.dart";
@@ -17,8 +18,7 @@ import "package:locker/l10n/l10n.dart";
import "package:locker/services/collections/collections_api_client.dart";
import "package:locker/services/collections/collections_service.dart";
import "package:locker/services/collections/models/collection.dart";
-import "package:locker/services/collections/models/public_url.dart";
-import "package:locker/ui/components/menu_section_description_widget.dart";
+import "package:locker/services/collections/models/public_url.dart";
import "package:locker/ui/sharing/pickers/device_limit_picker_page.dart";
import "package:locker/ui/sharing/pickers/link_expiry_picker_page.dart";
import "package:locker/utils/collection_actions.dart";
diff --git a/mobile/apps/locker/lib/ui/sharing/share_collection_page.dart b/mobile/apps/locker/lib/ui/sharing/share_collection_page.dart
index 1a66c14b15..8c2aacc087 100644
--- a/mobile/apps/locker/lib/ui/sharing/share_collection_page.dart
+++ b/mobile/apps/locker/lib/ui/sharing/share_collection_page.dart
@@ -1,16 +1,25 @@
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/theme/colors.dart";
import "package:ente_ui/theme/ente_theme.dart";
import "package:ente_ui/utils/toast_util.dart";
import "package:ente_utils/ente_utils.dart";
import "package:flutter/material.dart";
import "package:flutter/services.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/ui/components/menu_section_title.dart";
+import "package:locker/services/collections/models/user.dart";
+import "package:locker/ui/sharing/add_participant_page.dart";
+import "package:locker/ui/sharing/album_participants_page.dart";
+import "package:locker/ui/sharing/album_share_info_widget.dart";
+import "package:locker/ui/sharing/manage_album_participant.dart";
import "package:locker/ui/sharing/manage_links_widget.dart";
+import "package:locker/ui/sharing/user_avator_widget.dart";
import "package:locker/utils/collection_actions.dart";
class ShareCollectionPage extends StatefulWidget {
@@ -22,18 +31,125 @@ class ShareCollectionPage extends StatefulWidget {
}
class _ShareCollectionPageState extends State<ShareCollectionPage> {
+ late List<User?> _sharees;
+
+ Future<void> _navigateToManageUser() async {
+ if (_sharees.length == 1) {
+ await routeToPage(
+ context,
+ ManageIndividualParticipant(
+ collection: widget.collection,
+ user: _sharees.first!,
+ ),
+ );
+ } else {
+ await routeToPage(
+ context,
+ AlbumParticipantsPage(widget.collection),
+ );
+ }
+ if (mounted) {
+ setState(() => {});
+ }
+ }
+
@override
Widget build(BuildContext context) {
- final bool hasUrl = widget.collection.hasLink;
+ final bool hasUrl = widget.collection.hasLink;
final bool hasExpired =
widget.collection.publicURLs.firstOrNull?.isExpired ?? false;
+ _sharees = widget.collection.sharees;
+
final children = <Widget>[];
+
+ children.add(
+ MenuSectionTitle(
+ title: context.l10n.shareWithPeopleSectionTitle(_sharees.length),
+ iconData: Icons.workspaces,
+ ),
+ );
+
+ children.add(
+ EmailItemWidget(
+ widget.collection,
+ onTap: _navigateToManageUser,
+ ),
+ );
+
+ children.add(
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.addViewer,
+ makeTextBold: true,
+ ),
+ leadingIcon: Icons.add,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ isTopBorderRadiusRemoved: _sharees.isNotEmpty,
+ isBottomBorderRadiusRemoved: true,
+ onTap: () async {
+ // ignore: unawaited_futures
+ routeToPage(
+ context,
+ AddParticipantPage(
+ [widget.collection],
+ const [ActionTypesToShow.addViewer],
+ ),
+ ).then(
+ (value) => {
+ if (mounted) {setState(() => {})},
+ },
+ );
+ },
+ ),
+ );
+ children.add(
+ DividerWidget(
+ dividerType: DividerType.menu,
+ bgColor: getEnteColorScheme(context).fillFaint,
+ ),
+ );
+
+ children.add(
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.addCollaborator,
+ makeTextBold: true,
+ ),
+ leadingIcon: Icons.add,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ isTopBorderRadiusRemoved: true,
+ onTap: () async {
+ // ignore: unawaited_futures
+ routeToPage(
+ context,
+ AddParticipantPage(
+ [widget.collection],
+ const [ActionTypesToShow.addCollaborator],
+ ),
+ ).then(
+ (value) => {
+ if (mounted) {setState(() => {})},
+ },
+ );
+ },
+ ),
+ );
+
+ if (_sharees.isEmpty && !hasUrl) {
+ children.add(
+ MenuSectionDescriptionWidget(
+ content: context.l10n.sharedCollectionSectionDescription,
+ ),
+ );
+ }
+
children.addAll([
const SizedBox(
height: 24,
),
MenuSectionTitle(
- title: hasUrl ? "Public link enabled" : "Share a link",
+ title:
+ hasUrl ? context.l10n.publicLinkEnabled : context.l10n.shareALink,
iconData: Icons.public,
),
]);
@@ -42,7 +158,7 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
children.add(
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
- title: "Link has expired",
+ title: context.l10n.linkHasExpired,
textColor: getEnteColorScheme(context).warning500,
),
leadingIcon: Icons.error_outline,
@@ -57,8 +173,8 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
children.addAll(
[
MenuItemWidget(
- captionedTextWidget: const CaptionedTextWidget(
- title: "Copy link",
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.copyLink,
makeTextBold: true,
),
leadingIcon: Icons.copy,
@@ -75,8 +191,8 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
bgColor: getEnteColorScheme(context).fillFaint,
),
MenuItemWidget(
- captionedTextWidget: const CaptionedTextWidget(
- title: "Send link",
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.sendLink,
makeTextBold: true,
),
leadingIcon: Icons.adaptive.share,
@@ -102,8 +218,8 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
bgColor: getEnteColorScheme(context).fillFaint,
),
MenuItemWidget(
- captionedTextWidget: const CaptionedTextWidget(
- title: "Manage link",
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.manageLink,
makeTextBold: true,
),
leadingIcon: Icons.link,
@@ -125,8 +241,8 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
),
const SizedBox(height: 24),
MenuItemWidget(
- captionedTextWidget: const CaptionedTextWidget(
- title: "Remove Link",
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.removeLink,
textColor: warning500,
makeTextBold: true,
),
@@ -153,8 +269,8 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
children.addAll(
[
MenuItemWidget(
- captionedTextWidget: const CaptionedTextWidget(
- title: "Create public link",
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.createPublicLink,
makeTextBold: true,
),
leadingIcon: Icons.link,
@@ -198,3 +314,89 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
);
}
}
+
+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.getSharees().isEmpty) {
+ return const SizedBox.shrink();
+ } else if (collection.getSharees().length == 1) {
+ final User? user = collection.getSharees().firstOrNull;
+ return Column(
+ mainAxisAlignment: MainAxisAlignment.start,
+ children: [
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: user?.displayName ?? user?.email ?? '',
+ ),
+ leadingIconWidget: UserAvatarWidget(
+ collection.getSharees().first,
+ thumbnailView: false,
+ ),
+ leadingIconSize: 24,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ trailingIconIsMuted: true,
+ trailingIcon: Icons.chevron_right,
+ onTap: () async {
+ if (onTap != null) {
+ onTap!();
+ }
+ },
+ isBottomBorderRadiusRemoved: true,
+ ),
+ DividerWidget(
+ dividerType: DividerType.menu,
+ bgColor: getEnteColorScheme(context).fillFaint,
+ ),
+ ],
+ );
+ } else {
+ return Column(
+ mainAxisAlignment: MainAxisAlignment.start,
+ children: [
+ MenuItemWidget(
+ captionedTextWidget: Flexible(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 0),
+ child: SizedBox(
+ height: 24,
+ child: AlbumSharesIcons(
+ sharees: collection.getSharees(),
+ padding: const EdgeInsets.all(0),
+ limitCountTo: 10,
+ type: AvatarType.mini,
+ removeBorder: false,
+ ),
+ ),
+ ),
+ ),
+ alignCaptionedTextToLeft: true,
+ // leadingIcon: Icons.people_outline,
+ menuItemColor: getEnteColorScheme(context).fillFaint,
+ trailingIconIsMuted: true,
+ trailingIcon: Icons.chevron_right,
+ onTap: () async {
+ if (onTap != null) {
+ onTap!();
+ }
+ },
+ isBottomBorderRadiusRemoved: true,
+ ),
+ DividerWidget(
+ dividerType: DividerType.menu,
+ bgColor: getEnteColorScheme(context).fillFaint,
+ ),
+ ],
+ );
+ }
+ }
+}
diff --git a/mobile/apps/locker/lib/utils/collection_actions.dart b/mobile/apps/locker/lib/utils/collection_actions.dart
index 5918b1d80b..ce17a4420e 100644
--- a/mobile/apps/locker/lib/utils/collection_actions.dart
+++ b/mobile/apps/locker/lib/utils/collection_actions.dart
@@ -15,6 +15,7 @@ import 'package:locker/l10n/l10n.dart';
import "package:locker/services/collections/collections_api_client.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/services/configuration.dart";
import "package:locker/ui/components/user_dialogs.dart";
import 'package:locker/utils/snack_bar_utils.dart';
@@ -409,4 +410,50 @@ class CollectionActions {
}
}
}
+
+ // removeParticipant remove the user from a share album
+ Future<bool> removeParticipant(
+ BuildContext context,
+ Collection collection,
+ User user,
+ ) async {
+ final actionResult = await showActionSheet(
+ context: context,
+ buttons: [
+ ButtonWidget(
+ buttonType: ButtonType.critical,
+ isInAlert: true,
+ shouldStickToDarkTheme: true,
+ buttonAction: ButtonAction.first,
+ shouldSurfaceExecutionStates: true,
+ labelText: context.l10n.yesRemove,
+ onTap: () async {
+ final newSharees = await CollectionApiClient.instance
+ .unshare(collection.id, user.email);
+ collection.updateSharees(newSharees);
+ },
+ ),
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ buttonAction: ButtonAction.cancel,
+ isInAlert: true,
+ shouldStickToDarkTheme: true,
+ labelText: context.l10n.cancel,
+ ),
+ ],
+ title: context.l10n.removeWithQuestionMark,
+ body: context.l10n.removeParticipantBody(user.name ?? user.email),
+ );
+ if (actionResult?.action != null) {
+ if (actionResult!.action == ButtonAction.error) {
+ await showGenericErrorDialog(
+ context: context,
+ error: actionResult.exception,
+ );
+ }
+ return actionResult.action == ButtonAction.first;
+ }
+ return false;
+ }
+
}