Skip to content

Commit

Permalink
Maui support (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimonovdd authored Nov 28, 2022
1 parent f8e70a7 commit 368087e
Show file tree
Hide file tree
Showing 47 changed files with 476 additions and 179 deletions.
30 changes: 17 additions & 13 deletions MediaGallery/MediaGallery.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.38">
<Project Sdk="MSBuild.Sdk.Extras/3.0.44">
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0;net6.0-ios;Xamarin.iOS10;net6.0-android;MonoAndroid10.0;MonoAndroid11.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;Xamarin.iOS10;MonoAndroid10.0;MonoAndroid11.0;MonoAndroid12.0;</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks)net6.0-android;net6.0-ios</TargetFrameworks>
<AssemblyName>NativeMedia</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<PackageId>Xamarin.MediaGallery</PackageId>
<PackageTags>maui, xamarin, .net6, 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>2.1.0</Version>
<Version>2.1.2</Version>
<Authors>dimonovdd</Authors>
<Owners>dimonovdd</Owners>
<RepositoryUrl>https://github.com/dimonovdd/Xamarin.MediaGallery</RepositoryUrl>
Expand All @@ -17,7 +18,7 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Configurations>Release;Debug</Configurations>
<Configurations>Debug;Release</Configurations>
<LangVersion>10.0</LangVersion>
<_IsSample>false</_IsSample>
</PropertyGroup>
Expand All @@ -30,13 +31,10 @@
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup>
<_Net6 Condition=" $(TargetFramework.Contains('net6')) ">true</_Net6>
<_Droid Condition=" $(TargetFramework.Contains('droid')) ">true</_Droid>
Expand All @@ -48,21 +46,27 @@
<DefineConstants Condition=" '$(_Net6)' == 'true' ">$(DefineConstants);__NET6__;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(_Net6)' == 'true' AND '$(_Mobile)' == 'true' ">
<UseMauiEssentials>true</UseMauiEssentials>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<SupportedOSPlatformVersion Condition="'$(_IOS)' == 'true'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(_Droid)' == 'true'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup Condition=" '$(_Net6)' != 'true' AND '$(_Mobile)' == 'true' ">
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE" PackagePath="" Pack="true" />
<None Include="..\icon.png" PackagePath="" Pack="true" />
<None Include="..\README.md" PackagePath="" Pack="true" />
<Compile Include="**\*.shared.cs" />
<Compile Include="**\*.shared.*.cs" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' OR $(TargetFramework.StartsWith('netstandard')) ">
<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
<Compile Include="**\*.netstandard.cs" />
<Compile Include="**\*.netstandard.*.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MediaGallery/MediaGallery/PickMedia.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static async Task<IMediaFile> PlatformCapturePhotoAsync(CancellationToken token)

var fileName = $"{GetNewImageName()}.jpg";
var tempFilePath = GetFilePath(fileName);
using var file = new File(tempFilePath);
using var file = new Java.IO.File(tempFilePath);
if (!file.Exists())
file.CreateNewFile();
outputUri = MediaFileProvider.GetUriForFile(Platform.AppActivity, file);
Expand Down
7 changes: 6 additions & 1 deletion MediaGallery/MediaGallery/PickMedia.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ await MainThread.InvokeOnMainThreadAsync(() =>
{
SourceType = sourceType,
AllowsEditing = false,
#if !__NET6__
AllowsImageEditing = false,
#endif
Delegate = new PhotoPickerDelegate(tcs),
MediaTypes = isVideo && isImage
? new string[] { UTType.Movie, UTType.Image }
: new string[] { isVideo ? UTType.Movie : UTType.Image }
};

}

