Skip to content

Commit 9e52de4

Browse files
jonjohansenMaxJohansen
authored andcommitted
Ground breaking new feature
Images now have names (Only available on an ANDROID near you)! Also Stuff looks clean now
1 parent b3f05a6 commit 9e52de4

6 files changed

Lines changed: 18 additions & 13 deletions

File tree

Diplomatic.Android/Classes/Picture_Droid.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ public class Picture_Droid : IPicture
1313
{
1414
public void SavePictureToDisk(string filename, byte[] imageArray)
1515
{
16-
var dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);
17-
var pictures = dir.Path;
16+
File dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);
17+
string pictures = dir.Path;
1818

1919
string FilePath = System.IO.Path.Combine(pictures, filename+".png");
2020
try
2121
{
2222
// Write file to the android disk
2323
System.IO.File.WriteAllBytes(FilePath, imageArray);
24+
2425
// Now it needs to be added to image gallery
2526
var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
2627
mediaScanIntent.SetData(Android.Net.Uri.FromFile(new File(FilePath)));
27-
Xamarin.Forms.Forms.Context.SendBroadcast(mediaScanIntent);
28+
Android.App.Application.Context.SendBroadcast(mediaScanIntent);
2829
}
29-
catch(System.Exception e)
30+
catch (System.Exception e)
3031
{
3132
System.Console.WriteLine(e.ToString());
3233
}

Diplomatic.iOS/Classes/Picture_iOS.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace Diplomatic.iOS.Classes
99
{
1010
public class Picture_iOS : IPicture
1111
{
12-
1312
public void SavePictureToDisk(string filename, byte[] imageArray)
1413
{
1514
var Img = new UIImage(NSData.FromArray(imageArray));
@@ -18,7 +17,6 @@ public void SavePictureToDisk(string filename, byte[] imageArray)
1817
if (error != null)
1918
{
2019
Console.WriteLine(error);
21-
throw new Exception("Yeeeeeeeeeeeeeeeeeet");
2220
}
2321
});
2422
}

Diplomatic.iOS/Info.plist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<string>UIInterfaceOrientationLandscapeRight</string>
2222
</array>
2323
<key>MinimumOSVersion</key>
24-
<string>11.3</string>
24+
<string>11.0</string>
2525
<key>CFBundleDisplayName</key>
2626
<string>Diplomatic</string>
2727
<key>CFBundleIdentifier</key>
@@ -38,7 +38,5 @@
3838
<string>Assets.xcassets/LaunchImage.launchimage</string>
3939
<key>NSPhotoLibraryAddUsageDescription</key>
4040
<string></string>
41-
<key>NSPhotoLibraryUsageDescription</key>
42-
<string></string>
4341
</dict>
4442
</plist>

Diplomatic/ViewModels/ResultViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ namespace Diplomatic.ViewModels
55
public class ResultViewModel
66
{
77
public Uri ImageUri { get; }
8-
public ResultViewModel(Uri imageuri) => ImageUri = imageuri;
8+
public string Filename { get; set; }
9+
public ResultViewModel(Uri imageuri, string filename)
10+
{
11+
ImageUri = imageuri;
12+
Filename = filename;
13+
}
914
}
1015
}

Diplomatic/Views/Result.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ public async void SaveButtonClicked(object sender, EventArgs e)
1919
{
2020
using (var webClient = new WebClient())
2121
{
22+
string Filename = ((ResultViewModel)BindingContext).Filename;
2223
byte[] imageBytes = await webClient.DownloadDataTaskAsync(((ResultViewModel)BindingContext).ImageUri);
23-
DependencyService.Get<IPicture>().SavePictureToDisk("Navn", imageBytes);
24+
DependencyService.Get<IPicture>().SavePictureToDisk(Filename, imageBytes);
2425

25-
await DisplayAlert("Image save", "Your diploma has been saved!", "Ok");
26+
await DisplayAlert("Save diploma", "Your diploma has been saved!", "OK");
2627
}
2728
}
2829
}

Diplomatic/Views/Signatures.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ private async void NextPage(object sender, SelectedItemChangedEventArgs e)
1919
{
2020
Template template = ((SignaturePickerViewModel)BindingContext).SelectedTemplate;
2121
template.Signature = (Signature)e.SelectedItem;
22+
string Filename = template.TemplateName + "_";
2223
var queryParams = new List<string> { };
2324

2425
foreach (Field field in template.Fields)
2526
{
27+
Filename += field.Name + "_" + field.Value +"_";
2628
queryParams.Add($"{field.Name.ToLower()}={field.Value}");
2729
}
2830

@@ -32,7 +34,7 @@ private async void NextPage(object sender, SelectedItemChangedEventArgs e)
3234
var endpoint = new Uri(Uri.EscapeUriString(final));
3335
var next = new Result
3436
{
35-
BindingContext = new ResultViewModel(endpoint)
37+
BindingContext = new ResultViewModel(endpoint, Filename)
3638
};
3739

3840
await Navigation.PushAsync(next);

0 commit comments

Comments
 (0)