Skip to content

Commit

Permalink
Share pdf file to this app and render it Android/IOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeljko-Predjeskovic committed Oct 18, 2022
1 parent 3899836 commit 6c9a0ab
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 33 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build
on:
push:
branches: [ feature/github_workflow ]
pull_request:
branches: [ master ]

jobs:
Build:
runs-on: [windows-latest]

steps:
- uses: actions/checkout@v2

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1

- name: Setup NuGet
uses: NuGet/[email protected]

- name: Restore NuGet packages
run: nuget restore iCL.DocumentConverter.sln

- name: Build the Solution
run: msbuild iCL.DocumentConverter.sln /p:Configuration=Release
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test

on:
push:
branches: [ feature/github_workflow ]
pull_request:
branches: [ master ]

jobs:
Build:
runs-on: [windows-latest]

steps:
- uses: actions/checkout@v2
with:
dotnet-version: 6.0.x

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1

- name: Execute unit tests
run: dotnet test
2 changes: 1 addition & 1 deletion iCL.DocumentConverter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocumentConverter.Tests", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentPicker.Droid", "src\DocumentPicker.Droid\DocumentPicker.Droid.csproj", "{F7830ABA-CFCF-481C-9AB7-D5973FFE9B85}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentConverter.Benchmark", "tests\DocumentConverter.Benchmark\DocumentConverter.Benchmark.csproj", "{0275CD62-6BB8-4DBF-91B1-EB54CB18A184}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocumentConverter.Benchmark", "tests\DocumentConverter.Benchmark\DocumentConverter.Benchmark.csproj", "{0275CD62-6BB8-4DBF-91B1-EB54CB18A184}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
81 changes: 80 additions & 1 deletion src/DocumentPicker.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,109 @@
using Android.App;
using System.IO;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Net;
using Android.OS;
using Android.Provider;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using DocumentConverter.Plugin.Shared;
using DocumentConverter.Plugin.Shared.FileSharing;
using DocumentConverter.Plugin.Shared.StreamProvider;
using DocumentPicker.Samples;
using DocumentPicker.Samples.NotifyVisibility;
using Svg;

namespace DocumentPicker.Droid
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = @"application/pdf")]
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
LoadApp(bundle);


if (Intent.ActionSend.Equals(Intent?.Action) &&
Intent.Type != null &&
"application/pdf".Equals(Intent.Type))
{
// This is just an example of the data stored in the extras
var uriFromExtras = Intent.GetParcelableExtra(Intent.ExtraStream) as Android.Net.Uri;
var subject = Intent.GetStringExtra(Intent.ExtraSubject);

// Get the info from ClipData
var pdf = Intent.ClipData.GetItemAt(0);

// Open a stream from the URI
var pdfStream = ContentResolver.OpenInputStream(pdf.Uri);

SharedStream.Instance = pdfStream;
SharedVisibles.ShowShareViews();

//Save off the path and description here
//Remove dialog and navigate back to app or browser that shared
//the link
}
}

private void LoadApp(Bundle bundle)
{
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
Xamarin.Essentials.Platform.Init(this, bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SvgPlatform.Init();
LoadApplication(new App());
}

//private Stream GetFileStream(Uri uri)
//{

// // Get the info from ClipData
// var pdf = Intent.ClipData.GetItemAt(0);

// // Open a stream from the URI
// var pdfStream = ContentResolver.OpenInputStream(pdf.Uri);


// return pdfStream;
//}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

//private void handleSendUrl()
//{
// var view = new LinearLayout(this) { Orientation = Orientation.Vertical };
// var url = Intent.GetStringExtra(Intent.ExtraText);

// var urlTextView = new TextView(this) { Gravity = GravityFlags.Center };
// urlTextView.Text = url;

// view.AddView(urlTextView);
// var description = new EditText(this) { Gravity = GravityFlags.Top };
// view.AddView(description);

// new AlertDialog.Builder(this)
// .SetTitle("Save a URL Link")
// .SetMessage("Type a description for your link")
// .SetView(view)
// .SetPositiveButton("Add", (dialog, whichButton) =>
// {
// var desc = description.Text;
// //Save off the url and description here
// //Remove dialog and navigate back to app or browser that shared
// //the link
// FinishAndRemoveTask();
// FinishAffinity();
// })
// .Show();
//}
}
}
2 changes: 1 addition & 1 deletion src/DocumentPicker.Droid/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyTitle("DocumentPicker.Droid")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Optiq")]
[assembly: AssemblyProduct("DocumentPicker.Droid")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
Expand Down
24 changes: 21 additions & 3 deletions src/DocumentPicker.IOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using DocumentConverter.Plugin.Shared.StreamProvider;
using DocumentConverter.Plugin.Shared.FileSharing;
using DocumentConverter.Plugin.Shared.StreamProvider;
using DocumentPicker.Samples;
using DocumentPicker.Samples.NotifyVisibility;
using Foundation;
using Svg;
using UIKit;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace DocumentPicker.IOS
{
Expand All @@ -20,15 +24,29 @@ public override UIWindow Window
}

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
LoadApp();
return base.FinishedLaunching(app, options);
}

