-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathResultsPage.xaml.cs
96 lines (80 loc) · 3.47 KB
/
ResultsPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Anyline.Examples.MAUI.Models;
using Microsoft.Maui.Controls.Shapes;
namespace Anyline.Examples.MAUI;
public partial class ResultsPage : ContentPage
{
/// <summary>
/// This page is reponsible for displaying the scan results.
/// It is built in a generic way to support any scan mode, but in your use-case, it is recommended to work only with a strongly typed object in the MAUI layer.
/// </summary>
/// <param name="results"></param>
/// <param name="scanMode">Object containing the Name of the ScanMode and the JSON config file path (used for re-initializing the ScanView page)</param>
public ResultsPage(Dictionary<string, object> results, AnylineScanMode scanMode)
{
InitializeComponent();
Task.Run(() => ShowResults(results));
btHome.Clicked += async (s, e) => await Navigation.PopToRootAsync();
btScanAgain.Clicked += (s, e) =>
{
MainThread.BeginInvokeOnMainThread(async () =>
{
Navigation.InsertPageBefore(new MyScanningWithAnylinePage(scanMode), this);
await Navigation.PopAsync();
});
};
}
private void ShowResults(Dictionary<string, object> results)
{
View viewResults = CreateResultView(results);
MainThread.BeginInvokeOnMainThread(() =>
{
cvContent.Content = viewResults;
// workaround for the ScrollView height misscalculation on iOS
// when dynamically loading content into the layout.
var scrollView = new ScrollView();
scrollView.Content = Content;
Content = scrollView;
});
}
private View CreateResultView(Dictionary<string, object> dict)
{
StackLayout slItemResults = new StackLayout() { Padding = new Thickness(5, 0, 0, 0) };
foreach (var item in dict)
{
string[] name_type = item.Key.Split(' ');
var formmattedString = new FormattedString();
formmattedString.Spans.Add(new Span() { Text = name_type[0] + " ", TextColor = Color.FromArgb("32ADFF"), FontSize = 15, FontAttributes = FontAttributes.Bold });
formmattedString.Spans.Add(new Span() { Text = name_type[1], TextColor = Color.FromArgb("32ADFF"), FontSize = 10 });
slItemResults.Children.Add(new Label() { FormattedText = formmattedString });
if (item.Value is byte[] imageBytes)
{
var img = new Image()
{
Aspect = Aspect.AspectFit,
HeightRequest = 100,
Source = ImageSource.FromStream(() => new MemoryStream(imageBytes))
};
slItemResults.Children.Add(img);
}
else if (item.Value is Dictionary<string, object> subItems)
{
slItemResults.Children.Add(CreateResultView(subItems));
}
else
{
slItemResults.Children.Add(new Label { Text = item.Value.ToString(), TextColor = Colors.White, FontAttributes = FontAttributes.Bold, FontSize = 17 });
}
}
Grid grContent = new Grid()
{
ColumnDefinitions =
{
new ColumnDefinition(new GridLength(0.3)),
new ColumnDefinition(GridLength.Star)
}
};
grContent.Add(new BoxView { Color = Colors.Gray }, 0, 0);
grContent.Add(slItemResults, 1, 0);
return grContent;
}
}