Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

[WIP] Permission plugin #83

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions MvvmCross.Plugins.sln
Expand Up @@ -295,6 +295,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ResxLocalization", "ResxLoc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmCross.Plugins.ResxLocalization", "ResxLocalization\MvvmCross.Plugins.ResxLocalization\MvvmCross.Plugins.ResxLocalization.csproj", "{8AE35C8E-CC76-4E4C-98F8-CA68FBCB550B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Permissions", "Permissions", "{7C59A18B-E10F-41EA-9CF0-1A45FF02F901}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmCross.Plugins.Permissions", "Permissions\Core\MvvmCross.Plugins.Permissions.csproj", "{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -2243,6 +2247,22 @@ Global
{8AE35C8E-CC76-4E4C-98F8-CA68FBCB550B}.Release|x64.Build.0 = Release|Any CPU
{8AE35C8E-CC76-4E4C-98F8-CA68FBCB550B}.Release|x86.ActiveCfg = Release|Any CPU
{8AE35C8E-CC76-4E4C-98F8-CA68FBCB550B}.Release|x86.Build.0 = Release|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Debug|ARM.ActiveCfg = Debug|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Debug|ARM.Build.0 = Debug|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Debug|x64.ActiveCfg = Debug|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Debug|x64.Build.0 = Debug|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Debug|x86.ActiveCfg = Debug|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Debug|x86.Build.0 = Debug|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Release|Any CPU.Build.0 = Release|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Release|ARM.ActiveCfg = Release|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Release|ARM.Build.0 = Release|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Release|x64.ActiveCfg = Release|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Release|x64.Build.0 = Release|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Release|x86.ActiveCfg = Release|Any CPU
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2369,5 +2389,6 @@ Global
{BFD90EC2-CBDA-4198-81DA-1A13AD2803E1} = {D9F520C0-4C25-465B-9C16-CADDDE3E72B8}
{19B4DBB9-F476-433E-9DD2-37DEFE2CECA6} = {9B45C8EC-18B9-4A88-950E-8D8FF8FAA1DA}
{8AE35C8E-CC76-4E4C-98F8-CA68FBCB550B} = {8D6F4620-D8BD-4E14-B698-4998138EEA32}
{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841} = {7C59A18B-E10F-41EA-9CF0-1A45FF02F901}
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions Permissions/Core/IMvxPermissions.cs
@@ -0,0 +1,9 @@
using Plugin.Permissions.Abstractions;

namespace MvvmCross.Plugins.Permissions
{
public interface IMvxPermissions : IPermissions
{

}
}
71 changes: 71 additions & 0 deletions Permissions/Core/MvvmCross.Plugins.Permissions.csproj
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B3B46E7E-CDA2-4297-8700-6E8EBBE3A841}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MvvmCross.Plugins.Permissions</RootNamespace>
<AssemblyName>MvvmCross.Plugins.Permissions</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug\Mvx\Portable\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release\Mvx\Portable\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="IMvxPermissions.cs" />
<Compile Include="MvxPermissions.cs" />
<Compile Include="PluginLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="MvvmCross.Core, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\MvvmCross.Core.4.1.0\lib\portable-net45+win+wpa81+wp80\MvvmCross.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MvvmCross.Platform, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\MvvmCross.Platform.4.1.0\lib\portable-net45+win+wpa81+wp80\MvvmCross.Platform.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Plugin.Permissions, Version=1.1.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Plugin.Permissions.1.1.7\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Permissions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Plugin.Permissions.Abstractions, Version=1.1.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Plugin.Permissions.1.1.7\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Permissions.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
25 changes: 25 additions & 0 deletions Permissions/Core/MvxPermissions.cs
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Plugin.Permissions;
using Plugin.Permissions.Abstractions;

namespace MvvmCross.Plugins.Permissions
{
public class MvxPermissions : IMvxPermissions
{
public Task<bool> ShouldShowRequestPermissionRationaleAsync(Permission permission)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be async await?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to create an unnecessary context sync / wrap I believe, just pass the Task to the caller.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing wrong with this. No need to await it here, you can just pass the task along.

{
return CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(permission);
}

public Task<PermissionStatus> CheckPermissionStatusAsync(Permission permission)
{
return CrossPermissions.Current.CheckPermissionStatusAsync(permission);
}

public Task<Dictionary<Permission, PermissionStatus>> RequestPermissionsAsync(params Permission[] permissions)
{
return CrossPermissions.Current.RequestPermissionsAsync(permissions);
}
}
}
29 changes: 29 additions & 0 deletions Permissions/Core/PluginLoader.cs
@@ -0,0 +1,29 @@
// PluginLoader.cs
// (c) Copyright Cirrious Ltd. http://www.cirrious.com
// MvvmCross is licensed using Microsoft Public License (Ms-PL)
// Contributions and inspirations noted in readme.md and license.txt

using MvvmCross.Platform;
using MvvmCross.Platform.Plugins;

namespace MvvmCross.Plugins.Permissions
{
public class PluginLoader
: IMvxPluginLoader
{
public static readonly PluginLoader Instance = new PluginLoader();

private bool _loaded;

public void EnsureLoaded()
{
if (_loaded)
{
return;
}

Mvx.RegisterSingleton<IMvxPermissions>(new MvxPermissions());
_loaded = true;
}
}
}
30 changes: 30 additions & 0 deletions Permissions/Core/Properties/AssemblyInfo.cs
@@ -0,0 +1,30 @@
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Core")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Core")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
6 changes: 6 additions & 0 deletions Permissions/Core/packages.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MvvmCross.Core" version="4.1.0" targetFramework="portable45-net45+win8+wpa81" />
<package id="MvvmCross.Platform" version="4.1.0" targetFramework="portable45-net45+win8+wpa81" />
<package id="Plugin.Permissions" version="1.1.7" targetFramework="portable45-net45+win8+wpa81" />
</packages>