public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
SharedStream.Instance = System.IO.File.Open(url.Path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);

SharedVisibles.ShowShareViews();

return true;
}

private void LoadApp()
{
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
Xamarin.Forms.Forms.Init();
SvgPlatform.Init();
LoadApplication(new App());

return base.FinishedLaunching(app, options);
}


public override void OnResignActivation(UIApplication application)
{
// Invoked when the application is about to move from active to inactive state.
Expand Down
15 changes: 15 additions & 0 deletions src/DocumentPicker.IOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
</dict>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
Expand Down
5 changes: 1 addition & 4 deletions src/DocumentPicker.Plugin/DocumentConverter.Plugin.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="MSBuild.Sdk.Extras/2.0.54">
<Project Sdk="MSBuild.Sdk.Extras/2.0.54">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;MonoAndroid90;Xamarin.iOS10;uap10.0.17763</TargetFrameworks>
Expand All @@ -17,11 +17,8 @@

<ItemGroup Condition=" $(TargetFramework.StartsWith('uap')) ">
<Compile Include="Platforms\UniversalWindows\**\*.cs" />

<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.14" />

<Folder Include="Platforms\UniversalWindows\" />
</ItemGroup>


</Project>
22 changes: 22 additions & 0 deletions src/DocumentPicker.Plugin/Shared/FileSharing/SharedStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.IO;
using DocumentConverter.Plugin.Shared.StreamProvider;

namespace DocumentConverter.Plugin.Shared.FileSharing
{
public static class SharedStream
{
private static Stream _stream;

public static Stream Instance
{
get => _stream;
set => _stream = value;
}

public static void DisposeStream()
{
Instance.Dispose();
}
}
}
2 changes: 2 additions & 0 deletions src/DocumentPicker.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DocumentConverter.Plugin.Shared.StreamProvider;
using DocumentPicker.Samples.NotifyVisibility;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

Expand All @@ -13,6 +14,7 @@ public App()

CustomStreamProviderInitializer.Init();
MainPage = new NavigationPage(new DocumentPickerPage());
SharedVisibles.Init();
}

protected override void OnStart()
Expand Down
7 changes: 7 additions & 0 deletions src/DocumentPicker.Sample/DocumentPicker.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,6 +20,12 @@
<EmbeddedResource Update="DocumentPickerPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="PartialViews\ShareButton.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="PartialViews\ShareNotification.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions src/DocumentPicker.Sample/DocumentPickerPage.xaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mynamespace="clr-namespace:DocumentPicker.Samples.PartialViews;assembly=DocumentPicker.Samples"
x:Class="DocumentPicker.Samples.DocumentPickerPage"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="True">


<StackLayout Spacing="10" Padding="10">
<Label Text="Document Picker"></Label>
<mynamespace:ShareNotification x:Name="Notification"></mynamespace:ShareNotification>
<Grid x:Name="Grid">

</Grid>
<Button x:Name="pickDocument" Text="Pick Document"/>
<mynamespace:ShareButton x:Name="shareButton"></mynamespace:ShareButton>
<StackLayout Orientation="Horizontal">
</StackLayout>
<ScrollView>
Expand Down
Loading

0 comments on commit 6c9a0ab

Please sign in to comment.