π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Skip local files in download actions with clear toasts
ashilkn91ac7cb30c8d
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dartindex 2af40bdbfb..04ee8c2c60 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart@@ -45,6 +45,7 @@ import "package:photos/ui/viewer/location/update_location_data_widget.dart";import "package:photos/ui/viewer/people/add_files_to_person_page.dart";import 'package:photos/utils/delete_file_util.dart';import "package:photos/utils/dialog_util.dart";+import "package:photos/utils/download_skip_toast_util.dart";import "package:photos/utils/file_download_util.dart";import 'package:photos/utils/magic_util.dart';import "package:photos/utils/share_util.dart";@@ -150,8 +151,7 @@ class _FileSelectionActionsWidgetState!widget.selectedFiles.files.any((element) => element.fileType == FileType.video,);- final showDownloadOption =- widget.selectedFiles.files.any((element) => element.localID == null);+ final showDownloadOption = hasUploadedFileIDs;final bool isCollectionOwnerOrAdmin = widget.collection != null &&(widget.collection!.isOwner(currentUserID) ||widget.collection!.isAdmin(currentUserID));@@ -1099,21 +1099,29 @@ class _FileSelectionActionsWidgetState}Future<void> _download(List<EnteFile> files) async {- final totalFiles = files.length;- int downloadedFiles = 0;+ if (files.isEmpty) {+ return;+ }- final dialog = createProgressDialog(- context,- AppLocalizations.of(context).downloading +- " ($downloadedFiles/$totalFiles)",- isDismissible: true,- );- await dialog.show();- try {- final taskQueue = SimpleTaskQueue(maxConcurrent: 5);- final futures = <Future>[];- for (final file in files) {- if (file.localID == null) {+ final remoteFiles = files.where((file) => file.isRemoteFile).toList();+ final skippedFiles = files.where((file) => !file.isRemoteFile).toList();+ final skippedFilesCount = skippedFiles.length;++ if (remoteFiles.isNotEmpty) {+ final totalFiles = remoteFiles.length;+ int downloadedFiles = 0;++ final dialog = createProgressDialog(+ context,+ AppLocalizations.of(context).downloading ++ " ($downloadedFiles/$totalFiles)",+ isDismissible: true,+ );+ await dialog.show();+ try {+ final taskQueue = SimpleTaskQueue(maxConcurrent: 5);+ final futures = <Future>[];+ for (final file in remoteFiles) {futures.add(taskQueue.add(() async {await downloadToGallery(file);@@ -1125,15 +1133,48 @@ class _FileSelectionActionsWidgetState}),);}+ await Future.wait(futures);+ await dialog.hide();+ } catch (e) {+ _logger.warning("Failed to save files", e);+ await dialog.hide();+ await showGenericErrorDialog(context: context, error: e);+ return;}- await Future.wait(futures);- await dialog.hide();+ }++ String finalMessage;+ if (skippedFilesCount > 0) {+ if (skippedFilesCount == 1) {+ final skippedFile = skippedFiles.first;+ final folderName = await getLocalFolderNameForDownloadSkipToast(+ skippedFile,+ fallbackFolderName: AppLocalizations.of(context).gallery,+ );+ finalMessage =+ buildSingleFileDownloadSkippedInMultiSelectionToastMessage(+ skippedFile,+ folderName: folderName,+ fallbackFileName: AppLocalizations.of(context).file,+ );+ } else {+ finalMessage =+ buildMultipleFilesDownloadSkippedToastMessage(skippedFilesCount);+ }+ } else {+ finalMessage = AppLocalizations.of(context).filesSavedToGallery;+ }++ showToast(+ context,+ finalMessage,+ iosLongToastLengthInSec: 4,+ );++ if (skippedFilesCount == 0) {widget.selectedFiles.clearAll();- showToast(context, AppLocalizations.of(context).filesSavedToGallery);- } catch (e) {- _logger.warning("Failed to save files", e);- await dialog.hide();- await showGenericErrorDialog(context: context, error: e);+ } else if (remoteFiles.isNotEmpty) {+ widget.selectedFiles.unSelectAll(remoteFiles.toSet());}}}diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dartindex 0138f23b69..e3c410d859 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart@@ -37,6 +37,7 @@ import "package:photos/ui/viewer/file/detail_page.dart";import "package:photos/ui/viewer/file_details/favorite_widget.dart";import "package:photos/ui/viewer/file_details/upload_icon_widget.dart";import 'package:photos/utils/dialog_util.dart';+import "package:photos/utils/download_skip_toast_util.dart";import "package:photos/utils/file_download_util.dart";import 'package:photos/utils/file_util.dart';import "package:photos/utils/magic_util.dart";@@ -312,7 +313,7 @@ class FileAppBarState extends State<FileAppBar> {),);} else {- if (widget.file.isRemoteFile) {+ if (isFileUploaded) {items.add(EntePopupMenuItem(AppLocalizations.of(context).download,@@ -618,6 +619,25 @@ class FileAppBarState extends State<FileAppBar> {}Future<void> _download(EnteFile file) async {+ if (!file.isRemoteFile) {+ final folderName = await getLocalFolderNameForDownloadSkipToast(+ file,+ fallbackFolderName: AppLocalizations.of(context).gallery,+ );+ if (mounted) {+ showToast(+ context,+ buildSingleFileDownloadSkippedToastMessage(+ file,+ folderName: folderName,+ fallbackFileName: AppLocalizations.of(context).file,+ ),+ iosLongToastLengthInSec: 4,+ );+ }+ return;+ }+final dialog = createProgressDialog(context,context.l10n.downloading,diff --git a/mobile/apps/photos/lib/utils/download_skip_toast_util.dart b/mobile/apps/photos/lib/utils/download_skip_toast_util.dartnew file mode 100644index 0000000000..6a6f0bbf07--- /dev/null+++ b/mobile/apps/photos/lib/utils/download_skip_toast_util.dart@@ -0,0 +1,73 @@+import "package:photos/models/file/file.dart";++String buildSingleFileDownloadSkippedToastMessage(+ EnteFile file, {+ required String folderName,+ required String fallbackFileName,+}) {+ final title = (file.title ?? "").trim();+ final displayName = file.displayName.trim();+ final fileName = title.isNotEmpty+ ? title+ : displayName.isNotEmpty+ ? displayName+ : fallbackFileName;++ return "$fileName is already available in the $folderName folder on your device";+}++String buildSingleFileDownloadSkippedInMultiSelectionToastMessage(+ EnteFile file, {+ required String folderName,+ required String fallbackFileName,+}) {+ final title = (file.title ?? "").trim();+ final displayName = file.displayName.trim();+ final fileName = title.isNotEmpty+ ? title+ : displayName.isNotEmpty+ ? displayName+ : fallbackFileName;++ return "Download of $fileName skipped as it is already available in the $folderName folder on your device";+}++String buildMultipleFilesDownloadSkippedToastMessage(int fileCount) {+ if (fileCount == 1) {+ return "Download of 1 file skipped as it is already on your device";+ }+ return "Download of $fileCount files skipped as they are already on your device";+}++Future<String> getLocalFolderNameForDownloadSkipToast(+ EnteFile file, {+ required String fallbackFolderName,+}) async {+ final String deviceFolder = (file.deviceFolder ?? "").trim();+ if (deviceFolder.isNotEmpty) {+ return _getLastPathSegment(deviceFolder);+ }++ final asset = await file.getAsset;+ if (asset != null && await asset.exists) {+ final String relativePath =+ (asset.relativePath ?? "").trim().replaceFirst(RegExp(r'[/\\]+$'), '');+ if (relativePath.isNotEmpty) {+ return _getLastPathSegment(relativePath);+ }+ }++ return fallbackFolderName;+}++String _getLastPathSegment(String path) {+ final normalized = path.trim().replaceFirst(RegExp(r'[/\\]+$'), '');+ if (normalized.isEmpty) {+ return normalized;+ }+ final segments = normalized+ .split(RegExp(r'[/\\]+'))+ .where((segment) => segment.trim().isNotEmpty)+ .toList();+ return segments.isEmpty ? normalized : segments.last;+}