using System; using System.Globalization; using InABox.Core; using InABox.Mobile; namespace PRS.Mobile { public class DigitalFormTimeEntry : MobileTimeButton, IDigitalFormField { private DFLayoutTimeField _definition; public DFLayoutTimeField Definition { get => _definition; set { _definition = value; Initialize(value ?? new DFLayoutTimeField()); } } public TimeSpan Value { get => Time; set => Time = value; } public bool IsEmpty => Value.Equals(TimeSpan.Zero); private bool _readOnly; public bool ReadOnly { get => _readOnly; set { _readOnly = value; UpdateStatus(); } } public void Deserialize(string serialized) { if (TimeSpan.TryParseExact(serialized, "c", CultureInfo.InvariantCulture, TimeSpanStyles.None, out TimeSpan t)) Value = t; } public string Serialize() => Value.ToString("c"); public event DigitalFormViewChangedHandler ValueChanged; public DigitalFormTimeEntry() { HeightRequest = 40; Changed += (sender, args) => { ValueChanged?.Invoke(this, new DigitalFormViewChangedArgs(Definition,Value)); }; } private void Initialize(DFLayoutTimeField definition) { UpdateStatus(); } private void UpdateStatus() { IsEnabled = !_readOnly || Definition.Properties.Secure; var colors = DigitalFormUtils.GetColors(!IsEnabled, Definition.Properties.Required, true); BackgroundColor = colors.Background; BorderColor = colors.Border; TextColor = colors.Foreground; } } }