CancelTaskIfRequested(token, tcs);
Expand Down Expand Up @@ -124,7 +127,9 @@ await MainThread.InvokeOnMainThreadAsync(() =>
{
SourceType = UIImagePickerControllerSourceType.Camera,
AllowsEditing = false,
AllowsImageEditing = false,
#if !__NET6__
AllowsImageEditing = false,
#endif
Delegate = new PhotoPickerDelegate(tcs),
CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo
};
Expand Down
3 changes: 1 addition & 2 deletions MediaGallery/MediaPickRequest/MediaPickRequest.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public MediaPickRequest(int selectionLimit = 1, params MediaFileType[] types)
public string Title { get; set; }

/// <summary>Gets or sets the source rectangle to display the Picker UI from. This is only used on iPad currently.</summary>
/// <remarks>Xamarin - System.Drawing.Rectangle; &nbsp;
/// .net6(MAUI) - Microsoft.Maui.Graphics.Rectangle;</remarks>
/// <remarks>Xamarin - System.Drawing.Rectangle; .net6(MAUI) - Microsoft.Maui.Graphics.Rectangle;</remarks>
public object PresentationSourceBounds { get; set; } = default;

/// <summary>Gets or sets whether to use Intent.CreateChooser. Currently used only for Android.</summary>
Expand Down
2 changes: 1 addition & 1 deletion MediaGallery/Platform/Platform.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal static bool IsIntentSupported(Intent intent)

}

