Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] new delete ux

Priyanshu Dangarefa9d2db9a750
diff --git a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/NativeChannels.kt b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/NativeChannels.kt
index e48e0016ee..27bb7abd3f 100644
--- a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/NativeChannels.kt
+++ b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/NativeChannels.kt
@@ -1,5 +1,7 @@
package io.ente.photos
+import android.os.Build
+import android.provider.MediaStore
import android.content.Context
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.BinaryMessenger
@@ -27,6 +29,7 @@ private class InstallSourceChannel(context: Context) {
call.argument<Boolean>("isSignUp") == true,
result,
)
+
"getPendingEvents" -> provider.getPendingEvents(result)
"markEventSent" -> provider.markEventSent(call.argument("event"), result)
else -> result.notImplemented()
@@ -37,3 +40,25 @@ private class InstallSourceChannel(context: Context) {
const val CHANNEL = "io.ente.photos/install_source"
}
}
+
+private class MediaStoreChannel(private val context: Context) {
+ fun register(messenger: BinaryMessenger) {
+ MethodChannel(messenger, CHANNEL).setMethodCallHandler(::handle)
+ }
+
+ private fun handle(call: MethodCall, result: MethodChannel.Result) {
+ when (call.method) {
+ "canManageMedia" -> result.success(canManageMedia())
+ else -> result.notImplemented()
+ }
+ }
+
+ private fun canManageMedia(): Boolean {
+ return MediaStore.canManageMedia(context)
+
+ }
+
+ private companion object {
+ const val CHANNEL = "io.ente.photos/media_store"
+ }
+}
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arb
index eedf817f78..0a8c450e0e 100644
--- a/mobile/apps/photos/lib/l10n/intl_en.arb
+++ b/mobile/apps/photos/lib/l10n/intl_en.arb
@@ -441,16 +441,77 @@
"uncategorized": "Uncategorized",
"videoSmallCase": "video",
"photoSmallCase": "photo",
+ "videosSmallCase": "videos",
+ "photosSmallCase": "photos",
+ "itemsSmallCase": "items",
"singleFileDeleteHighlight": "It will be deleted from all albums.",
- "singleFileInBothLocalAndRemote": "This {fileType} is in both Ente and your device.",
- "singleFileInRemoteOnly": "This {fileType} will be deleted from Ente.",
- "singleFileDeleteFromDevice": "This {fileType} will be deleted from your device.",
+ "singleFileInBothLocalAndRemote": "This {fileType} is saved on this device and backed up to Ente. It will be removed from all albums.",
+ "singleFileInRemoteOnly": "This {fileType} is backed up to Ente. It will be removed from all albums.",
+ "singleFileDeleteFromDevice": "This {fileType} is saved on this device only.",
+ "deleteFileQuestion": "Delete {fileType}?",
+ "@deleteFileQuestion": {
+ "placeholders": {
+ "fileType": {
+ "type": "String"
+ }
+ }
+ },
+ "deletePhotosQuestion": "{count, plural, one {Delete photo?} other {Delete {count} photos?}}",
+ "@deletePhotosQuestion": {
+ "placeholders": {
+ "count": {
+ "type": "int"
+ }
+ }
+ },
+ "deleteVideosQuestion": "{count, plural, one {Delete video?} other {Delete {count} videos?}}",
+ "@deleteVideosQuestion": {
+ "placeholders": {
+ "count": {
+ "type": "int"
+ }
+ }
+ },
+ "deleteItemsQuestion": "{count, plural, one {Delete item?} other {Delete {count} items?}}",
+ "@deleteItemsQuestion": {
+ "placeholders": {
+ "count": {
+ "type": "int"
+ }
+ }
+ },
+ "selectedFilesSavedOnDeviceOnly": "These {fileTypes} are saved on this device only.",
+ "@selectedFilesSavedOnDeviceOnly": {
+ "placeholders": {
+ "fileTypes": {
+ "type": "String"
+ }
+ }
+ },
+ "selectedFilesBackedUpToEnte": "These {fileTypes} are backed up to Ente. They will be removed from all albums.",
+ "@selectedFilesBackedUpToEnte": {
+ "placeholders": {
+ "fileTypes": {
+ "type": "String"
+ }
+ }
+ },
+ "someSelectedFilesBackedUpToEnte": "Some {fileTypes} are backed up to Ente. They will be removed from all albums.",
+ "@someSelectedFilesBackedUpToEnte": {
+ "placeholders": {
+ "fileTypes": {
+ "type": "String"
+ }
+ }
+ },
"deleteFromEnte": "Delete from Ente",
"yesDelete": "Yes, delete",
"movedToTrash": "Moved to trash",
"deleteFromDeviceQuestion": "Delete from device?",
"deleteFromDevice": "Delete from device",
"deleteFromBoth": "Delete from both",
+ "moreOptions": "More options",
+ "setAsDefault": "Set as default",
"newAlbum": "New album",
"albums": "Albums",
"ente": "Ente",
diff --git a/mobile/apps/photos/lib/settings/local_settings.dart b/mobile/apps/photos/lib/settings/local_settings.dart
index b54075a479..7eb526c663 100644
--- a/mobile/apps/photos/lib/settings/local_settings.dart
+++ b/mobile/apps/photos/lib/settings/local_settings.dart
@@ -37,6 +37,26 @@ enum LocalGalleryFlag {
localGallerySettingsBannerDismissed,
}
+enum DeletePreference {
+ DeleteFromBoth("delete_from_both"),
+ DeleteFromLocalOnly("delete_from_local_only"),
+ DeleteFromRemoteOnly("delete_from_remote_only");
+
+ const DeletePreference(this._serializedValue);
+
+ final String _serializedValue;
+
+ static DeletePreference? _fromSerializedValue(String? value) {
+ return switch (value) {
+ "delete_from_both" => DeleteFromBoth,
+ "delete_from_local_only" => DeleteFromLocalOnly,
+ "delete_from_remote_only" ||
+ "delete_from_ente_only" => DeleteFromRemoteOnly,
+ _ => null,
+ };
+ }
+}
+
class LocalSettings {
static const kCollectionSortPref = "collection_sort_pref";
static const kGalleryGroupType = "gallery_group_type";
@@ -87,6 +107,7 @@ class LocalSettings {
"ml_debug.semantic_search_exact_in_rust";
static const _kAppMode = "ls.app_mode";
static const _kShowLocalGalleryModeOption = "ls.show_offline_mode_option";
+ static const _kDeletePreference = "delete_preference";
static const _kWidgetHideTextFlags = "ls.widget_hide_text_flags";
@@ -601,4 +622,21 @@ class LocalSettings {
Future<void> setLocalGallerySettingsBannerDismissed(bool value) =>
_setFlag(LocalGalleryFlag.localGallerySettingsBannerDismissed, value);
+
+ DeletePreference? getDeletePreference() {
+ if (!_prefs.containsKey(_kDeletePreference)) {
+ return null;
+ }
+ return DeletePreference._fromSerializedValue(
+ _prefs.getString(_kDeletePreference),
+ );
+ }
+
+ Future<void> setDeletePreference(DeletePreference? preference) async {
+ if (preference == null) {
+ await _prefs.remove(_kDeletePreference);
+ } else {
+ await _prefs.setString(_kDeletePreference, preference._serializedValue);
+ }
+ }
}
diff --git a/mobile/apps/photos/lib/ui/actions/file/file_actions.dart b/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
index 4cbf8f0c5b..cf78b1779c 100644
--- a/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
+++ b/mobile/apps/photos/lib/ui/actions/file/file_actions.dart
@@ -27,105 +27,80 @@ Future<void> showSingleFileDeleteSheet(
bool isLocalOnlyContext = false,
}) async {
final l10n = AppLocalizations.of(context);
- final String fileType = file.fileType == FileType.video
- ? l10n.videoSmallCase
- : l10n.photoSmallCase;
- final bool isBothLocalAndRemote =
- file.uploadedFileID != null && file.localID != null;
- final bool isLocalOnly = file.uploadedFileID == null && file.localID != null;
- final bool isRemoteOnly = file.uploadedFileID != null && file.localID == null;
+ final bool isLocal = file.localID != null;
+ final bool isRemote = file.uploadedFileID != null;
if (isLocalGalleryMode) {
- if (file.localID == null) {
+ if (!isLocal) {
showShortToast(context, l10n.noDeviceThatCanBeDeleted);
return;
}
- final deletedFiles = await deleteFilesOnDeviceOnly(context, [file]);
- if (deletedFiles.isNotEmpty &&
- onFileRemoved != null &&
- (isLocalOnly || isLocalOnlyContext)) {
- onFileRemoved(file);
+ if (Platform.isAndroid) {
+ await showBottomSheetComponent<ButtonResult>(
+ context: context,
+ useRootNavigator: Platform.isIOS,
+ builder: (_) => DeleteConfirmationSheet(
+ count: 1,
+ hasPhotos: file.fileType != FileType.video,
+ hasVideos: file.fileType == FileType.video,
+ isLocal: isLocal,
+ isRemote: false,
+ onDeleteFromLocal: () async {
+ final deletedFiles = await deleteFilesOnDeviceOnly(context, [file]);
+ if (deletedFiles.isNotEmpty &&
+ ((isLocal && !isRemote) || isLocalOnlyContext)) {
+ onFileRemoved?.call(file);
+ }
+ },
+ onDeleteFromRemote: () async {
+ throw AssertionError("delete from remote in local gallery mode");
+ },
+ onDeleteFromBoth: () async {
+ throw AssertionError("delete from both in local gallery mode");
+ },
+ ),
+ );
+ } else {
+ final deletedFiles = await deleteFilesOnDeviceOnly(context, [file]);
+ if (deletedFiles.isNotEmpty &&
+ ((isLocal && !isRemote) || isLocalOnlyContext)) {
+ onFileRemoved?.call(file);
+ }
}
return;
}
- final String bodyHighlight = l10n.singleFileDeleteHighlight;
- late final String body;
- if (isBothLocalAndRemote) {
- body = l10n.singleFileInBothLocalAndRemote(fileType: fileType);
- } else if (isRemoteOnly) {
- body = l10n.singleFileInRemoteOnly(fileType: fileType);
- } else if (isLocalOnly) {
- body = l10n.singleFileDeleteFromDevice(fileType: fileType);
- } else {
+ if (!isLocal && !isRemote) {
throw AssertionError("Unexpected state");
}
-
final actionResult = await showBottomSheetComponent<ButtonResult>(
context: context,
useRootNavigator: Platform.isIOS,
- builder: (sheetContext) => BottomSheetComponent(
- title: l10n.areYouSure,
- message: isLocalOnly ? body : '$body\n$bodyHighlight',
- illustration: Image.asset("assets/warning-grey.png"),
- closeTooltip: l10n.close,
- closeResult: ButtonResult(ButtonAction.fourth),
- actions: [
- if (isBothLocalAndRemote || isRemoteOnly)
- ButtonComponent(
- label: isBothLocalAndRemote ? l10n.deleteFromEnte : l10n.yesDelete,
- variant: isBothLocalAndRemote
- ? ButtonComponentVariant.neutral
- : ButtonComponentVariant.critical,
- onTap: () => _runSingleFileDeleteAction(
- sheetContext,
- ButtonAction.first,
- () async {
- await deleteFilesFromRemoteOnly(context, [file]);
- showShortToast(context, l10n.movedToTrash);
- if (onFileRemoved != null &&
- (isRemoteOnly || !isLocalOnlyContext)) {
- onFileRemoved(file);
- }
- },
- ),
- ),
- if (isBothLocalAndRemote || isLocalOnly)
- ButtonComponent(
- label: isBothLocalAndRemote
- ? l10n.deleteFromDevice
- : l10n.yesDelete,
- variant: isBothLocalAndRemote
- ? ButtonComponentVariant.neutral
- : ButtonComponentVariant.critical,
- shouldSurfaceExecutionStates: false,
- onTap: () => _runSingleFileDeleteAction(
- sheetContext,
- ButtonAction.second,
- () async {
- final deletedFiles = await deleteFilesOnDeviceOnly(context, [
- file,
- ]);
- if (deletedFiles.isNotEmpty &&
- onFileRemoved != null &&
- (isLocalOnly || isLocalOnlyContext)) {
- onFileRemoved(file);
- }
- },
- ),
- ),
- if (isBothLocalAndRemote)
- ButtonComponent(
- label: l10n.deleteFromBoth,
- variant: ButtonComponentVariant.critical,
- onTap: () => _runSingleFileDeleteAction(
- sheetContext,
- ButtonAction.third,
- () => deleteFilesFromEverywhere(context, [file]),
- afterPop: () => onFileRemoved?.call(file),
- ),
- ),
- ],
+ builder: (_) => DeleteConfirmationSheet(
+ isLocal: isLocal,
+ isRemote: isRemote,
+ count: 1,
+ hasPhotos: file.fileType != FileType.video,
+ hasVideos: file.fileType == FileType.video,
+ onDeleteFromLocal: () async {
+ final deletedFiles = await deleteFilesOnDeviceOnly(context, [file]);
+ if (deletedFiles.isNotEmpty &&
+ ((isLocal && !isRemote) || isLocalOnlyContext)) {
+ onFileRemoved?.call(file);
+ }
+ },
+ onDeleteFromRemote: () async {
+ await deleteFilesFromRemoteOnly(context, [file]);
+ showShortToast(context, l10n.movedToTrash);
+ if (((isRemote && !isLocal) || !isLocalOnlyContext)) {
+ onFileRemoved?.call(file);
+ }
+ },
+ onDeleteFromBoth: () async {
+ await deleteFilesFromEverywhere(context, [file]);
+ onFileRemoved?.call(file);
+ },
),
);
+
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.error) {
await showGenericErrorDialog(
@@ -135,32 +110,6 @@ Future<void> showSingleFileDeleteSheet(
}
}
-Future<void> _runSingleFileDeleteAction(
- BuildContext context,
- ButtonAction action,
- Future<void> Function() onDelete, {
- FutureOr<void> Function()? afterPop,
-}) async {
- try {
- await onDelete();
- if (context.mounted) {
- Navigator.of(context).pop(ButtonResult(action));
- await afterPop?.call();
- }
- } 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> showDetailsSheet(BuildContext context, EnteFile file) async {
if (file.canEditMetaInfo && file.isPanorama() == null) {
guardedCheckPanorama(file).ignore();
diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dart
index 90dca3c180..007b78dd74 100644
--- a/mobile/apps/photos/lib/utils/delete_file_util.dart
+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart
@@ -18,6 +18,7 @@ import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
import "package:photos/models/button_result.dart";
import 'package:photos/models/file/file.dart';
+import 'package:photos/models/file/file_type.dart';
import "package:photos/models/files_split.dart";
import "package:photos/models/freeable_space_info.dart";
import 'package:photos/models/selected_files.dart';
@@ -26,6 +27,7 @@ import "package:photos/services/files_service.dart";
import "package:photos/services/sync/local_sync_service.dart";
import 'package:photos/services/sync/remote_sync_service.dart';
import 'package:photos/services/sync/sync_service.dart';
+import "package:photos/settings/local_settings.dart";
import 'package:photos/ui/common/linear_progress_dialog.dart';
import 'package:photos/ui/components/buttons/button_widget.dart'
show ButtonAction;
@@ -150,9 +152,10 @@ Future<void> deleteFilesFromRemoteOnly(
BuildContext context,
List<EnteFile> files,
) async {
+ final l10n = AppLocalizations.of(context);
files.removeWhere((element) => element.uploadedFileID == null);
if (files.isEmpty) {
- showToast(context, AppLocalizations.of(context).selectedFilesAreNotOnEnte);
+ showToast(context, l10n.selectedFilesAreNotOnEnte);
return;
}
_logger.info(
@@ -784,6 +787,7 @@ Future<void> showDeleteSheet(
Future<void> Function(BuildContext context, List<EnteFile> files)?
deleteFromEverywhereOverride,
}) async {
+ final l10n = AppLocalizations.of(context);
if (selectedFiles.files.length != filesSplit.count) {
throw AssertionError(
"Unexpected state, #{selectedFiles.files.length} != "
@@ -804,10 +808,7 @@ Future<void> showDeleteSheet(
deleteFromEverywhereOverride ?? deleteFilesFromEverywhere;
if (deletableFiles.isEmpty && filesSplit.ownedByOtherUsers.isNotEmpty) {
- showShortToast(
- context,
- AppLocalizations.of(context).cannotDeleteSharedFiles,
- );
+ showShortToast(context, l10n.cannotDeleteSharedFiles);
return;
}
if (isLocalGalleryMode) {
@@ -815,43 +816,62 @@ Future<void> showDeleteSheet(
.where((file) => file.localID != null)
.toList();
if (localGalleryDeletableFiles.isEmpty) {
- showShortToast(
- context,
- AppLocalizations.of(context).noDeviceThatCanBeDeleted,
- );
+ showShortToast(context, l10n.noDeviceThatCanBeDeleted);
return;
}
- await deleteOnDeviceOnlyAction(context, localGalleryDeletableFiles);
+ if (Platform.isAndroid) {
+ final hasVideos = localGalleryDeletableFiles.any(
+ (file) => file.fileType == FileType.video,
+ );
+ final hasPhotos = localGalleryDeletableFiles.any(
+ (file) => file.fileType != FileType.video,
+ );
+ 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");
+ },
+ ),
+ );
+ } else {
+ await deleteOnDeviceOnlyAction(context, localGalleryDeletableFiles);
+ }
selectedFiles.unSelectAll(localGalleryDeletableFiles.toSet());
return;
}
- final containsUploadedFile = deletableFiles.any((f) => f.isUploaded);
- final containsLocalFile = deletableFiles.any((f) => f.localID != null);
+ final hasRemoteFiles = deletableFiles.any((f) => f.isUploaded);
+ final hasLocalFiles = deletableFiles.any((f) => f.localID != null);
+ final hasVideos = deletableFiles.any(
+ (file) => file.fileType == FileType.video,
+ );
+ final hasPhotos = deletableFiles.any(
+ (file) => file.fileType != FileType.video,
+ );
- final bool isBothLocalAndRemote = containsUploadedFile && containsLocalFile;
- final bool isLocalOnly = !containsUploadedFile;
- final bool isRemoteOnly = !containsLocalFile;
- late final String body;
- late final String? bodyHighlight;
- if (isBothLocalAndRemote) {
- body = AppLocalizations.of(context).someItemsAreInBothEnteAndYourDevice;
- bodyHighlight = AppLocalizations.of(context).theyWillBeDeletedFromAllAlbums;
- } else if (isRemoteOnly) {
- body = AppLocalizations.of(
- context,
- ).selectedItemsWillBeDeletedFromAllAlbumsAndMoved;
- bodyHighlight = null;
- } else if (isLocalOnly) {
- body = AppLocalizations.of(context).theseItemsWillBeDeletedFromYourDevice;
- bodyHighlight = null;
- } else {
+ final bool isBothLocalAndRemote = hasRemoteFiles && hasLocalFiles;
+ final bool isLocalOnly = !hasRemoteFiles;
+ final bool isRemoteOnly = !hasLocalFiles;
+ if (!isBothLocalAndRemote && !isRemoteOnly && !isLocalOnly) {
throw AssertionError("Unexpected state");
}
Future<void> deleteFromEnte() async {
await deleteFromRemoteOnlyAction(context, deletableFiles).then(
(value) {
- showShortToast(context, AppLocalizations.of(context).movedToTrash);
+ showShortToast(context, l10n.movedToTrash);
},
onError: (e, s) {
showGenericErrorDialog(context: context, error: e);
@@ -859,46 +879,25 @@ Future<void> showDeleteSheet(
);
}
- if (isBothLocalAndRemote) {
- final actionResult = await _showMixedDeleteTargetSheet(
- context: context,
- body: body,
- bodyHighlight: bodyHighlight!,
- onDelete: (target) async {
- switch (target) {
- case _MixedDeleteTarget.ente:
- await deleteFromEnte();
- case _MixedDeleteTarget.device:
- await deleteOnDeviceOnlyAction(context, deletableFiles);
- case _MixedDeleteTarget.both:
- await deleteFromEverywhereAction(context, deletableFiles);
- }
- },
- );
- if (actionResult?.action != null &&
- actionResult!.action == ButtonAction.error) {
- await showGenericErrorDialog(
- context: context,
- error: actionResult.exception,
- );
- } else {
- selectedFiles.clearAll();
- }
- return;
- }
-
- final actionResult = await _showSingleDeleteConfirmationSheet(
+ final actionResult = await showBottomSheetComponent<ButtonResult>(
context: context,
- body: body,
- action: isRemoteOnly ? ButtonAction.first : ButtonAction.second,
- shouldSurfaceExecutionStates: isRemoteOnly,
- onDelete: () async {
- if (isRemoteOnly) {
- await deleteFromEnte();
- } else {
+ useRootNavigator: Platform.isIOS,
+ builder: (_) => DeleteConfirmationSheet(
+ isLocal: hasLocalFiles,
+ isRemote: hasRemoteFiles,
+ count: deletableFiles.length,
+ hasPhotos: hasPhotos,
+ hasVideos: hasVideos,
+ onDeleteFromLocal: () async {
await deleteOnDeviceOnlyAction(context, deletableFiles);
- }
- },
+ },
+ onDeleteFromRemote: () async {
+ await deleteFromEnte();
+ },
+ onDeleteFromBoth: () async {
+ await deleteFromEverywhereAction(context, deletableFiles);
+ },
+ ),
);
if (actionResult?.action != null &&
actionResult!.action == ButtonAction.error) {
@@ -911,127 +910,6 @@ Future<void> showDeleteSheet(
}
}
-enum _MixedDeleteTarget { ente, device, both }
-
-class _MixedDeleteTargetOption {
- const _MixedDeleteTargetOption({
- required this.target,
- required this.action,
- required this.label,
- });
-
- final _MixedDeleteTarget target;
- final ButtonAction action;
- final String label;
-}
-
-Future<ButtonResult?> _showMixedDeleteTargetSheet({
- required BuildContext context,
- required String body,
- required String bodyHighlight,
- required Future<void> Function(_MixedDeleteTarget target) onDelete,
-}) {
- final l10n = AppLocalizations.of(context);
- return showBottomSheetComponent<ButtonResult>(
- context: context,
- useRootNavigator: Platform.isIOS,
- builder: (_) => _MixedDeleteTargetSheet(
- title: l10n.areYouSure,
- body: body,
- bodyHighlight: bodyHighlight,
- closeTooltip: l10n.close,
- options: [
- _MixedDeleteTargetOption(
- target: _MixedDeleteTarget.ente,
- action: ButtonAction.first,
- label: l10n.deleteFromEnte,
- ),
- _MixedDeleteTargetOption(
- target: _MixedDeleteTarget.device,
- action: ButtonAction.second,
- label: l10n.deleteFromDevice,
- ),
- _MixedDeleteTargetOption(
- target: _MixedDeleteTarget.both,
- action: ButtonAction.third,
- label: l10n.deleteFromBoth,
- ),
- ],
- onDelete: onDelete,
- ),
- );
-}
-
-Future<ButtonResult?> _showSingleDeleteConfirmationSheet({
- required BuildContext context,
- required String body,
- required ButtonAction action,
- required bool shouldSurfaceExecutionStates,
- required Future<void> Function() onDelete,
-}) {
- final l10n = AppLocalizations.of(context);
- return showBottomSheetComponent<ButtonResult>(
- context: context,
- useRootNavigator: Platform.isIOS,
- builder: (sheetContext) => BottomSheetComponent(
- title: l10n.areYouSure,
- message: body,
- illustration: Image.asset("assets/warning-grey.png"),
- closeTooltip: l10n.close,
- closeResult: ButtonResult(ButtonAction.fourth),
- actions: [
- ButtonComponent(
- label: l10n.yesDelete,
- variant: ButtonComponentVariant.critical,
- shouldSurfaceExecutionStates: shouldSurfaceExecutionStates,
- onTap: () => _runDeleteAction(sheetContext, action, onDelete),
- ),
- ],
- ),
- );
-}
-
-class _MixedDeleteTargetSheet extends StatelessWidget {
- const _MixedDeleteTargetSheet({
- required this.title,
- required this.body,
- required this.bodyHighlight,
- required this.closeTooltip,
- required this.options,
- required this.onDelete,
- });
-
- final String title;
- final String body;
- final String bodyHighlight;
- final String closeTooltip;
- final List<_MixedDeleteTargetOption> options;
- final Future<void> Function(_MixedDeleteTarget target) onDelete;
-
- @override
- Widget build(BuildContext context) {
- return BottomSheetComponent(
- title: title,
- message: '$body\n$bodyHighlight',
- illustration: Image.asset("assets/warning-grey.png"),
- closeTooltip: closeTooltip,
- actions: [
- for (final option in options)
- ButtonComponent(
- key: ValueKey('mixedDeleteTarget.${option.target.name}'),
- label: option.label,
- variant: _variantFor(option.target),
- onTap: () => _runDeleteAction(
- context,
- option.action,
- () => onDelete(option.target),
- ),
- ),
- ],
- );
- }
-}
-
Future<void> _runDeleteAction(
BuildContext context,
ButtonAction action,
@@ -1051,14 +929,243 @@ Future<void> _runDeleteAction(
}
}
-ButtonComponentVariant _variantFor(_MixedDeleteTarget target) {
- return switch (target) {
- _MixedDeleteTarget.ente ||
- _MixedDeleteTarget.device => ButtonComponentVariant.neutral,
- _MixedDeleteTarget.both => ButtonComponentVariant.critical,
- };
-}
-
Exception _toException(Object error) {
return error is Exception ? error : Exception(error.toString());
}
+
+class _MoreOptionsButton extends StatefulWidget {
+ const _MoreOptionsButton({required this.onTap});
+
+ final VoidCallback onTap;
+
+ @override
+ State<_MoreOptionsButton> createState() => _MoreOptionsButtonState();
+}
+
+// TODO: Replace this component once ente_components has a ghost button variant.
+class _MoreOptionsButtonState extends State<_MoreOptionsButton> {
+ var _isPressed = false;
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = AppLocalizations.of(context);
+ final foreground = context.componentColors.textLight;
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTapDown: (_) => setState(() => _isPressed = true),
+ onTapUp: (_) => setState(() => _isPressed = false),
+ onTapCancel: () => setState(() => _isPressed = false),
+ onTap: widget.onTap,
+ child: AnimatedScale(
+ scale: _isPressed ? 0.98 : 1,
+ duration: const Duration(milliseconds: 120),
+ curve: Curves.easeOutCubic,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Text(
+ l10n.moreOptions,
+ overflow: TextOverflow.ellipsis,
+ maxLines: 1,
+ style: TextStyles.body.copyWith(color: foreground),
+ ),
+ const SizedBox(width: Spacing.xs),
+ Icon(
+ Icons.keyboard_arrow_up,
+ color: foreground,
+ size: IconSizes.small,
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class DeleteConfirmationSheet extends StatefulWidget {
+ final bool isLocal;
+ final bool isRemote;
+ final int count;
+ final bool hasPhotos;
+ final bool hasVideos;
+ final Future<void> Function() onDeleteFromLocal;
+ final Future<void> Function() onDeleteFromRemote;
+ final Future<void> Function() onDeleteFromBoth;
+
+ const DeleteConfirmationSheet({
+ super.key,
+ required this.isLocal,
+ required this.isRemote,
+ required this.count,
+ required this.hasPhotos,
+ required this.hasVideos,
+ required this.onDeleteFromLocal,
+ required this.onDeleteFromRemote,
+ required this.onDeleteFromBoth,
+ });
+
+ @override
+ State<StatefulWidget> createState() {
+ return DeleteConfirmationSheetState();
+ }
+}
+
+class DeleteConfirmationSheetState extends State<DeleteConfirmationSheet> {
+ var _isMoreOptionsShown = false;
+ var _isSetAsDefaultSelected = false;
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = AppLocalizations.of(context);
+ // Dialog copy
+ final title = widget.hasPhotos && widget.hasVideos
+ ? l10n.deleteItemsQuestion(count: widget.count)
+ : widget.hasVideos
+ ? l10n.deleteVideosQuestion(count: widget.count)
+ : l10n.deletePhotosQuestion(count: widget.count);
+ final fileType = widget.hasVideos
+ ? l10n.videoSmallCase
+ : l10n.photoSmallCase;
+ final fileTypes = widget.hasPhotos && widget.hasVideos
+ ? l10n.itemsSmallCase
+ : widget.hasVideos
+ ? l10n.videosSmallCase
+ : l10n.photosSmallCase;
+ final body = widget.count == 1 && widget.isLocal && widget.isRemote
+ ? l10n.singleFileInBothLocalAndRemote(fileType: fileType)
+ : widget.count == 1 && widget.isRemote
+ ? l10n.singleFileInRemoteOnly(fileType: fileType)
+ : widget.count == 1 && widget.isLocal
+ ? l10n.singleFileDeleteFromDevice(fileType: fileType)
+ : widget.isLocal && widget.isRemote
+ ? l10n.someSelectedFilesBackedUpToEnte(fileTypes: fileTypes)
+ : widget.isRemote
+ ? l10n.selectedFilesBackedUpToEnte(fileTypes: fileTypes)
+ : l10n.selectedFilesSavedOnDeviceOnly(fileTypes: fileTypes);
+ // Default delete target
+ final deletePreference = (widget.isLocal && !widget.isRemote)
+ ? DeletePreference.DeleteFromLocalOnly
+ : (widget.isRemote && !widget.isLocal)
+ ? DeletePreference.DeleteFromRemoteOnly
+ : localSettings.getDeletePreference() ??
+ DeletePreference.DeleteFromBoth;
+ // Shared delete runner
+ void onDelete(Future<void> Function() callback) async {
+ try {
+ await callback();
+ if (context.mounted) {
+ Navigator.of(context).pop();
+ }
+ } catch (error) {
+ if (context.mounted) {
+ Navigator.of(
+ context,
+ ).pop(ButtonResult(ButtonAction.error, _toException(error)));
+ }
+ rethrow;
+ }
+ }
+
+ return BottomSheetComponent(
+ title: title,
+ illustration: Image.asset("assets/warning-red.png"),
+ closeTooltip: l10n.close,
+ content: Text(
+ body,
+ textAlign: TextAlign.center,
+ style: TextStyles.body.copyWith(
+ color: context.componentColors.textLight,
+ ),
+ ),
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ contentSpacing: Spacing.sm,
+ actionsTopSpacing: Spacing.xxl,
+ actions: [
+ // Expanded target choices
+ if (_isMoreOptionsShown) ...[
+ ButtonComponent(
+ label: l10n.deleteFromDevice,
+ variant: ButtonComponentVariant.secondary,
+ onTap: () async {
+ if (_isSetAsDefaultSelected) {
+ await localSettings.setDeletePreference(.DeleteFromLocalOnly);
+ }
+ onDelete(widget.onDeleteFromLocal);
+ },
+ ),
+ ButtonComponent(
+ label: l10n.deleteFromEnte,
+ variant: ButtonComponentVariant.secondary,
+ onTap: () async {
+ if (_isSetAsDefaultSelected) {
+ await localSettings.setDeletePreference(.DeleteFromRemoteOnly);
+ }
+ onDelete(widget.onDeleteFromRemote);
+ },
+ ),
+ ButtonComponent(
+ label: l10n.deleteFromBoth,
+ variant: ButtonComponentVariant.critical,
+ onTap: () async {
+ if (_isSetAsDefaultSelected) {
+ await localSettings.setDeletePreference(.DeleteFromBoth);
+ }
+ onDelete(widget.onDeleteFromBoth);
+ },
+ ),
+ ] else ...[
+ // Preferred target shortcut
+ ButtonComponent(
+ key: const ValueKey('DeleteConfirmationSheet.default'),
+ label: switch (deletePreference) {
+ DeletePreference.DeleteFromRemoteOnly => l10n.deleteFromEnte,
+ DeletePreference.DeleteFromLocalOnly => l10n.deleteFromDevice,
+ DeletePreference.DeleteFromBoth => l10n.deleteFromBoth,
+ },
+ variant: ButtonComponentVariant.critical,
+ onTap: () async {
+ switch (deletePreference) {
+ case DeletePreference.DeleteFromRemoteOnly:
+ onDelete(widget.onDeleteFromRemote);
+ case DeletePreference.DeleteFromLocalOnly:
+ onDelete(widget.onDeleteFromLocal);
+ case DeletePreference.DeleteFromBoth:
+ onDelete(widget.onDeleteFromBoth);
+ }
+ },
+ ),
+ ],
+ // Preference control
+ if (widget.isLocal && widget.isRemote)
+ ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: 48),
+ child: _isMoreOptionsShown
+ ? LabeledControlComponent(
+ control: CheckboxComponent(
+ selected: _isSetAsDefaultSelected,
+ onChanged: (value) {
+ setState(() {
+ _isSetAsDefaultSelected = value;
+ });
+ },
+ ),
+ label: l10n.setAsDefault,
+ onTap: () {
+ setState(() {
+ _isSetAsDefaultSelected = !_isSetAsDefaultSelected;
+ });
+ },
+ )
+ : _MoreOptionsButton(
+ onTap: () {
+ setState(() {
+ _isMoreOptionsShown = true;
+ });
+ },
+ ),
+ ),
+ ],
+ );
+ }
+}
diff --git a/mobile/packages/ente_components/lib/components/selection_controls/labeled_control_component.dart b/mobile/packages/ente_components/lib/components/selection_controls/labeled_control_component.dart
index 559aaed53d..28d67b2b96 100644
--- a/mobile/packages/ente_components/lib/components/selection_controls/labeled_control_component.dart
+++ b/mobile/packages/ente_components/lib/components/selection_controls/labeled_control_component.dart
@@ -9,35 +9,48 @@ class LabeledControlComponent extends StatelessWidget {
required this.control,
required this.label,
this.subtitle,
+ this.foreground,
+ this.onTap,
});
final Widget control;
final String label;
final String? subtitle;
+ /// Overrides the label and subtitle color.
+ final Color? foreground;
+
+ /// Called when the label area is tapped.
+ final VoidCallback? onTap;
+
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
+ final labelContent = Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ label,
+ style: TextStyles.body.copyWith(color: foreground ?? colors.textBase),
+ ),
+ if (subtitle != null)
+ Text(
+ subtitle!,
+ style: TextStyles.mini.copyWith(
+ color: foreground ?? colors.textLight,
+ ),
+ ),
+ ],
+ );
+ final tappableLabel = InkWell(onTap: onTap, child: labelContent);
return Row(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
children: [
control,
const SizedBox(width: Spacing.md),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- label,
- style: TextStyles.body.copyWith(color: colors.textBase),
- ),
- if (subtitle != null)
- Text(
- subtitle!,
- style: TextStyles.mini.copyWith(color: colors.textLight),
- ),
- ],
- ),
- ),
+ tappableLabel,
],
);
}