Skip to content

Commit

Permalink
Code Style (#135)
Browse files Browse the repository at this point in the history
code style

upd editor config

usings

fix _

fix editorconfig
  • Loading branch information
dimonovdd authored Nov 5, 2024
1 parent 7936050 commit 4c93fd8
Show file tree
Hide file tree
Showing 57 changed files with 1,245 additions and 978 deletions.
869 changes: 778 additions & 91 deletions .editorconfig

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions MediaGallery/ExceptionHelper/ExceptionHelper.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

static class ExceptionHelper
{
private static Exception NotSupportedOrImplementedException
static Exception NotSupportedOrImplementedException
=> new NotImplementedException("This functionality is not implemented in the portable version of this assembly. " +
"You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.");

internal static PermissionException PermissionException(PermissionStatus status)
=> new($"{nameof(SaveMediaPermission)} was not granted: {status}");

private static bool? isSupported;
static bool? isSupported;

internal static void CheckSupport()
{
if (!isSupported.HasValue)
{
isSupported
#if __ANDROID__
= Platform.HasSdkVersion(21);
= Platform.HasSdkVersion(21);
#else
= Platform.HasOSVersion(11);
#endif
Expand All @@ -27,9 +27,9 @@ internal static void CheckSupport()
}

#if __ANDROID__
internal static Exception ActivityNotDetected
=> new NullReferenceException("The current Activity can not be detected. " +
$"Ensure that you have called Xamarin.Essentials.Platform.Init in your Activity or Application class.");
internal static Exception ActivityNotDetected
=> new NullReferenceException("The current Activity can not be detected. " +
"Ensure that you have called Xamarin.Essentials.Platform.Init in your Activity or Application class.");
#else
internal static Exception ControllerNotFound
=> new InvalidOperationException("Could not find current view controller.");
Expand Down
4 changes: 2 additions & 2 deletions MediaGallery/MediaFile/IMediaFile.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>Describes and allows to open a media file</summary>
public interface IMediaFile : IDisposable
{
/// <summary>Returns the file name without extension. Can return an null or empty value</summary>
/// <summary>Returns the file name without extension. Can return a null or empty value</summary>
string NameWithoutExtension { get; }

/// <summary>Returns the file extension without a dot (eg:, "png").</summary>
Expand All @@ -12,7 +12,7 @@ public interface IMediaFile : IDisposable
/// <summary>Returns the file's content type as a MIME type (eg: "image/png").</summary>
string ContentType { get; }

/// <summary>Returns the file type. Can return an null value.</summary>
/// <summary>Returns the file type. Can return a null value.</summary>
MediaFileType? Type { get; }

/// <summary>Opens a read-only stream containing the file.</summary>
Expand Down
24 changes: 12 additions & 12 deletions MediaGallery/MediaFile/MediaFile.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ namespace NativeMedia;

partial class MediaFile
{
readonly Uri uri;
readonly string tempFilePath;
readonly Uri uri;

internal MediaFile(string fileName, Uri uri, string tempFilePath = null)
{
this.tempFilePath = tempFilePath;
NameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
Extension = Path.GetExtension(fileName);
ContentType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(Extension);
this.uri = uri;
Type = GetFileType(ContentType);
}
this.tempFilePath = tempFilePath;
NameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
Extension = Path.GetExtension(fileName);
ContentType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(Extension);
this.uri = uri;
Type = GetFileType(ContentType);
}

Task<Stream> PlatformOpenReadAsync()
=> Task.FromResult(Platform.AppActivity.ContentResolver.OpenInputStream(uri));

void PlatformDispose()
{
if(!string.IsNullOrWhiteSpace(tempFilePath) && File.Exists(tempFilePath))
File.Delete(tempFilePath);
if (!string.IsNullOrWhiteSpace(tempFilePath) && File.Exists(tempFilePath))
File.Delete(tempFilePath);

uri?.Dispose();
}
uri?.Dispose();
}
}
24 changes: 11 additions & 13 deletions MediaGallery/MediaFile/MediaFile.ios.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Foundation;
using ImageIO;
using ImageIO;
using MobileCoreServices;
using UIKit;

namespace NativeMedia;

Expand All @@ -15,16 +13,16 @@ protected virtual void PlatformDispose() { }
protected string GetExtension(string identifier)
=> UTType.CopyAllTags(identifier, UTType.TagClassFilenameExtension)?.FirstOrDefault();

protected string GetMIMEType(string identifier)
protected string GetMimeType(string identifier)
=> UTType.CopyAllTags(identifier, UTType.TagClassMIMEType)?.FirstOrDefault();
}

class PHPickerFile : MediaFile
class PhPickerFile : MediaFile
{
readonly string identifier;
NSItemProvider provider;

internal PHPickerFile(NSItemProvider provider)
internal PhPickerFile(NSItemProvider provider)
{
this.provider = provider;
NameWithoutExtension = provider?.SuggestedName;
Expand All @@ -35,7 +33,7 @@ internal PHPickerFile(NSItemProvider provider)
return;

Extension = GetExtension(identifier);
ContentType = GetMIMEType(identifier);
ContentType = GetMimeType(identifier);
Type = GetFileType(ContentType);
}

Expand All @@ -49,7 +47,7 @@ protected override void PlatformDispose()
base.PlatformDispose();
}

private string GetIdentifier(string[] identifiers)
string GetIdentifier(string[] identifiers)
{
if (!(identifiers?.Length > 0))
return null;
Expand All @@ -63,15 +61,15 @@ private string GetIdentifier(string[] identifiers)

class UIDocumentFile : MediaFile
{
UIDocument document;
NSUrl assetUrl;
UIDocument document;

internal UIDocumentFile(NSUrl assetUrl, string fileName)
{
this.assetUrl = assetUrl;
document = new UIDocument(assetUrl);
Extension = document.FileUrl.PathExtension;
ContentType = GetMIMEType(document.FileType);
ContentType = GetMimeType(document.FileType);
NameWithoutExtension = !string.IsNullOrWhiteSpace(fileName)
? Path.GetFileNameWithoutExtension(fileName)
: null;
Expand All @@ -94,15 +92,15 @@ protected override void PlatformDispose()
class PhotoFile : MediaFile
{
UIImage img;
NSDictionary metadata;
NSMutableData imgWithMetadata;
NSDictionary metadata;

internal PhotoFile(UIImage img, NSDictionary metadata, string name)
{
this.img = img;
this.metadata = metadata;
NameWithoutExtension = name;
ContentType = GetMIMEType(UTType.JPEG);
ContentType = GetMimeType(UTType.JPEG);
Extension = GetExtension(UTType.JPEG);
Type = GetFileType(ContentType);
}
Expand All @@ -120,7 +118,7 @@ public NSMutableData GetImageWithMeta()

using var source = CGImageSource.FromData(img.AsJPEG());
var destData = new NSMutableData();
using var destination = CGImageDestination.Create(destData, source.TypeIdentifier, 1, null);
using var destination = CGImageDestination.Create(destData, source.TypeIdentifier, 1);
destination.AddImage(source, 0, metadata);
destination.Close();
DisposeSources();
Expand Down
2 changes: 1 addition & 1 deletion MediaGallery/MediaFile/MediaFile.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

partial class MediaFile : IMediaFile
{
private string extension;
string extension;

public string NameWithoutExtension { get; protected internal set; }

Expand Down
128 changes: 64 additions & 64 deletions MediaGallery/MediaGallery.csproj
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.44">
<PropertyGroup>
<TargetFrameworks>net8.0-ios;net8.0-android;</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>NativeMedia</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<PackageId>Xamarin.MediaGallery</PackageId>
<PackageTags>maui, xamarin, .net8, ios, android, toolkit, xamarin.forms, media, picker, photos, videos, mediapicker</PackageTags>
<Description>This plugin is designed for picking and saving photos and video files from the native gallery of Android and iOS devices</Description>
<Version>3.0.0-preview</Version>
<Authors>dimonovdd</Authors>
<Owners>dimonovdd</Owners>
<RepositoryUrl>https://github.com/dimonovdd/Xamarin.MediaGallery</RepositoryUrl>
<PackageReleaseNotes>See: https://github.com/dimonovdd/Xamarin.MediaGallery/releases</PackageReleaseNotes>
<PackageReadmeFile>README.nuget.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Configurations>Debug;Release</Configurations>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup>
<_Droid Condition=" $(TargetFramework.Contains('droid')) ">true</_Droid>
<_IOS Condition=" $(TargetFramework.ToLowerInvariant().Contains('ios')) ">true</_IOS>
</PropertyGroup>
<PropertyGroup>
<SupportedOSPlatformVersion Condition="'$(_IOS)' == 'true'">13.6</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(_Droid)' == 'true'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.3" />
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE" PackagePath="" Pack="true" />
<None Include="..\icon.png" PackagePath="" Pack="true" />
<None Include="..\docs\README.nuget.md" PackagePath="" Pack="true" />
<Compile Include="**\*.shared.cs" />
<Compile Include="**\*.shared.*.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(_Droid)' == 'true' ">
<Compile Include="**\*.android.*.cs" Exclude="**\*.resource.*.cs"/>
<Compile Include="**\*.android.cs" />
<AndroidResource Include="Resources\xml\*.xml" />
</ItemGroup>
<ItemGroup Condition=" '$(_IOS)' == 'true' ">
<Compile Include="**\*.ios.*.cs" />
<Compile Include="**\*.ios.cs" />
</ItemGroup>
<Target Name="DisplayMessages" BeforeTargets="Build">
<Message Text="$(AssemblyName) DefineConstants: $(DefineConstants)"/>
<Message Text="$(AssemblyName) Configuration: '$(Configuration)|$(Platform)'"/>
</Target>
<PropertyGroup>
<TargetFrameworks>net8.0-ios;net8.0-android;</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>NativeMedia</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<PackageId>Xamarin.MediaGallery</PackageId>
<PackageTags>maui, xamarin, .net8, ios, android, toolkit, xamarin.forms, media, picker, photos, videos, mediapicker</PackageTags>
<Description>This plugin is designed for picking and saving photos and video files from the native gallery of Android and iOS devices</Description>
<Version>3.0.0-preview</Version>
<Authors>dimonovdd</Authors>
<Owners>dimonovdd</Owners>
<RepositoryUrl>https://github.com/dimonovdd/Xamarin.MediaGallery</RepositoryUrl>
<PackageReleaseNotes>See: https://github.com/dimonovdd/Xamarin.MediaGallery/releases</PackageReleaseNotes>
<PackageReadmeFile>README.nuget.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Configurations>Debug;Release</Configurations>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup>
<_Droid Condition=" $(TargetFramework.Contains('droid')) ">true</_Droid>
<_IOS Condition=" $(TargetFramework.ToLowerInvariant().Contains('ios')) ">true</_IOS>
</PropertyGroup>
<PropertyGroup>
<SupportedOSPlatformVersion Condition="'$(_IOS)' == 'true'">13.6</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(_Droid)' == 'true'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.3"/>
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE" PackagePath="" Pack="true"/>
<None Include="..\icon.png" PackagePath="" Pack="true"/>
<None Include="..\docs\README.nuget.md" PackagePath="" Pack="true"/>
<Compile Include="**\*.shared.cs"/>
<Compile Include="**\*.shared.*.cs"/>
</ItemGroup>
<ItemGroup Condition=" '$(_Droid)' == 'true' ">
<Compile Include="**\*.android.*.cs" Exclude="**\*.resource.*.cs"/>
<Compile Include="**\*.android.cs"/>
<AndroidResource Include="Resources\xml\*.xml"/>
</ItemGroup>
<ItemGroup Condition=" '$(_IOS)' == 'true' ">
<Compile Include="**\*.ios.*.cs"/>
<Compile Include="**\*.ios.cs"/>
</ItemGroup>
<Target Name="DisplayMessages" BeforeTargets="Build">
<Message Text="$(AssemblyName) DefineConstants: $(DefineConstants)"/>
<Message Text="$(AssemblyName) Configuration: '$(Configuration)|$(Platform)'"/>
</Target>
</Project>
5 changes: 2 additions & 3 deletions MediaGallery/MediaGallery/MediaFileType.shared.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

namespace NativeMedia;
namespace NativeMedia;

/// <summary>Enumeration media files</summary>
public enum MediaFileType
{
/// <summary>image/*</summary>
Image,
/// <summary>video/*</summary>
Video
Video,
}
Loading

0 comments on commit 4c93fd8

Please sign in to comment.