π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] clear user selection only if deletion was successful
Priyanshu Dangare9daa23c3c1e0
diff --git a/mobile/apps/photos/lib/ui/actions/file/file_actions.dart b/mobile/apps/photos/lib/ui/actions/file/file_actions.dartindex b128c8f75f..66ca201c0a 100644--- a/mobile/apps/photos/lib/ui/actions/file/file_actions.dart+++ b/mobile/apps/photos/lib/ui/actions/file/file_actions.dart@@ -6,19 +6,15 @@ import "package:flutter/material.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/details_sheet_event.dart";import "package:photos/generated/l10n.dart";-import "package:photos/models/button_result.dart";import "package:photos/models/file/extensions/file_props.dart";import 'package:photos/models/file/file.dart';import 'package:photos/models/file/file_type.dart';import "package:photos/service_locator.dart";import "package:photos/services/media_store_service.dart";import "package:photos/theme/ente_theme.dart";-import 'package:photos/ui/components/buttons/button_widget.dart'- show ButtonAction;import "package:photos/ui/notification/toast.dart";import 'package:photos/ui/viewer/file/file_details_widget.dart';import "package:photos/utils/delete_file_util.dart";-import "package:photos/utils/dialog_util.dart";import "package:photos/utils/panorama_util.dart";Future<void> showSingleFileDeleteSheet(@@ -36,7 +32,7 @@ Future<void> showSingleFileDeleteSheet(return;}if (Platform.isAndroid && await MediaStoreService.canManageMedia()) {- await showBottomSheetComponent<ButtonResult>(+ await showBottomSheetComponent<bool>(context: context,useRootNavigator: Platform.isIOS,builder: (_) => DeleteConfirmationSheet(@@ -72,7 +68,7 @@ Future<void> showSingleFileDeleteSheet(if (!isLocal && !isRemote) {throw AssertionError("Unexpected state");}- final actionResult = await showBottomSheetComponent<ButtonResult>(+ final didDelete = await showBottomSheetComponent<bool>(context: context,useRootNavigator: Platform.isIOS,builder: (_) => DeleteConfirmationSheet(@@ -101,16 +97,9 @@ Future<void> showSingleFileDeleteSheet(},),);- if (isLocal) {+ if (didDelete == true && isLocal) {await showMediaManagementHintSheet(context);}- if (actionResult?.action != null &&- actionResult!.action == ButtonAction.error) {- await showGenericErrorDialog(- context: context,- error: actionResult.exception,- );- }}Future<void> showDetailsSheet(BuildContext context, EnteFile file) async {diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dartindex 5095cad3da..03fb4edfa4 100644--- a/mobile/apps/photos/lib/utils/delete_file_util.dart+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart@@ -882,7 +882,7 @@ Future<void> showDeleteSheet(showShortToast(context, l10n.noDeviceThatCanBeDeleted);return;}- ButtonResult? actionResult;+ var didDelete = false;if (Platform.isAndroid && await MediaStoreService.canManageMedia()) {final hasVideos = localGalleryDeletableFiles.any((file) => file.fileType == FileType.video,@@ -890,34 +890,38 @@ Future<void> showDeleteSheet(final hasPhotos = localGalleryDeletableFiles.any((file) => file.fileType != FileType.video,);- actionResult = await showBottomSheetComponent<ButtonResult>(- context: context,- useRootNavigator: Platform.isIOS,- builder: (_) => DeleteConfirmationSheet(- count: localGalleryDeletableFiles.length,- hasPhotos: hasPhotos,- hasVideos: hasVideos,- isLocal: true,- isRemote: false,- onDeleteFromLocal: () async {- await deleteOnDeviceOnlyAction(context, localGalleryDeletableFiles);- },- onDeleteFromRemote: () async {- throw AssertionError("delete from remote in local gallery mode");- },- onDeleteFromBoth: () async {- throw AssertionError("delete from both in local gallery mode");- },- ),- );+ didDelete =+ await showBottomSheetComponent<bool>(+ context: context,+ useRootNavigator: Platform.isIOS,+ builder: (_) => DeleteConfirmationSheet(+ count: localGalleryDeletableFiles.length,+ hasPhotos: hasPhotos,+ hasVideos: hasVideos,+ isLocal: true,+ isRemote: false,+ onDeleteFromLocal: () async {+ await deleteOnDeviceOnlyAction(+ context,+ localGalleryDeletableFiles,+ );+ },+ onDeleteFromRemote: () async {+ throw AssertionError(+ "delete from remote in local gallery mode",+ );+ },+ onDeleteFromBoth: () async {+ throw AssertionError("delete from both in local gallery mode");+ },+ ),+ ) ==+ true;} else {await deleteOnDeviceOnlyAction(context, localGalleryDeletableFiles);+ didDelete = true;}- if (actionResult?.action == ButtonAction.error) {- await showGenericErrorDialog(- context: context,- error: actionResult!.exception,- );+ if (!didDelete) {return;}selectedFiles.unSelectAll(localGalleryDeletableFiles.toSet());@@ -951,7 +955,7 @@ Future<void> showDeleteSheet();}- final actionResult = await showBottomSheetComponent<ButtonResult>(+ final actionResult = await showBottomSheetComponent<bool>(context: context,useRootNavigator: Platform.isIOS,builder: (_) => DeleteConfirmationSheet(@@ -971,17 +975,11 @@ Future<void> showDeleteSheet(},),);- if (hasLocalFiles) {- await showMediaManagementHintSheet(context);- }- if (actionResult?.action != null &&- actionResult!.action == ButtonAction.error) {- await showGenericErrorDialog(- context: context,- error: actionResult.exception,- );- } else {+ if (actionResult == true) {selectedFiles.clearAll();+ if (hasLocalFiles) {+ await showMediaManagementHintSheet(context);+ }}}@@ -1130,13 +1128,17 @@ class DeleteConfirmationSheetState extends State<DeleteConfirmationSheet> {try {await callback();if (context.mounted) {- Navigator.of(context).pop();+ Navigator.of(context).pop(true);}} catch (error) {if (context.mounted) {- Navigator.of(- context,- ).pop(ButtonResult(ButtonAction.error, _toException(error)));+ await showGenericErrorDialog(+ context: context,+ error: _toException(error),+ );+ if (context.mounted) {+ Navigator.of(context).pop(false);+ }}rethrow;}