π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Polish album delete bottom sheets
ashilknde33748d760b
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex fc935f3a4e..e7a46974e8 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -413,13 +413,14 @@"cannotMoveToSharedAlbumsMessage": "Items can only be added to shared albums, not moved. Would you like to add instead?","deleteSharedAlbum": "Delete shared album?","deleteAlbum": "Delete album",+ "deleteAlbumQuestion": "Delete this album?","deleteAlbumDialog": "Also delete the photos (and videos) present in this album from <bold>all</bold> other albums they are part of?","deleteSharedAlbumDialogBody": "The album will be deleted for everyone\n\nYou will lose access to shared photos in this album that are owned by others","yesRemove": "Yes, remove","creatingLink": "Creating link...","removeWithQuestionMark": "Remove?","removeParticipantBody": "{userEmail} will be removed from this shared album\n\nAny photos added by them will also be removed from the album",- "keepPhotos": "Keep Photos",+ "keepPhotos": "Keep photos","deletePhotos": "Delete photos","inviteToEnte": "Invite to Ente","removePublicLink": "Remove public link",@@ -2477,6 +2478,7 @@"memoriesWidgetDesc": "Select the kinds of memories you want to see on your home screen.","smartMemories": "Smart memories","pastYearsMemories": "Past years' memories",+ "deleteMultipleAlbumsQuestion": "Delete these albums?","deleteMultipleAlbumDialog": "Also delete the photos (and videos) present in these {count} albums from <bold>all</bold> other albums they are part of?","addParticipants": "Add participants","selectedAlbums": "{count} selected",diff --git a/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart b/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dartindex 50b94c8cd2..9c428fc1b0 100644--- a/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart+++ b/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart@@ -10,6 +10,7 @@ import 'package:photos/db/files_db.dart';import 'package:photos/gateways/collections/models/create_request.dart';import "package:photos/generated/l10n.dart";import "package:photos/models/api/collection/user.dart";+import 'package:photos/models/button_result.dart';import 'package:photos/models/collection/collection.dart';import 'package:photos/models/file/file.dart';import 'package:photos/models/files_split.dart';@@ -344,86 +345,33 @@ class CollectionActions {BuildContext context,List<Collection> collections,) async {- final colors = context.componentColors;- final actionResult = await showActionSheet(+ return _showDeleteCollectionConfirmationSheet(context: context,- buttons: [- ButtonWidget(- labelText: AppLocalizations.of(context).keepPhotos,- buttonType: ButtonType.neutral,- buttonSize: ButtonSize.large,- buttonAction: ButtonAction.first,- shouldStickToDarkTheme: true,- isInAlert: true,- onTap: () async {- for (final collection in collections) {- try {- await trashCollectionKeepingPhotos(collection, context);- } catch (e, s) {- logger.severe(- "Failed to keep photos & delete collection",- e,- s,- );- rethrow;- }- }- },- ),- ButtonWidget(- labelText: AppLocalizations.of(context).deletePhotos,- buttonType: ButtonType.critical,- buttonSize: ButtonSize.large,- buttonAction: ButtonAction.second,- shouldStickToDarkTheme: true,- isInAlert: true,- onTap: () async {- for (final collection in collections) {- try {- await collectionsService.trashNonEmptyCollection(collection);- } catch (e) {- logger.severe("Failed to delete collection", e);- rethrow;- }- }- },- ),- ButtonWidget(- labelText: AppLocalizations.of(context).cancel,- buttonType: ButtonType.secondary,- buttonSize: ButtonSize.large,- buttonAction: ButtonAction.third,- shouldStickToDarkTheme: true,- isInAlert: true,- ),- ],- bodyWidget: StyledText(- text: AppLocalizations.of(- context,- ).deleteMultipleAlbumDialog(count: collections.length),- style: TextStyles.body.copyWith(color: colors.textLight),- tags: {- 'bold': StyledTextTag(- style: TextStyles.body.copyWith(color: colors.textBase),- ),- },- ),- actionSheetType: ActionSheetType.defaultActionSheet,+ title: AppLocalizations.of(context).deleteMultipleAlbumsQuestion,+ message: AppLocalizations.of(+ context,+ ).deleteMultipleAlbumDialog(count: collections.length),+ keepPhotos: () async {+ for (final collection in collections) {+ try {+ await trashCollectionKeepingPhotos(collection, context);+ } catch (e, s) {+ logger.severe("Failed to keep photos & delete collection", e, s);+ rethrow;+ }+ }+ },+ deletePhotos: () async {+ for (final collection in collections) {+ try {+ await collectionsService.trashNonEmptyCollection(collection);+ } catch (e) {+ logger.severe("Failed to delete collection", e);+ rethrow;+ }+ }+ },);- if (actionResult?.action != null &&- actionResult!.action == ButtonAction.error) {- await showGenericErrorDialog(- context: context,- error: actionResult.exception,- );- return false;- }- if ((actionResult?.action != null) &&- (actionResult!.action == ButtonAction.first ||- actionResult.action == ButtonAction.second)) {- return true;- }- return false;}// deleteCollectionSheet returns true if the album is successfully deleted@@ -431,7 +379,6 @@ class CollectionActions {BuildContext bContext,Collection collection,) async {- final colors = bContext.componentColors;final currentUserID = Configuration.instance.getUserID()!;if (collection.owner.id != currentUserID) {throw AssertionError("Can not delete album owned by others");@@ -445,65 +392,83 @@ class CollectionActions {return false;}}- final actionResult = await showActionSheet(+ return _showDeleteCollectionConfirmationSheet(context: bContext,- buttons: [- ButtonWidget(- labelText: AppLocalizations.of(bContext).keepPhotos,- buttonType: ButtonType.neutral,- buttonSize: ButtonSize.large,- buttonAction: ButtonAction.first,- shouldStickToDarkTheme: true,- isInAlert: true,- onTap: () async {- try {- await trashCollectionKeepingPhotos(collection, bContext);- } catch (e, s) {- logger.severe("Failed to keep photos & delete collection", e, s);- rethrow;- }- },- ),- ButtonWidget(- labelText: AppLocalizations.of(bContext).deletePhotos,- buttonType: ButtonType.critical,- buttonSize: ButtonSize.large,- buttonAction: ButtonAction.second,- shouldStickToDarkTheme: true,- isInAlert: true,- onTap: () async {- try {- await collectionsService.trashNonEmptyCollection(collection);- } catch (e) {- logger.severe("Failed to delete collection", e);- rethrow;- }- },- ),- ButtonWidget(- labelText: AppLocalizations.of(bContext).cancel,- buttonType: ButtonType.secondary,- buttonSize: ButtonSize.large,- buttonAction: ButtonAction.third,- shouldStickToDarkTheme: true,- isInAlert: true,- ),- ],- bodyWidget: StyledText(- text: AppLocalizations.of(bContext).deleteAlbumDialog,- style: TextStyles.body.copyWith(color: colors.textLight),- tags: {- 'bold': StyledTextTag(- style: TextStyles.body.copyWith(color: colors.textBase),+ title: AppLocalizations.of(bContext).deleteAlbumQuestion,+ message: AppLocalizations.of(bContext).deleteAlbumDialog,+ keepPhotos: () async {+ try {+ await trashCollectionKeepingPhotos(collection, bContext);+ } catch (e, s) {+ logger.severe("Failed to keep photos & delete collection", e, s);+ rethrow;+ }+ },+ deletePhotos: () async {+ try {+ await collectionsService.trashNonEmptyCollection(collection);+ } catch (e) {+ logger.severe("Failed to delete collection", e);+ rethrow;+ }+ },+ );+ }++ Future<bool> _showDeleteCollectionConfirmationSheet({+ required BuildContext context,+ required String title,+ required String message,+ required Future<void> Function() keepPhotos,+ required Future<void> Function() deletePhotos,+ }) async {+ final l10n = AppLocalizations.of(context);+ final actionResult = await showBottomSheetComponent<ButtonResult>(+ context: context,+ builder: (sheetContext) {+ final colors = sheetContext.componentColors;+ return BottomSheetComponent(+ title: title,+ illustration: Image.asset("assets/warning-grey.png"),+ closeTooltip: l10n.close,+ closeResult: ButtonResult(ButtonAction.third),+ content: StyledText(+ text: message,+ textAlign: TextAlign.center,+ style: TextStyles.body.copyWith(color: colors.textLight),+ tags: {+ 'bold': StyledTextTag(+ style: TextStyles.body.copyWith(color: colors.textBase),+ ),+ },),- },- ),- actionSheetType: ActionSheetType.defaultActionSheet,+ actions: [+ ButtonComponent(+ label: l10n.keepPhotos,+ variant: ButtonComponentVariant.neutral,+ onTap: () => _runCollectionAction(+ sheetContext,+ ButtonAction.first,+ keepPhotos,+ ),+ ),+ ButtonComponent(+ label: l10n.deletePhotos,+ variant: ButtonComponentVariant.critical,+ onTap: () => _runCollectionAction(+ sheetContext,+ ButtonAction.second,+ deletePhotos,+ ),+ ),+ ],+ );+ },);if (actionResult?.action != null &&actionResult!.action == ButtonAction.error) {await showGenericErrorDialog(- context: bContext,+ context: context,error: actionResult.exception,);return false;@@ -516,6 +481,30 @@ class CollectionActions {return false;}+ Future<void> _runCollectionAction(+ BuildContext context,+ ButtonAction action,+ Future<void> Function() callback,+ ) async {+ try {+ await callback();+ if (context.mounted) {+ Navigator.of(context).pop(ButtonResult(action));+ }+ } catch (error) {+ if (context.mounted) {+ Navigator.of(+ context,+ ).pop(ButtonResult(ButtonAction.error, _toException(error)));+ }+ rethrow;+ }+ }++ Exception _toException(Object error) {+ return error is Exception ? error : Exception(error.toString());+ }+Future<void> trashCollectionKeepingPhotos(Collection collection,BuildContext bContext,