|
@@ -0,0 +1,174 @@
|
|
|
+using System.Linq;
|
|
|
+using InABox.Core;
|
|
|
+using InABox.Mobile;
|
|
|
+using Xamarin.Forms;
|
|
|
+
|
|
|
+namespace PRS.Mobile
|
|
|
+{
|
|
|
+ public abstract class DigitalFormEmbeddedMedia<T, TProperties> : MobileCard, IDigitalFormField<T,TProperties, byte[]>
|
|
|
+ where T : DFLayoutField<TProperties>, new()
|
|
|
+ where TProperties : DFLayoutFieldProperties<byte[]>, new()
|
|
|
+ {
|
|
|
+
|
|
|
+ protected abstract bool IsVideo { get; }
|
|
|
+
|
|
|
+ private readonly MobileButton _cameraButton;
|
|
|
+ private readonly Label _cameraLabel;
|
|
|
+ private readonly MobileButton _libraryButton;
|
|
|
+ private readonly Label _libraryLabel;
|
|
|
+
|
|
|
+ private T _definition;
|
|
|
+ public T Definition
|
|
|
+ {
|
|
|
+ get => _definition;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _definition = value;
|
|
|
+ Initialize(value ?? new T());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DigitalFormEmbeddedMediaValue _value;
|
|
|
+ public byte[] Value
|
|
|
+ {
|
|
|
+ get => _value.Data;
|
|
|
+ set => _value.Data = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool IsEmpty => Value?.Any() != true;
|
|
|
+
|
|
|
+ private bool _readOnly;
|
|
|
+
|
|
|
+ public bool ReadOnly
|
|
|
+ {
|
|
|
+ get => _readOnly;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _readOnly = value;
|
|
|
+ UpdateStatus();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Load(string value)
|
|
|
+ {
|
|
|
+ _value = new DigitalFormEmbeddedMediaValue(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public string Save()
|
|
|
+ {
|
|
|
+ return _value?.ToString() ?? "";
|
|
|
+ }
|
|
|
+
|
|
|
+ public event DigitalFormViewChangedHandler ValueChanged;
|
|
|
+
|
|
|
+ protected DigitalFormEmbeddedMedia()
|
|
|
+ {
|
|
|
+ Padding = new Thickness(10);
|
|
|
+ var grid = new Grid()
|
|
|
+ {
|
|
|
+ ColumnSpacing = 0,
|
|
|
+ RowSpacing = 0
|
|
|
+ };
|
|
|
+ grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
|
|
+ grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
|
|
|
+ grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
|
|
|
+ grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
|
|
|
+
|
|
|
+ _cameraButton = new MobileButton
|
|
|
+ {
|
|
|
+ Image = "camera",
|
|
|
+ ImageSize = new Size(50, 50),
|
|
|
+ Margin = 5,
|
|
|
+ BackgroundColor = Color.FromHex("#15C7C1"),
|
|
|
+ HeightRequest = 70,
|
|
|
+ WidthRequest = 70,
|
|
|
+ HorizontalOptions = LayoutOptions.Center,
|
|
|
+ VerticalOptions = LayoutOptions.Center,
|
|
|
+ Padding = 2
|
|
|
+ };
|
|
|
+ Grid.SetColumn(_cameraButton, 0);
|
|
|
+ Grid.SetRow(_cameraButton, 0);
|
|
|
+ _cameraButton.Clicked += CameraButton_Clicked;
|
|
|
+ grid.Children.Add(_cameraButton);
|
|
|
+
|
|
|
+ _cameraLabel = new Label
|
|
|
+ {
|
|
|
+ HorizontalOptions = LayoutOptions.Center,
|
|
|
+ HorizontalTextAlignment = TextAlignment.Center,
|
|
|
+ FontAttributes = FontAttributes.Bold,
|
|
|
+ TextColor = Color.Black
|
|
|
+ };
|
|
|
+ _cameraLabel.FontSize = Device.GetNamedSize(NamedSize.Small, _cameraLabel);
|
|
|
+ Grid.SetRow(_cameraLabel, 1);
|
|
|
+ Grid.SetColumn(_cameraLabel, 0);
|
|
|
+ grid.Children.Add(_cameraLabel);
|
|
|
+
|
|
|
+ _libraryButton = new MobileButton
|
|
|
+ {
|
|
|
+ Image = "gallery",
|
|
|
+ Margin = 5,
|
|
|
+ Padding = 2,
|
|
|
+ BackgroundColor = Color.FromHex("#15C7C1"),
|
|
|
+ HeightRequest = 70,
|
|
|
+ WidthRequest = 70,
|
|
|
+ HorizontalOptions = LayoutOptions.Center,
|
|
|
+ VerticalOptions = LayoutOptions.Center
|
|
|
+ };
|
|
|
+ Grid.SetRow(_libraryButton, 0);
|
|
|
+ Grid.SetColumn(_libraryButton, 1);
|
|
|
+ _libraryButton.Clicked += LibraryButton_Clicked;
|
|
|
+ grid.Children.Add(_libraryButton);
|
|
|
+
|
|
|
+ _libraryLabel = new()
|
|
|
+ {
|
|
|
+ Text = "Library",
|
|
|
+ HorizontalOptions = LayoutOptions.Center,
|
|
|
+ HorizontalTextAlignment = TextAlignment.Center,
|
|
|
+ FontAttributes = FontAttributes.Bold
|
|
|
+ };
|
|
|
+ _libraryLabel.FontSize = Device.GetNamedSize(NamedSize.Small, _libraryLabel);
|
|
|
+ Grid.SetRow(_libraryLabel, 1);
|
|
|
+ Grid.SetColumn(_libraryLabel, 1);
|
|
|
+ grid.Children.Add(_libraryLabel);
|
|
|
+
|
|
|
+ Content = grid;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CameraButton_Clicked(object sender, MobileButtonClickEventArgs args)
|
|
|
+ {
|
|
|
+ // reset _id here
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LibraryButton_Clicked(object sender, MobileButtonClickEventArgs args)
|
|
|
+ {
|
|
|
+ // reset _id here
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Initialize(T definition)
|
|
|
+ {
|
|
|
+ UpdateStatus();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected abstract bool DisableLibrary { get; }
|
|
|
+ protected abstract bool Secure { get; }
|
|
|
+ protected abstract bool Required { get; }
|
|
|
+
|
|
|
+ private void UpdateStatus()
|
|
|
+ {
|
|
|
+ _cameraLabel.Text = IsVideo ? "Take Video" : "Camera";
|
|
|
+ _libraryButton.IsEnabled = !DisableLibrary;
|
|
|
+
|
|
|
+ bool enabled = !_readOnly && !Secure;
|
|
|
+ _cameraButton.IsEnabled = enabled;
|
|
|
+ _libraryButton.IsEnabled = enabled && !DisableLibrary;
|
|
|
+ _libraryLabel.TextColor = enabled && !DisableLibrary
|
|
|
+ ? Color.Black
|
|
|
+ : Color.Gray;
|
|
|
+
|
|
|
+ var colors = DigitalFormUtils.GetColors(!enabled, Required, false);
|
|
|
+ BackgroundColor = colors.Background;
|
|
|
+ BorderColor = colors.Border;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|