Modified uses of ActionSheets to work with ButtonWidget

This commit is contained in:
ashilkn 2023-02-09 18:48:01 +05:30
parent ee3d152083
commit dd49b7913d
10 changed files with 69 additions and 51 deletions

View file

@ -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();

View file

@ -54,7 +54,7 @@ class CollectionActions {
}
Future<bool> 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;
}
/*

View file

@ -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<ButtonAction?> showActionSheet({
Future<ButtonResult?> showActionSheet({
required BuildContext context,
required List<ButtonWidget> buttons,
ActionSheetType actionSheetType = ActionSheetType.defaultActionSheet,

View file

@ -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(

View file

@ -524,7 +524,8 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
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));
}
}

View file

@ -428,15 +428,18 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
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(() => {});
}

View file

@ -431,14 +431,15 @@ class FadingAppBarState extends State<FadingAppBar> {
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);
}
}

View file

@ -139,7 +139,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
Future<dynamic> _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<GalleryAppBarWidget> {
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();
}
}

View file

@ -247,7 +247,7 @@ Future<void> deleteFilesOnDeviceOnly(
Future<bool> deleteFromTrash(BuildContext context, List<File> 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<bool> deleteFromTrash(BuildContext context, List<File> 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<bool> emptyTrash(BuildContext context) async {
final result = await showChoiceActionSheet(
final actionResult = await showChoiceActionSheet(
context,
title: "Empty trash?",
body:
@ -298,11 +299,11 @@ Future<bool> 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<List<String>> _tryDeleteSharedMediaFiles(List<String> localIDs) {
}
Future<bool> shouldProceedWithDeletion(BuildContext context) async {
final choice = await showChoiceActionSheet(
final actionResult = await showChoiceActionSheet(
context,
title: "Permanently delete from device?",
body:
@ -475,10 +476,10 @@ Future<bool> 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<void> 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<void> 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();

View file

@ -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<ButtonAction?> showChoiceDialog(
}
///Will return null if dismissed by tapping outside
Future<ButtonAction?> showChoiceActionSheet(
Future<ButtonResult?> showChoiceActionSheet(
BuildContext context, {
required String title,
String? body,