From dd49b7913d01c8015b26655a5fc1e15d403ee72c Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 9 Feb 2023 18:48:01 +0530 Subject: [PATCH] Modified uses of ActionSheets to work with ButtonWidget --- .../collection/collection_file_actions.dart | 3 +- .../collection_sharing_actions.dart | 30 +++++++------- lib/ui/components/action_sheet_widget.dart | 3 +- lib/ui/sharing/manage_album_participant.dart | 6 +-- lib/ui/tools/editor/image_editor_page.dart | 3 +- .../file_selection_actions_widget.dart | 19 +++++---- lib/ui/viewer/file/fading_app_bar.dart | 5 ++- .../gallery/gallery_app_bar_widget.dart | 8 ++-- lib/utils/delete_file_util.dart | 40 +++++++++++-------- lib/utils/dialog_util.dart | 3 +- 10 files changed, 69 insertions(+), 51 deletions(-) diff --git a/lib/ui/actions/collection/collection_file_actions.dart b/lib/ui/actions/collection/collection_file_actions.dart index 846f56744..cc0353508 100644 --- a/lib/ui/actions/collection/collection_file_actions.dart +++ b/lib/ui/actions/collection/collection_file_actions.dart @@ -57,7 +57,8 @@ extension CollectionFileActions on CollectionActions { : "Selected items will be removed from this album", actionSheetType: ActionSheetType.defaultActionSheet, ); - if (actionResult != null && actionResult == ButtonAction.error) { + if (actionResult?.action != null && + actionResult!.action == ButtonAction.error) { showGenericErrorDialog(context: bContext); } else { selectedFiles.clearAll(); diff --git a/lib/ui/actions/collection/collection_sharing_actions.dart b/lib/ui/actions/collection/collection_sharing_actions.dart index b2a92437d..436026331 100644 --- a/lib/ui/actions/collection/collection_sharing_actions.dart +++ b/lib/ui/actions/collection/collection_sharing_actions.dart @@ -54,7 +54,7 @@ class CollectionActions { } Future disableUrl(BuildContext context, Collection collection) async { - final ButtonAction? result = await showActionSheet( + final actionResult = await showActionSheet( context: context, buttons: [ ButtonWidget( @@ -80,11 +80,11 @@ class CollectionActions { body: 'This will remove the public link for accessing "${collection.name}".', ); - if (result != null) { - if (result == ButtonAction.error) { + if (actionResult?.action != null) { + if (actionResult!.action == ButtonAction.error) { showGenericErrorDialog(context: context); } - return result == ButtonAction.first; + return actionResult.action == ButtonAction.first; } else { return false; } @@ -140,7 +140,7 @@ class CollectionActions { Collection collection, User user, ) async { - final ButtonAction? result = await showActionSheet( + final actionResult = await showActionSheet( context: context, buttons: [ ButtonWidget( @@ -168,11 +168,11 @@ class CollectionActions { body: '${user.email} will be removed from this shared album\n\nAny ' 'photos added by them will also be removed from the album', ); - if (result != null) { - if (result == ButtonAction.error) { + if (actionResult?.action != null) { + if (actionResult!.action == ButtonAction.error) { showGenericErrorDialog(context: context); } - return result == ButtonAction.first; + return actionResult.action == ButtonAction.first; } return false; } @@ -346,13 +346,14 @@ class CollectionActions { ), actionSheetType: ActionSheetType.defaultActionSheet, ); - if (actionResult != null && actionResult == ButtonAction.error) { + if (actionResult?.action != null && + actionResult!.action == ButtonAction.error) { showGenericErrorDialog(context: bContext); return false; } - if (actionResult != null && - (actionResult == ButtonAction.first || - actionResult == ButtonAction.second)) { + if ((actionResult?.action != null) && + (actionResult!.action == ButtonAction.first || + actionResult.action == ButtonAction.second)) { return true; } return false; @@ -364,7 +365,7 @@ class CollectionActions { BuildContext context, Collection collection, ) async { - final ButtonAction? result = await showChoiceActionSheet( + final actionResult = await showChoiceActionSheet( context, isCritical: true, title: "Delete shared album?", @@ -372,7 +373,8 @@ class CollectionActions { body: "The album will be deleted for everyone\n\nYou will lose access to " "shared photos in this album that are owned by others", ); - return result != null && result == ButtonAction.first; + return actionResult?.action != null && + actionResult!.action == ButtonAction.first; } /* diff --git a/lib/ui/components/action_sheet_widget.dart b/lib/ui/components/action_sheet_widget.dart index b20aea7bb..c7703f858 100644 --- a/lib/ui/components/action_sheet_widget.dart +++ b/lib/ui/components/action_sheet_widget.dart @@ -3,6 +3,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; import 'package:photos/core/constants.dart'; +import "package:photos/models/search/button_result.dart"; import 'package:photos/theme/colors.dart'; import 'package:photos/theme/effects.dart'; import 'package:photos/theme/ente_theme.dart'; @@ -15,7 +16,7 @@ enum ActionSheetType { } ///Returns null if dismissed -Future showActionSheet({ +Future showActionSheet({ required BuildContext context, required List buttons, ActionSheetType actionSheetType = ActionSheetType.defaultActionSheet, diff --git a/lib/ui/sharing/manage_album_participant.dart b/lib/ui/sharing/manage_album_participant.dart index e3c8340a9..f3f0b49f7 100644 --- a/lib/ui/sharing/manage_album_participant.dart +++ b/lib/ui/sharing/manage_album_participant.dart @@ -108,7 +108,7 @@ class _ManageIndividualParticipantState onTap: widget.user.isViewer ? null : () async { - final ButtonAction? result = await showChoiceActionSheet( + final actionResult = await showChoiceActionSheet( context, title: "Change permissions?", firstButtonLabel: "Yes, convert to viewer", @@ -116,8 +116,8 @@ class _ManageIndividualParticipantState '${widget.user.email} will not be able to add more photos to this album\n\nThey will still be able to remove existing photos added by them', isCritical: true, ); - if (result != null) { - if (result == ButtonAction.first) { + if (actionResult?.action != null) { + if (actionResult!.action == ButtonAction.first) { try { isConvertToViewSuccess = await collectionActions.addEmailToCollection( diff --git a/lib/ui/tools/editor/image_editor_page.dart b/lib/ui/tools/editor/image_editor_page.dart index 345f5da8d..c5ad847a3 100644 --- a/lib/ui/tools/editor/image_editor_page.dart +++ b/lib/ui/tools/editor/image_editor_page.dart @@ -524,7 +524,8 @@ class _ImageEditorPageState extends State { body: "Do you want to discard the edits you have made?", actionSheetType: ActionSheetType.defaultActionSheet, ); - if (actionResult != null && actionResult == ButtonAction.first) { + if (actionResult?.action != null && + actionResult!.action == ButtonAction.first) { replacePage(context, DetailPage(widget.detailPageConfig)); } } diff --git a/lib/ui/viewer/actions/file_selection_actions_widget.dart b/lib/ui/viewer/actions/file_selection_actions_widget.dart index 2f2c65a48..ef5a69451 100644 --- a/lib/ui/viewer/actions/file_selection_actions_widget.dart +++ b/lib/ui/viewer/actions/file_selection_actions_widget.dart @@ -428,15 +428,18 @@ class _FileSelectionActionWidgetState extends State { body: "You can manage your links in the share tab.", actionSheetType: ActionSheetType.defaultActionSheet, ); - if (actionResult != null && actionResult == ButtonAction.first) { - await _copyLink(); - } - if (actionResult != null && actionResult == ButtonAction.second) { - routeToPage( - context, - ManageSharedLinkWidget(collection: _cachedCollectionForSharedLink), - ); + if (actionResult?.action != null) { + if (actionResult!.action == ButtonAction.first) { + await _copyLink(); + } + if (actionResult.action == ButtonAction.second) { + routeToPage( + context, + ManageSharedLinkWidget(collection: _cachedCollectionForSharedLink), + ); + } } + if (mounted) { setState(() => {}); } diff --git a/lib/ui/viewer/file/fading_app_bar.dart b/lib/ui/viewer/file/fading_app_bar.dart index 318ef3135..a9d674970 100644 --- a/lib/ui/viewer/file/fading_app_bar.dart +++ b/lib/ui/viewer/file/fading_app_bar.dart @@ -431,14 +431,15 @@ class FadingAppBarState extends State { isInAlert: true, ), ); - final ButtonAction? result = await showActionSheet( + final actionResult = await showActionSheet( context: context, buttons: buttons, actionSheetType: ActionSheetType.defaultActionSheet, body: body, bodyHighlight: bodyHighlight, ); - if (result != null && result == ButtonAction.error) { + if (actionResult?.action != null && + actionResult!.action == ButtonAction.error) { showGenericErrorDialog(context: context); } } diff --git a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart index 8d723222f..846f3360e 100644 --- a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart +++ b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart @@ -139,7 +139,7 @@ class _GalleryAppBarWidgetState extends State { } Future _leaveAlbum(BuildContext context) async { - final ButtonAction? result = await showActionSheet( + final actionResult = await showActionSheet( context: context, buttons: [ ButtonWidget( @@ -164,10 +164,10 @@ class _GalleryAppBarWidgetState extends State { title: "Leave shared album?", body: "Photos added by you will be removed from the album", ); - if (result != null && mounted) { - if (result == ButtonAction.error) { + if (actionResult?.action != null && mounted) { + if (actionResult!.action == ButtonAction.error) { showGenericErrorDialog(context: context); - } else if (result == ButtonAction.first) { + } else if (actionResult.action == ButtonAction.first) { Navigator.of(context).pop(); } } diff --git a/lib/utils/delete_file_util.dart b/lib/utils/delete_file_util.dart index cf86f1aa0..077af27d0 100644 --- a/lib/utils/delete_file_util.dart +++ b/lib/utils/delete_file_util.dart @@ -247,7 +247,7 @@ Future deleteFilesOnDeviceOnly( Future deleteFromTrash(BuildContext context, List files) async { bool didDeletionStart = false; - final result = await showChoiceActionSheet( + final actionResult = await showChoiceActionSheet( context, title: "Permanently delete?", body: "This action cannot be undone", @@ -270,19 +270,20 @@ Future deleteFromTrash(BuildContext context, List files) async { } }, ); - if (result == ButtonAction.error) { + + if (actionResult?.action == null || + actionResult!.action == ButtonAction.cancel) { + return didDeletionStart ? true : false; + } else if (actionResult.action == ButtonAction.error) { await showGenericErrorDialog(context: context); return false; - } - if (result == null || result == ButtonAction.cancel) { - return didDeletionStart ? true : false; } else { return true; } } Future emptyTrash(BuildContext context) async { - final result = await showChoiceActionSheet( + final actionResult = await showChoiceActionSheet( context, title: "Empty trash?", body: @@ -298,11 +299,11 @@ Future emptyTrash(BuildContext context) async { } }, ); - if (result == ButtonAction.error) { - await showGenericErrorDialog(context: context); + if (actionResult?.action == null || + actionResult!.action == ButtonAction.cancel) { return false; - } - if (result == null || result == ButtonAction.cancel) { + } else if (actionResult.action == ButtonAction.error) { + await showGenericErrorDialog(context: context); return false; } else { return true; @@ -467,7 +468,7 @@ Future> _tryDeleteSharedMediaFiles(List localIDs) { } Future shouldProceedWithDeletion(BuildContext context) async { - final choice = await showChoiceActionSheet( + final actionResult = await showChoiceActionSheet( context, title: "Permanently delete from device?", body: @@ -475,10 +476,10 @@ Future shouldProceedWithDeletion(BuildContext context) async { firstButtonLabel: "Delete", isCritical: true, ); - if (choice == null) { + if (actionResult?.action == null) { return false; } else { - return choice == ButtonAction.first; + return actionResult!.action == ButtonAction.first; } } @@ -528,8 +529,14 @@ Future showDeleteSheet( await deleteFilesFromRemoteOnly( context, selectedFiles.files.toList(), + ).then( + (value) { + showShortToast(context, "Moved to trash"); + }, + onError: (e, s) { + showGenericErrorDialog(context: context); + }, ); - showShortToast(context, "Moved to trash"); }, ), ); @@ -581,14 +588,15 @@ Future showDeleteSheet( isInAlert: true, ), ); - final ButtonAction? result = await showActionSheet( + final actionResult = await showActionSheet( context: context, buttons: buttons, actionSheetType: ActionSheetType.defaultActionSheet, body: body, bodyHighlight: bodyHighlight, ); - if (result != null && result == ButtonAction.error) { + if (actionResult?.action != null && + actionResult!.action == ButtonAction.error) { showGenericErrorDialog(context: context); } else { selectedFiles.clearAll(); diff --git a/lib/utils/dialog_util.dart b/lib/utils/dialog_util.dart index d94764de6..a624b2d73 100644 --- a/lib/utils/dialog_util.dart +++ b/lib/utils/dialog_util.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:confetti/confetti.dart'; import 'package:flutter/material.dart'; import 'package:photos/core/constants.dart'; +import "package:photos/models/search/button_result.dart"; import 'package:photos/ui/common/loading_widget.dart'; import 'package:photos/ui/common/progress_dialog.dart'; import 'package:photos/ui/components/action_sheet_widget.dart'; @@ -135,7 +136,7 @@ Future showChoiceDialog( } ///Will return null if dismissed by tapping outside -Future showChoiceActionSheet( +Future showChoiceActionSheet( BuildContext context, { required String title, String? body,