Skip to content

armgit / ente

Public Imported from GitHub
0

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

Support sharing multiple files into Locker on Android

AmanRajSinghMourya2c37ff49316d
diff --git a/mobile/apps/locker/android/app/src/main/AndroidManifest.xml b/mobile/apps/locker/android/app/src/main/AndroidManifest.xml
index 3b0148afe3..3ff5ab4195 100644
--- a/mobile/apps/locker/android/app/src/main/AndroidManifest.xml
+++ b/mobile/apps/locker/android/app/src/main/AndroidManifest.xml
@@ -41,6 +41,7 @@
<intent-filter>
<action android:name="android.intent.action.SEND" />
+ <action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
diff --git a/mobile/apps/locker/changes/android-multiple-file-sharing.md b/mobile/apps/locker/changes/android-multiple-file-sharing.md
new file mode 100644
index 0000000000..5d61dd280c
--- /dev/null
+++ b/mobile/apps/locker/changes/android-multiple-file-sharing.md
@@ -0,0 +1 @@
+- Added support for sharing multiple files into Locker on Android, with a warning for files that were skipped.
diff --git a/mobile/apps/locker/lib/ui/pages/home_page.dart b/mobile/apps/locker/lib/ui/pages/home_page.dart
index 4e98184f2b..88cd6e9ce8 100644
--- a/mobile/apps/locker/lib/ui/pages/home_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/home_page.dart
@@ -418,23 +418,56 @@ class _HomePageState extends UploaderPageState<HomePage>
}
try {
+ final files = <File>[];
+ final seen = <String>{};
+ var skippedCount = 0;
for (final sharedFile in sharedFiles) {
- _logger.info('Processing shared file');
- if (sharedFile.path.isNotEmpty) {
- final file = File(sharedFile.path);
- if (await file.exists()) {
- _logger.info('File exists, uploading');
- await uploadFiles([file]);
- } else {
- _logger.warning('Shared file does not exist');
+ if (seen.contains(sharedFile.path)) {
+ skippedCount++;
+ continue;
+ }
+ final file = File(sharedFile.path);
+ try {
+ final reader = await file.open();
+ try {
+ await reader.read(1);
+ } finally {
+ await reader.close();
+ }
+ seen.add(sharedFile.path);
+ files.add(file);
+ } on FileSystemException {
+ // The plugin also labels files with captions as text; probe them first.
+ if (sharedFile.type != SharedMediaType.text &&
+ sharedFile.type != SharedMediaType.url &&
+ sharedFile.type != SharedMediaType.mailto) {
+ skippedCount++;
}
- } else {
- _logger.warning('Shared file has empty path');
}
}
+ if (!mounted) return;
- await ReceiveSharingIntent.instance.reset();
- _logger.info('Reset sharing intent after handling files');
+ if (skippedCount > 0) {
+ _logger.warning('Skipped $skippedCount unreadable or repeated files');
+ await showBottomSheetComponent(
+ context: context,
+ builder: (sheetContext) => BottomSheetComponent(
+ title: context.strings.skippedFiles,
+ message: context.strings.sharedFilesSkipped,
+ illustration: LockerBottomSheetIllustration.warningGrey,
+ actions: [
+ ButtonComponent(
+ label: context.strings.ok,
+ onTap: () => Navigator.of(sheetContext).pop(),
+ ),
+ ],
+ ),
+ );
+ }
+
+ if (mounted && files.isNotEmpty) {
+ await uploadFiles(files);
+ }
} catch (e) {
_logger.severe('Error handling shared files: $e');
if (mounted) {
@@ -455,6 +488,8 @@ class _HomePageState extends UploaderPageState<HomePage>
),
);
}
+ } finally {
+ await ReceiveSharingIntent.instance.reset();
}
}
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 88bfd52157..82a5538944 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -4171,6 +4171,7 @@
},
"skip": "Skip",
"skippedFiles": "Skipped files",
+ "sharedFilesSkipped": "Some shared files could not be read or had the same name. They were skipped.",
"slideshow": "Slideshow",
"slideshowSettings": "Slideshow settings",
"smartMemories": "Smart memories",