[ContentProvider(new[] { "${applicationId}" + Authority },Name = "haraba.fileProvider", Exported = false, GrantUriPermissions = true)]
[ContentProvider(new[] { "${applicationId}" + Authority },Name = "nativeMedia.fileProvider", Exported = false, GrantUriPermissions = true)]
[MetaData("android.support.FILE_PROVIDER_PATHS", Resource = "@xml/file_provider_paths")]
public class MediaFileProvider : ContentFileProvider
{
Expand Down
12 changes: 6 additions & 6 deletions MediaGallery/Usings/GlobalUsings.shared.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#if NET6_0_ANDROID || NET6_0_IOS
global using EssentialsEx = Microsoft.Maui.Essentials;
global using Microsoft.Maui.Essentials;
global using Rectangle = Microsoft.Maui.Graphics.Rectangle;
#if __NET6__
global using EssentialsEx = Microsoft.Maui.ApplicationModel;
global using Microsoft.Maui.ApplicationModel;
global using Rectangle = Microsoft.Maui.Graphics.Rect;
#elif __MOBILE__
global using EssentialsEx = Xamarin.Essentials;
global using Xamarin.Essentials;
#endif
#if XAMARIN_IOS
#if __IOS__ && !__NET6__
global using Rectangle = System.Drawing.Rectangle;
#endif
#if MONOANDROID11_0 || NET6_0_ANDROID
#if MONOANDROID12_0 || MONOANDROID11_0 || (__NET6__ && __DROID__)
global using MediaColumns = Android.Provider.MediaStore.IMediaColumns;
#elif MONOANDROID10_0
global using MediaColumns = Android.Provider.MediaStore.MediaColumns;
Expand Down
6 changes: 3 additions & 3 deletions MediaGallery/Usings/UsingsHelper.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
static class UsingsHelper
{
public static Rectangle EmptyRectangle =>
#if NET6_0_IOS
#if __NET6__
Rectangle.Zero;
#else
Rectangle.Empty;
#endif

public static CGRect AsCGRect(this Rectangle rect) =>
#if NET6_0_IOS
new CGRect((nfloat)rect.X, (nfloat)rect.Y, (nfloat)rect.Width, (nfloat)rect.Height);
#if __NET6__
new CGRect((float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height);
#else
rect.ToPlatformRectangle();
#endif
Expand Down
10 changes: 6 additions & 4 deletions Permission/Maui/Permission.Maui.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.38">
<Project Sdk="MSBuild.Sdk.Extras/3.0.44">
<PropertyGroup>
<TargetFrameworks>net6.0;net6.0-ios;net6.0-android;</TargetFrameworks>
<TargetFrameworks>net6.0-ios;net6.0-android;Xamarin.iOS10;MonoAndroid10.0;MonoAndroid11.0;MonoAndroid12.0;</TargetFrameworks>
<AssemblyName>NativeMedia.Permision.Maui</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<PackageId>Xamarin.MediaGallery.Permision.Maui</PackageId>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Configurations>Release;Debug</Configurations>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<UseMauiEssentials>true</UseMauiEssentials>
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net6')) ">
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>
Expand Down
7 changes: 5 additions & 2 deletions Permission/Xamarim.MediaGallery.Permission.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<PackageTags>maui, xamarin, .net6, 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>2.0.0</Version>
<Version>2.1.2</Version>
<Authors>dimonovdd</Authors>
<Owners>dimonovdd</Owners>
<RepositoryUrl>https://github.com/dimonovdd/Xamarin.MediaGallery</RepositoryUrl>
Expand All @@ -30,14 +30,17 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" !$(TargetFramework.StartsWith('net6')) ">
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE" PackagePath="" Pack="true" />
<None Include="..\..\icon.png" PackagePath="" Pack="true" />
<None Include="..\..\README.md" PackagePath="" Pack="true" />
<Compile Include="..\src\**\*.shared.cs" />
<Compile Include="..\src\**\*.shared.*.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' OR $(TargetFramework.StartsWith('netstandard')) ">
<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
<Compile Include="..\src\**\*.netstandard.cs" />
<Compile Include="..\src\**\*.netstandard.*.cs" />
</ItemGroup>
Expand Down
7 changes: 2 additions & 5 deletions Permission/Xamarin/Permission.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.38">
<Project Sdk="MSBuild.Sdk.Extras/3.0.44">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;Xamarin.iOS10;MonoAndroid10.0;MonoAndroid11.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;Xamarin.iOS10;MonoAndroid10.0;MonoAndroid11.0;MonoAndroid12.0;</TargetFrameworks>
<AssemblyName>NativeMedia.Permision</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<PackageId>Xamarin.MediaGallery.Permision</PackageId>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Configurations>Release;Debug</Configurations>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
</ItemGroup>

<Import Project="..\Xamarim.MediaGallery.Permission.targets" />
</Project>
4 changes: 2 additions & 2 deletions Permission/src/Usings/GlobalUsings.shared.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if NET6_0 || NET6_0_ANDROID || NET6_0_IOS
global using EssentialsEx = Microsoft.Maui.Essentials;
global using Microsoft.Maui.Essentials;
global using EssentialsEx = Microsoft.Maui.ApplicationModel;
global using Microsoft.Maui.ApplicationModel;
#else
global using EssentialsEx = Xamarin.Essentials;
global using Xamarin.Essentials;
Expand Down
16 changes: 0 additions & 16 deletions Sample/Common/GlobalUsings.cs

This file was deleted.

3 changes: 3 additions & 0 deletions Sample/Common/Maui/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>
File renamed without changes.
17 changes: 17 additions & 0 deletions Sample/Common/Maui/Sample.Common.Maui.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.44">

<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<SupportedOSPlatformVersion Condition="'$(_IOS)' == 'true'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(_Droid)' == 'true'">21.0</SupportedOSPlatformVersion>
</PropertyGroup>

<Import Project="..\Sample.Common.targets" />
<Import Project="..\..\..\Xamarim.MediaGallery.targets" />
</Project>
43 changes: 0 additions & 43 deletions Sample/Common/Sample.Common.csproj

This file was deleted.

34 changes: 34 additions & 0 deletions Sample/Common/Sample.Common.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project>

<PropertyGroup>
<AssemblyName>Sample.Common</AssemblyName>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<EnableDefaultCompileItems>true</EnableDefaultCompileItems>
<LangVersion>10.0</LangVersion>
<DefineConstants Condition=" $(TargetFramework.StartsWith('net6')) ">$(DefineConstants);__NET6__;</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MetadataExtractor" Version="2.7.1" />
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Fody" Version="6.6.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\..\..\TestResources\*" Link="TestResources\%(Filename)%(Extension)" />
<Compile Include="..\src\**\*.cs" />
<None Include="..\src\**\*.xml" />
<None Include="..\src\**\*.xsd" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions Sample/Common/Xamarin/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>
Loading

0 comments on commit 368087e

Please sign in to comment.