Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Copy to temp on media picking (#11084)

Willian Wang6ede01ba0212
diff --git a/mobile/apps/photos/changes/sd-card-media-picker.md b/mobile/apps/photos/changes/sd-card-media-picker.md
new file mode 100644
index 0000000000..b79f55f052
--- /dev/null
+++ b/mobile/apps/photos/changes/sd-card-media-picker.md
@@ -0,0 +1 @@
+- Fixed picking SD card media from Ente in other Android apps. Thanks wangwillian0!
diff --git a/mobile/apps/photos/lib/module/share/picker_result_uri.dart b/mobile/apps/photos/lib/module/share/picker_result_uri.dart
new file mode 100644
index 0000000000..72f6fffd5d
--- /dev/null
+++ b/mobile/apps/photos/lib/module/share/picker_result_uri.dart
@@ -0,0 +1,10 @@
+import "package:photos/models/file/file.dart";
+import "package:photos/module/download/file.dart";
+
+Future<String?> getPickerResultUri(EnteFile file) async {
+ if (!file.isSharedMediaToAppSandbox) {
+ final mediaUri = await (await file.getAsset)?.getMediaUrl();
+ if (mediaUri != null) return mediaUri;
+ }
+ return (await getFile(file))?.uri.toString();
+}
diff --git a/mobile/apps/photos/lib/ui/picker/external_media_picker_page.dart b/mobile/apps/photos/lib/ui/picker/external_media_picker_page.dart
index 742a04f434..d39e867ac7 100644
--- a/mobile/apps/photos/lib/ui/picker/external_media_picker_page.dart
+++ b/mobile/apps/photos/lib/ui/picker/external_media_picker_page.dart
@@ -18,7 +18,7 @@ import "package:photos/models/file/file_type.dart";
import "package:photos/models/file_load_result.dart";
import "package:photos/models/gallery_type.dart";
import "package:photos/models/selected_files.dart";
-import "package:photos/module/download/file.dart";
+import "package:photos/module/share/picker_result_uri.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/services/filter/db_filters.dart";
@@ -129,10 +129,8 @@ class _ExternalMediaPickerPageState extends State<ExternalMediaPickerPage> {
final selectedFiles = _selectedFiles.files.toList();
final uris = <String>[];
for (final file in selectedFiles) {
- final ioFile = await getFile(file);
- if (ioFile != null) {
- uris.add(ioFile.uri.toString());
- }
+ final uri = await getPickerResultUri(file);
+ if (uri != null) uris.add(uri);
}
if (!mounted) {
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
index 5a492af5a5..318bbab287 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
@@ -12,7 +12,7 @@ import "package:photos/events/file_uploaded_event.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/gallery_type.dart";
import "package:photos/models/selected_files.dart";
-import "package:photos/module/download/file.dart";
+import "package:photos/module/share/picker_result_uri.dart";
import "package:photos/services/app_lifecycle_service.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/ui/common/touch_cross_detector.dart";
@@ -243,8 +243,7 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
} else {
if (AppLifecycleService.instance.mediaExtensionAction.action ==
IntentAction.pick) {
- final ioFile = await getFile(file);
- await MediaExtension().setResult("file://${ioFile!.path}");
+ await _returnPickerResult(file);
} else {
_routeToDetailPage(file, context);
}
@@ -281,13 +280,17 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
) async {
if (AppLifecycleService.instance.mediaExtensionAction.action ==
IntentAction.pick) {
- final ioFile = await getFile(file);
- await MediaExtension().setResult("file://${ioFile!.path}");
+ await _returnPickerResult(file);
} else {
_routeToDetailPage(file, context);
}
}
+ Future<void> _returnPickerResult(EnteFile file) async {
+ final uri = await getPickerResultUri(file);
+ if (uri != null) await MediaExtension().setResult(uri);
+ }
+
void _routeToDetailPage(EnteFile file, BuildContext context) {
final galleryFiles = GalleryFilesState.of(context).galleryFiles;
final selectedIndex = galleryFiles.indexOf(file);