Skip to content

Commit

Permalink
chore: Remove overwrite feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed May 29, 2024
1 parent a1f2d07 commit 1f0282a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand Down
21 changes: 1 addition & 20 deletions src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static async Task<bool> CheckAccessPlatformAsync()
}
}

private static async Task<MediaGallerySaveResult> 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.");
Expand Down Expand Up @@ -78,23 +78,6 @@ private static async Task<MediaGallerySaveResult> 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));
Expand Down Expand Up @@ -142,8 +125,6 @@ private static async Task<MediaGallerySaveResult> 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;
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public static partial class MediaGallery
/// <param name="data">Byte array representing the file.</param>
/// <param name="targetFileName">Target file name.</param>
/// <returns>Task representing the progress of the operation.</returns>
public static async Task<MediaGallerySaveResult> 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);
}

/// <summary>
Expand All @@ -40,7 +40,7 @@ public static async Task<MediaGallerySaveResult> SaveAsync(MediaFileType type, b
/// <param name="stream">Stream representing the file.</param>
/// <param name="targetFileName">Target file name.</param>
/// <returns>Task representing the progress of the operation.</returns>
public static async Task<MediaGallerySaveResult> 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
15 changes: 0 additions & 15 deletions src/Uno.Toolkit.UI/Helpers/MediaGallery/MediaGallerySaveResult.cs

This file was deleted.

0 comments on commit 1f0282a

Please sign in to comment.