| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- using System.Collections.Generic;
- using System.Linq;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- namespace PRS.Mobile
- {
- public class DigitalFormMultiSignature : Grid, IDigitalFormField<DFLayoutMultiSignaturePad, DFLayoutMultiSignaturePadProperties, Dictionary<string, byte[]>, Dictionary<string, byte[]>?>
- {
- private readonly CollectionView _images;
- private readonly MobileCard _frame;
- private readonly MobileButton _add;
- private readonly MobileButton _select;
- private readonly MobileButton _clear;
-
- private DFLayoutMultiSignaturePad? _definition;
- public DFLayoutMultiSignaturePad? Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value ?? new DFLayoutMultiSignaturePad());
- }
- }
-
- private Dictionary<string, byte[]> _value = new Dictionary<string, byte[]>();
- public Dictionary<string, byte[]> Value
- {
- get => _value;
- set
- {
- _value = value;
- DoUpdateUI();
- }
- }
-
- public bool IsEmpty => Value.Any() != true;
- private void DoUpdateUI()
- {
- _images.ItemsSource = null;
- _images.ItemsSource = _value.ToArray();
- }
- private bool _readOnly;
- public bool ReadOnly
- {
- get => _readOnly;
- set
- {
- _readOnly = value;
- UpdateStatus();
- }
- }
-
- public void Deserialize(DFLoadStorageEntry entry)
- {
- _value = Definition?.Properties.DeserializeValue(entry) ?? new Dictionary<string, byte[]>();
- DoUpdateUI();
- }
- public void Serialize(DFSaveStorageEntry entry)
- {
- Definition?.Properties.SerializeValue(entry,_value);
- }
-
- public event DigitalFormViewChangedHandler? ValueChanged;
- public DigitalFormMultiSignature()
- {
-
- HeightRequest = 200;
-
- ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });
- ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
-
- RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
- RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
- RowDefinitions.Add(new RowDefinition() { Height = GridLength.Star });
- RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
- _images = new CollectionView()
- {
- ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) { ItemSpacing = 10 },
- ItemSizingStrategy = ItemSizingStrategy.MeasureAllItems,
- ItemTemplate = new DataTemplate(() =>
- {
- var image = new Image()
- {
- Aspect = Aspect.AspectFit,
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.FillAndExpand,
- WidthRequest = 200,
- Margin = new Thickness(10),
- };
- image.SetBinding(Image.SourceProperty, new Binding("Value",BindingMode.Default,new ByteArrayToImageSourceConverter()));
- image.SetValue(Grid.RowProperty,0);
- image.SetValue(Grid.ColumnProperty,0);
- image.SetValue(Grid.ColumnSpanProperty,2);
-
- var label = new Label()
- {
- HorizontalOptions = LayoutOptions.Fill,
- HorizontalTextAlignment = TextAlignment.Center
- };
- label.SetBinding(Image.SourceProperty, new Binding("Key"));
- label.SetValue(Grid.RowProperty,1);
- label.SetValue(Grid.ColumnProperty,0);
-
- var button = new MobileMenuButton()
- {
- Image = ImageSource.FromFile("cross")
- };
- button.Clicked += (sender, args) =>
- {
- /* DoDelete functionality here*/
- };
- button.SetValue(Grid.RowProperty,1);
- button.SetValue(Grid.ColumnProperty,1);
- var grid = new Grid();
- grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Star });
- grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
- grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });
- grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
- grid.Children.Add(image);
- grid.Children.Add(label);
- grid.Children.Add(button);
-
- var frame = new MobileCard()
- {
- BorderColor = Color.White,
- BackgroundColor = Color.White,
- CornerRadius = 5,
- Content = grid
- };
-
- return frame;
- }),
- };
- _frame = new MobileCard()
- {
- Content = _images,
- Padding = 10
- };
- _frame.SetValue(Grid.RowProperty,0);
- _frame.SetValue(Grid.ColumnProperty,0);
- _frame.SetValue(Grid.RowSpanProperty,4);
- Children.Add(_frame);
-
- _add = new MobileButton()
- {
- Image = ImageSource.FromFile("plus"),
- Orientation = StackOrientation.Horizontal,
- WidthRequest = 40,
- HeightRequest = 40,
- CornerRadius = 5
- };
- _add.Clicked += (sender, args) =>
- {
-
- };
- _add.SetValue(Grid.RowProperty,0);
- _add.SetValue(Grid.ColumnProperty,1);
- Children.Add(_add);
-
- _select = new MobileButton()
- {
- Image = ImageSource.FromFile("photolibrary"),
- Orientation = StackOrientation.Horizontal,
- WidthRequest = 40,
- HeightRequest = 40,
- CornerRadius = 5
- };
- _select.Clicked += (sender, args) =>
- {
-
- };
- _select.SetValue(Grid.RowProperty,1);
- _select.SetValue(Grid.ColumnProperty,1);
- Children.Add(_select);
-
- _clear = new MobileButton()
- {
- Image = ImageSource.FromFile("cross"),
- Orientation = StackOrientation.Horizontal,
- WidthRequest = 40,
- HeightRequest = 40,
- CornerRadius = 5
-
- };
- _clear.Clicked += (sender, args) =>
- {
-
- };
- _clear.SetValue(Grid.RowProperty,3);
- _clear.SetValue(Grid.ColumnProperty,1);
- Children.Add(_clear);
- }
-
- private void Initialize(DFLayoutMultiSignaturePad value)
- {
- UpdateStatus();
- }
-
- protected bool Secure => Definition?.Properties.Secure ?? false;
- protected bool Required => Definition?.Properties.Required ?? false;
-
- private void UpdateStatus()
- {
- bool enabled = !_readOnly && !Secure;
- _add.IsEnabled = enabled;
- _clear.IsEnabled = enabled;
-
- var colors = DigitalFormUtils.GetColors(!enabled, Required, false);
- _frame.BackgroundColor = colors.Background;
- _frame.BorderColor = colors.Border;
-
- colors = DigitalFormUtils.GetColors(!enabled, Required, true);
- _add.BackgroundColor = colors.Background;
- _add.BorderColor = colors.Border;
-
- _clear.BackgroundColor = colors.Background;
- _clear.BorderColor = colors.Border;
- }
- }
- }
|