π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[locker] Add leave option for shared collections and improve UI consistency
AmanRajSinghMourya8aee24fee5a5
diff --git a/mobile/apps/locker/lib/ui/components/delete_confirmation_sheet.dart b/mobile/apps/locker/lib/ui/components/delete_confirmation_sheet.dartindex 6db65b748f..f354b14795 100644--- a/mobile/apps/locker/lib/ui/components/delete_confirmation_sheet.dart+++ b/mobile/apps/locker/lib/ui/components/delete_confirmation_sheet.dart@@ -1,6 +1,6 @@-import "package:ente_ui/components/base_bottom_sheet.dart";import "package:ente_ui/components/buttons/button_widget.dart";import "package:ente_ui/components/buttons/models/button_result.dart";+import "package:ente_ui/components/close_icon_button.dart";import "package:ente_ui/theme/ente_theme.dart";import "package:flutter/material.dart";import "package:locker/l10n/l10n.dart";@@ -24,12 +24,13 @@ Future<DeleteConfirmationResult?> showDeleteConfirmationSheet(required String assetPath,bool showDeleteFromAllCollectionsOption = false,}) {- return showBaseBottomSheet<DeleteConfirmationResult>(- context,- title: title,- headerSpacing: 20,- crossAxisAlignment: CrossAxisAlignment.center,- child: DeleteConfirmationSheet(+ return showModalBottomSheet<DeleteConfirmationResult>(+ context: context,+ isScrollControlled: true,+ isDismissible: true,+ backgroundColor: Colors.transparent,+ builder: (context) => DeleteConfirmationSheet(+ title: title,body: body,deleteButtonLabel: deleteButtonLabel,assetPath: assetPath,@@ -39,6 +40,7 @@ Future<DeleteConfirmationResult?> showDeleteConfirmationSheet(}class DeleteConfirmationSheet extends StatefulWidget {+ final String title;final String body;final String deleteButtonLabel;final String assetPath;@@ -46,6 +48,7 @@ class DeleteConfirmationSheet extends StatefulWidget {const DeleteConfirmationSheet({super.key,+ required this.title,required this.body,required this.deleteButtonLabel,required this.assetPath,@@ -65,87 +68,114 @@ class _DeleteConfirmationSheetState extends State<DeleteConfirmationSheet> {final textTheme = getEnteTextTheme(context);final colorScheme = getEnteColorScheme(context);- return Column(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.center,- children: [- Center(child: Image.asset(widget.assetPath)),- const SizedBox(height: 16),- Text(- widget.body,- style: textTheme.body.copyWith(- color: colorScheme.textMuted,- ),- textAlign: TextAlign.center,+ return Container(+ decoration: BoxDecoration(+ color: colorScheme.backgroundElevated2,+ borderRadius: const BorderRadius.only(+ topLeft: Radius.circular(24),+ topRight: Radius.circular(24),),- const SizedBox(height: 20),- if (widget.showDeleteFromAllCollectionsOption) ...[- GestureDetector(- onTap: () {- setState(() {- _deleteFromAllCollections = !_deleteFromAllCollections;- });- },- child: SizedBox(- width: double.infinity,- child: Wrap(- alignment: WrapAlignment.center,- crossAxisAlignment: WrapCrossAlignment.center,- spacing: 12,- runSpacing: 8,+ ),+ child: SafeArea(+ top: false,+ child: Padding(+ padding: const EdgeInsets.all(16),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.center,+ children: [+ const Row(+ mainAxisAlignment: MainAxisAlignment.end,children: [- Container(- width: 18,- height: 18,- decoration: BoxDecoration(- border: Border.all(- color: _deleteFromAllCollections- ? colorScheme.primary700- : colorScheme.strokeMuted,- width: 2,- ),- borderRadius: BorderRadius.circular(6),- color: _deleteFromAllCollections- ? colorScheme.primary700- : Colors.transparent,- ),- alignment: Alignment.center,- child: _deleteFromAllCollections- ? const Icon(- Icons.check,- size: 12,- color: Colors.white,- )- : null,- ),- Text(- context.l10n.deleteCollectionFromEverywhere,- style: textTheme.small,- textAlign: TextAlign.center,- ),+ CloseIconButton(),],),- ),- ),- const SizedBox(height: 20),- ],- const SizedBox(height: 12),- SizedBox(- width: double.infinity,- child: GradientButton(- onTap: () {- Navigator.of(context).pop(- DeleteConfirmationResult(- buttonResult: ButtonResult(ButtonAction.first),- deleteFromAllCollections: _deleteFromAllCollections,+ const SizedBox(height: 12),+ Center(child: Image.asset(widget.assetPath)),+ const SizedBox(height: 20),+ Text(+ widget.title,+ style: textTheme.h3Bold,+ textAlign: TextAlign.center,+ ),+ const SizedBox(height: 12),+ Text(+ widget.body,+ style: textTheme.body.copyWith(+ color: colorScheme.textMuted,),- );- },- text: widget.deleteButtonLabel,- backgroundColor: colorScheme.warning400,+ textAlign: TextAlign.center,+ ),+ if (widget.showDeleteFromAllCollectionsOption) ...[+ const SizedBox(height: 20),+ GestureDetector(+ onTap: () {+ setState(() {+ _deleteFromAllCollections = !_deleteFromAllCollections;+ });+ },+ child: SizedBox(+ width: double.infinity,+ child: Wrap(+ alignment: WrapAlignment.center,+ crossAxisAlignment: WrapCrossAlignment.center,+ spacing: 12,+ runSpacing: 8,+ children: [+ Container(+ width: 18,+ height: 18,+ decoration: BoxDecoration(+ border: Border.all(+ color: _deleteFromAllCollections+ ? colorScheme.primary700+ : colorScheme.strokeMuted,+ width: 2,+ ),+ borderRadius: BorderRadius.circular(6),+ color: _deleteFromAllCollections+ ? colorScheme.primary700+ : Colors.transparent,+ ),+ alignment: Alignment.center,+ child: _deleteFromAllCollections+ ? const Icon(+ Icons.check,+ size: 12,+ color: Colors.white,+ )+ : null,+ ),+ Text(+ context.l10n.deleteCollectionFromEverywhere,+ style: textTheme.small,+ textAlign: TextAlign.center,+ ),+ ],+ ),+ ),+ ),+ ],+ const SizedBox(height: 20),+ SizedBox(+ width: double.infinity,+ child: GradientButton(+ onTap: () {+ Navigator.of(context).pop(+ DeleteConfirmationResult(+ buttonResult: ButtonResult(ButtonAction.first),+ deleteFromAllCollections: _deleteFromAllCollections,+ ),+ );+ },+ text: widget.deleteButtonLabel,+ backgroundColor: colorScheme.warning400,+ ),+ ),+ ],),),- ],+ ),);}}diff --git a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dartindex 4e541c4af8..467a4192b3 100644--- a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart+++ b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart@@ -31,10 +31,11 @@ class _CollectionSelectionOverlayBarStateextends State<CollectionSelectionOverlayBar> {static final _logger = Logger('CollectionSelectionOverlayBar');+ int get _currentUserID => Configuration.instance.getUserID()!;+List<Collection> _getOwnedCollections(List<Collection> collections) {- final currentUserID = Configuration.instance.getUserID()!;final ownedCollections =- collections.where((c) => c.isOwner(currentUserID)).toList();+ collections.where((c) => c.isOwner(_currentUserID)).toList();final sharedCount = collections.length - ownedCollections.length;if (sharedCount > 0 && mounted) {@@ -47,6 +48,10 @@ class _CollectionSelectionOverlayBarStatereturn ownedCollections;}+ List<Collection> _getSharedIncomingCollections(List<Collection> collections) {+ return collections.where((c) => !c.isOwner(_currentUserID)).toList();+ }+@overridevoid initState() {super.initState();@@ -220,8 +225,17 @@ class _CollectionSelectionOverlayBarStatefinal isSingleSelection = selectedCollections.length == 1;final collection = isSingleSelection ? selectedCollections.first : null;+ final ownedCollections =+ selectedCollections.where((c) => c.isOwner(_currentUserID)).toList();+ final sharedIncomingCollections = _getSharedIncomingCollections(+ selectedCollections.toList(),+ );++ final hasOwnedCollections = ownedCollections.isNotEmpty;+ final hasSharedIncoming = sharedIncomingCollections.isNotEmpty;+final primaryActions = <Widget>[- if (isSingleSelection)+ if (isSingleSelection && hasOwnedCollections)SelectionActionButton(hugeIcon: const HugeIcon(icon: HugeIcons.strokeRoundedNavigation06,@@ -229,7 +243,7 @@ class _CollectionSelectionOverlayBarStatelabel: context.l10n.share,onTap: () => _shareCollection(collection!),),- if (isSingleSelection)+ if (isSingleSelection && hasOwnedCollections)SelectionActionButton(hugeIcon: const HugeIcon(icon: HugeIcons.strokeRoundedPencilEdit02,@@ -237,25 +251,42 @@ class _CollectionSelectionOverlayBarStatelabel: context.l10n.edit,onTap: () => _editCollection(collection!),),- SelectionActionButton(- hugeIcon: HugeIcon(- icon: HugeIcons.strokeRoundedDelete02,- color: colorScheme.warning500,+ if (hasSharedIncoming)+ SelectionActionButton(+ hugeIcon: HugeIcon(+ icon: HugeIcons.strokeRoundedLogout02,+ color: colorScheme.warning500,+ ),+ label: context.l10n.leaveCollection,+ onTap: () => _leaveCollections(sharedIncomingCollections),+ isDestructive: true,+ ),+ if (hasOwnedCollections)+ SelectionActionButton(+ hugeIcon: HugeIcon(+ icon: HugeIcons.strokeRoundedDelete02,+ color: colorScheme.warning500,+ ),+ label: context.l10n.delete,+ onTap: () {+ if (isSingleSelection) {+ _deleteCollection(collection!);+ } else {+ _deleteMultipleCollections(selectedCollections);+ }+ },+ isDestructive: true,),- label: context.l10n.delete,- onTap: () {- if (isSingleSelection) {- _deleteCollection(collection!);- } else {- _deleteMultipleCollections(selectedCollections);- }- },- isDestructive: true,- ),];- return Row(- children: _buildActionRow(primaryActions),+ return Container(+ decoration: BoxDecoration(+ color: colorScheme.backgroundElevated2,+ borderRadius: BorderRadius.circular(24),+ ),+ child: Row(+ children: _buildActionRow(primaryActions),+ ),);}@@ -342,4 +373,29 @@ class _CollectionSelectionOverlayBarState}widget.selectedCollections.clearAll();}++ Future<void> _leaveCollections(List<Collection> collections) async {+ if (collections.isEmpty) {+ widget.selectedCollections.clearAll();+ return;+ }++ try {+ if (collections.length == 1) {+ await CollectionActions.leaveCollection(+ context,+ collections.first,+ );+ } else {+ await CollectionActions.leaveMultipleCollection(+ context,+ collections,+ );+ }+ } catch (e, s) {+ _logger.severe(e, s);+ await showGenericErrorDialog(context: context, error: e);+ }+ widget.selectedCollections.clearAll();+ }}diff --git a/mobile/apps/locker/lib/utils/collection_actions.dart b/mobile/apps/locker/lib/utils/collection_actions.dartindex a67bba9614..47fda6a129 100644--- a/mobile/apps/locker/lib/utils/collection_actions.dart+++ b/mobile/apps/locker/lib/utils/collection_actions.dart@@ -376,46 +376,40 @@ class CollectionActions {List<Collection> collections, {VoidCallback? onSuccess,}) async {- final actionResult = await showActionSheet(- context: context,+ final confirmed = await showAlertBottomSheet(+ context,+ title: context.l10n.leaveCollection,+ message: context.l10n.filesAddedByYouWillBeRemovedFromTheCollection,+ assetPath: "assets/warning-grey.png",buttons: [- ButtonWidget(- buttonType: ButtonType.critical,- isInAlert: true,- shouldStickToDarkTheme: true,- buttonAction: ButtonAction.first,- shouldSurfaceExecutionStates: true,- labelText: context.l10n.leaveCollection,- onTap: () async {- for (final col in collections) {- await CollectionApiClient.instance.leaveCollection(col);- }- },- ),- ButtonWidget(- buttonType: ButtonType.secondary,- buttonAction: ButtonAction.cancel,- isInAlert: true,- shouldStickToDarkTheme: true,- labelText: context.l10n.cancel,+ SizedBox(+ child: GradientButton(+ text: context.l10n.leaveCollection,+ onTap: () => Navigator.of(context).pop(true),+ ),),],- title: context.l10n.leaveCollection,- body: context.l10n.filesAddedByYouWillBeRemovedFromTheCollection,);- if (actionResult?.action != null && context.mounted) {- if (actionResult!.action == ButtonAction.error) {- await showGenericErrorDialog(- context: context,- error: actionResult.exception,- );- } else if (actionResult.action == ButtonAction.first) {- onSuccess?.call();- Navigator.of(context).pop();- showToast(- context,- "Leave collection successfully",- );+ if (confirmed == true) {+ try {+ for (final col in collections) {+ await CollectionApiClient.instance.leaveCollection(col);+ }+ if (context.mounted) {+ onSuccess?.call();+ showToast(+ context,+ "Left ${collections.length} collection${collections.length > 1 ? 's' : ''} successfully",+ );+ }+ } catch (e) {+ _logger.severe("Failed to leave collections", e);+ if (context.mounted) {+ showToast(+ context,+ context.l10n.somethingWentWrong,+ );+ }}}}