From 1f0282ac02bb0f4265bc362952d51a26d4d63182 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 29 May 2024 17:05:40 +0200 Subject: [PATCH] chore: Remove overwrite feature --- .../MediaGalleryHelperSamplePage.xaml.cs | 6 +++--- .../MediaGallery/MediaGallery.Android.cs | 21 +------------------ .../Helpers/MediaGallery/MediaGallery.cs | 8 +++---- .../MediaGallery/MediaGallerySaveResult.cs | 15 ------------- 4 files changed, 8 insertions(+), 42 deletions(-) delete mode 100644 src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallerySaveResult.cs diff --git a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Helpers/MediaGalleryHelperSamplePage.xaml.cs b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Helpers/MediaGalleryHelperSamplePage.xaml.cs index d29f38b16..48e0f9249 100644 --- a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Helpers/MediaGalleryHelperSamplePage.xaml.cs +++ b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Helpers/MediaGalleryHelperSamplePage.xaml.cs @@ -76,7 +76,7 @@ public class MediaGalleryHelperSampleVM : ViewModelBase { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/UnoLogo.png", UriKind.Absolute)); using var stream = await file.OpenStreamForReadAsync(); - await MediaGallery.SaveAsync(MediaFileType.Image, stream, "UnoLogo.png", false); + await MediaGallery.SaveAsync(MediaFileType.Image, stream, "UnoLogo.png"); } else { @@ -97,7 +97,7 @@ public class MediaGalleryHelperSampleVM : ViewModelBase using var stream = await file.OpenStreamForReadAsync(); var fileName = Guid.NewGuid() + ".png"; - await MediaGallery.SaveAsync(MediaFileType.Image, stream, fileName, false); + await MediaGallery.SaveAsync(MediaFileType.Image, stream, fileName); } else { @@ -116,7 +116,7 @@ public class MediaGalleryHelperSampleVM : ViewModelBase { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/UnoLogo.png", UriKind.Absolute)); using var stream = await file.OpenStreamForReadAsync(); - await MediaGallery.SaveAsync(MediaFileType.Image, stream, "UnoLogo.png", true); + await MediaGallery.SaveAsync(MediaFileType.Image, stream, "UnoLogo.png"); } else { diff --git a/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.Android.cs b/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.Android.cs index bc432db05..aff6dd8b0 100644 --- a/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.Android.cs +++ b/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.Android.cs @@ -34,7 +34,7 @@ private static async Task CheckAccessPlatformAsync() } } - private static async Task SavePlatformAsync(MediaFileType type, Stream sourceStream, string targetFileName, bool overwrite) + private static async Task SavePlatformAsync(MediaFileType type, Stream sourceStream, string targetFileName) { var context = Application.Context; var contentResolver = context.ContentResolver ?? throw new InvalidOperationException("ContentResolver is not set."); @@ -78,23 +78,6 @@ private static async Task SavePlatformAsync(MediaFileTyp throw new InvalidOperationException($"Relative path for {type} is not available."); } - // Check if file already exists - if (!overwrite) - { - using var cursor = contentResolver.Query(externalContentUri, null, $"{IMediaColumns.DisplayName} = ?", new[] { targetFileName }, null); - - if (cursor is null) - { - throw new InvalidOperationException("Could not query media content"); - } - - if (cursor.MoveToFirst()) - { - cursor.Close(); - return MediaGallerySaveResult.Exists; - } - } - if ((int)Build.VERSION.SdkInt >= 29) { values.Put(IMediaColumns.RelativePath, Path.Combine(relativePath, appFolderName)); @@ -142,8 +125,6 @@ private static async Task SavePlatformAsync(MediaFileTyp context.SendBroadcast(mediaScanIntent); #pragma warning restore CS0618 // Type or member is obsolete } - - return MediaGallerySaveResult.Success; } private static long TimeMillis(DateTime current) => (long)GetTimeDifference(current).TotalMilliseconds; diff --git a/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.cs b/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.cs index 7a7639c13..26fe678e7 100644 --- a/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.cs +++ b/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.cs @@ -27,10 +27,10 @@ public static partial class MediaGallery /// Byte array representing the file. /// Target file name. /// Task representing the progress of the operation. - public static async Task SaveAsync(MediaFileType type, byte[] data, string targetFileName, bool overwrite) + public static async Task SaveAsync(MediaFileType type, byte[] data, string targetFileName) { using var memoryStream = new MemoryStream(data); - return await SaveAsync(type, memoryStream, targetFileName, overwrite); + await SaveAsync(type, memoryStream, targetFileName); } /// @@ -40,7 +40,7 @@ public static async Task SaveAsync(MediaFileType type, b /// Stream representing the file. /// Target file name. /// Task representing the progress of the operation. - public static async Task SaveAsync(MediaFileType type, Stream stream, string targetFileName, bool overwrite) => - await SavePlatformAsync(type, stream, targetFileName, overwrite); + public static async Task SaveAsync(MediaFileType type, Stream stream, string targetFileName) => + await SavePlatformAsync(type, stream, targetFileName); } #endif diff --git a/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallerySaveResult.cs b/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallerySaveResult.cs deleted file mode 100644 index a59d8b8b7..000000000 --- a/src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallerySaveResult.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Uno.Toolkit.UI; - -public enum MediaGallerySaveResult -{ - /// - /// The file was saved successfully. - /// - Success, - - /// - /// File with this name already exists. - /// - Exists -} -