Skip to content

Commit

Permalink
Merge branch 'master' into feature/signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxJohansen committed Jul 4, 2018
2 parents 77bdc07 + 84788e4 commit 9909e76
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 24 deletions.
36 changes: 36 additions & 0 deletions Diplomatic.Android/Classes/Picture_Droid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Android.Content;
using Android.Net;
using Diplomatic.Droid.Classes;
using Diplomatic.Interfaces;
using Java.IO;

[assembly: Xamarin.Forms.Dependency(typeof(Picture_Droid))]

namespace Diplomatic.Droid.Classes
{
public class Picture_Droid : IPicture
{
public void SavePictureToDisk(string filename, byte[] imageArray)
{
File dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);
string pictures = dir.Path;

string FilePath = System.IO.Path.Combine(pictures, filename+".png");
try
{
// Write file to the android disk
System.IO.File.WriteAllBytes(FilePath, imageArray);

// Now it needs to be added to image gallery
var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
mediaScanIntent.SetData(Android.Net.Uri.FromFile(new File(FilePath)));
Android.App.Application.Context.SendBroadcast(mediaScanIntent);
}
catch (System.Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SplashScreen.cs" />
<Compile Include="Classes\Picture_Droid.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
Expand Down Expand Up @@ -106,5 +107,8 @@
<ItemGroup>
<AndroidResource Include="Resources\drawable\splash.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Classes\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Diplomatic.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.Diplomatic" android:installLocation="auto">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="Diplomatic.Android" android:icon="@drawable/icon512"></application>
</manifest>
2 changes: 2 additions & 0 deletions Diplomatic.Android/Resources/drawable/splash_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
android:gravity="center"/>
</item>
</layer-list>

<!---->
24 changes: 24 additions & 0 deletions Diplomatic.iOS/Classes/Picture_iOS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Diplomatic.Interfaces;
using Diplomatic.iOS.Classes;
using Foundation;
using UIKit;

[assembly: Xamarin.Forms.Dependency(typeof(Picture_iOS))]
namespace Diplomatic.iOS.Classes
{
public class Picture_iOS : IPicture
{
public void SavePictureToDisk(string filename, byte[] imageArray)
{
var Img = new UIImage(NSData.FromArray(imageArray));
Img.SaveToPhotosAlbum((image, error) =>
{
if (error != null)
{
Console.WriteLine(error);
}
});
}
}
}
1 change: 1 addition & 0 deletions Diplomatic.iOS/Diplomatic.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<None Include="Entitlements.plist" />
<None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Classes\Picture_iOS.cs" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Icon-1024.png">
Expand Down
4 changes: 3 additions & 1 deletion Diplomatic.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>11.0</string>
<key>CFBundleDisplayName</key>
<string>Diplomatic</string>
<key>CFBundleIdentifier</key>
Expand All @@ -36,5 +36,7 @@
<string>Assets.xcassets/AppIcon.appiconset</string>
<key>XSLaunchImageAssets</key>
<string>Assets.xcassets/LaunchImage.launchimage</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string></string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions Diplomatic.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Diplomatic", "Diplomatic\Diplomatic.csproj", "{CDB8B215-5C59-4F03-A016-E3C7A8DEABCC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diplomatic", "Diplomatic\Diplomatic.csproj", "{CDB8B215-5C59-4F03-A016-E3C7A8DEABCC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diplomatic.Android", "Diplomatic.Android\Diplomatic.Android.csproj", "{86FD3DB4-B1E4-4FDF-9442-01A9ADC6FAB7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diplomatic.Droid", "Diplomatic.Android\Diplomatic.Droid.csproj", "{86FD3DB4-B1E4-4FDF-9442-01A9ADC6FAB7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diplomatic.iOS", "Diplomatic.iOS\Diplomatic.iOS.csproj", "{EE7E1D42-0BF7-4A64-A8CF-29014B444061}"
EndProject
Expand Down
23 changes: 23 additions & 0 deletions Diplomatic/App.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Diplomatic.Utils.Triggers"
x:Class="Diplomatic.App">
<Application.Resources>
<Color x:Key="backgroundColor">#e5f4f2</Color>
Expand All @@ -15,6 +16,28 @@
<Setter Property="WidthRequest" Value="75" />
</Style>

<Style TargetType="Label">
<Setter Property="Opacity" Value="1"/>
<Style.Triggers>
<Trigger TargetType="Label"
Property="IsVisible" Value="True">
<Trigger.EnterActions>
<local:OpacityTriggerAction StartsFrom="0"/>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="Entry">
<Setter Property="Opacity" Value="0.75"/>
<Style.Triggers>
<Trigger TargetType="Entry"
Property="IsFocused" Value="True">
<Setter Property="Opacity" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>

<OnPlatform
x:Key="EntryMargins"
x:TypeArguments="Thickness"
Expand Down
1 change: 1 addition & 0 deletions Diplomatic/Diplomatic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
<Folder Include="Interfaces\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Views\Result.xaml">
Expand Down
8 changes: 8 additions & 0 deletions Diplomatic/Interfaces/IPicture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
namespace Diplomatic.Interfaces
{
public interface IPicture
{
void SavePictureToDisk(string filename, byte[] imageArray);
}
}
8 changes: 4 additions & 4 deletions Diplomatic/Utils/Behaviors/FormatValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using Xamarin.Forms;

namespace Diplomatic.Utils.Behaviors
Expand All @@ -20,9 +20,9 @@ protected override void OnDetachingFrom(Entry entry)

public void ValidateFormat(object sender, TextChangedEventArgs args)
{
string text = (sender as Entry).Text;
var regex = new Regex(Pattern, RegexOptions.Compiled);
(sender as Entry).TextColor = regex.IsMatch(text) ? Color.Default : Color.Red;
var entry = (Entry)sender;
string text = entry.Text;
entry.TextColor = Regex.IsMatch(text, Pattern) ? Color.Default : Color.Red;
}
}
}
23 changes: 23 additions & 0 deletions Diplomatic/Utils/Triggers/OpacityAnimation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;

namespace Diplomatic.Utils.Triggers
{
public class OpacityTriggerAction : TriggerAction<VisualElement>
{
public int StartsFrom { set; get; } = 0;

protected override void Invoke(VisualElement visual)
{
visual.Animate("label", new Animation((d) => {
var val = StartsFrom == 0 ? d : 1 - d;
visual.Opacity = val;

}),
length: 500,
easing: Easing.Linear);
}
}
}
2 changes: 1 addition & 1 deletion Diplomatic/Utils/Triggers/ScaleAnimation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Xamarin.Forms;
using Xamarin.Forms;

namespace Diplomatic.Utils.Triggers
{
Expand Down
7 changes: 6 additions & 1 deletion Diplomatic/ViewModels/ResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Diplomatic.ViewModels
public class ResultViewModel
{
public Uri ImageUri { get; }
public ResultViewModel(Uri imageuri) => ImageUri = imageuri;
public string Filename { get; set; }
public ResultViewModel(Uri imageuri, string filename)
{
ImageUri = imageuri;
Filename = filename;
}
}
}
7 changes: 6 additions & 1 deletion Diplomatic/Views/Result.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Diplomatic.Views.Result">
x:Class="Diplomatic.Views.Result"
Title="Result">
<ContentPage.ToolbarItems>
<ToolbarItem Name="Save" Order="Primary" Text="Save" Priority="1" Activated="SaveButtonClicked" />
<ToolbarItem Name="Share" Order="Primary" Text="Share" Priority="2" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout>
<Image x:Name="theImage" Source="{Binding ImageUri}"/>
Expand Down
34 changes: 21 additions & 13 deletions Diplomatic/Views/Result.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Net;
using Diplomatic.Interfaces;
using Diplomatic.ViewModels;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Diplomatic.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Result : ContentPage
{
public Result ()
{
InitializeComponent ();
}
}
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Result : ContentPage
{
public Result()
{
InitializeComponent();
}
public async void SaveButtonClicked(object sender, EventArgs e)
{
using (var webClient = new WebClient())
{
string Filename = ((ResultViewModel)BindingContext).Filename;
byte[] imageBytes = await webClient.DownloadDataTaskAsync(((ResultViewModel)BindingContext).ImageUri);
DependencyService.Get<IPicture>().SavePictureToDisk(Filename, imageBytes);
await DisplayAlert("Save diploma", "Your diploma has been saved!", "OK");
}
}
}
}
4 changes: 3 additions & 1 deletion Diplomatic/Views/Signatures.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ async void NextPage(object sender, SelectedItemChangedEventArgs e)
{
Template template = ((SignaturePickerViewModel)BindingContext).SelectedTemplate;
template.Signature = (Signature)e.SelectedItem;
string Filename = template.TemplateName + "_";
var queryParams = new List<string> { };
foreach (Field field in template.Fields)
{
Filename += field.Name + "_" + field.Value +"_";
queryParams.Add($"{field.Name.ToLower()}={field.Value}");
}
queryParams.Add($"signature={template.Signature.Id}");
Expand All @@ -30,7 +32,7 @@ async void NextPage(object sender, SelectedItemChangedEventArgs e)
var endpoint = new Uri(Uri.EscapeUriString(final));
var next = new Result
{
BindingContext = new ResultViewModel(endpoint)
BindingContext = new ResultViewModel(endpoint, Filename)
};
await Navigation.PushAsync(next);
}
Expand Down

0 comments on commit 9909e76

Please sign in to comment.