using System; using InABox.Core; using InABox.Mobile; namespace PRS.Mobile { public class DigitalFormTimeEntry : MobileTimeButton, IDigitalFormField { private TimeSpan _value = TimeSpan.Zero; private DFLayoutTimeField? _definition; public DFLayoutTimeField? Definition { get => _definition; set { _definition = value; Initialize(value ?? new DFLayoutTimeField()); } } public TimeSpan Value { get => _value; set { _value = value; UpdateUI(); } } private void UpdateUI() { Time = _value; } protected override void DoChanged() { _value = Time; base.DoChanged(); } public bool IsEmpty => Value.Equals(TimeSpan.Zero); private bool _readOnly; public bool ReadOnly { get => _readOnly; set { _readOnly = value; UpdateStatus(); } } public void Deserialize(DFLoadStorageEntry entry) => Value = Definition?.Properties.DeserializeValue(entry) ?? TimeSpan.Zero; public void Serialize(DFSaveStorageEntry entry) => entry.SetValue(Value); public event DigitalFormViewChangedHandler? ValueChanged; public DigitalFormTimeEntry() { Prompt = ""; OnPropertyChanged(nameof(Time)); 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 == false; var colors = DigitalFormUtils.GetColors(!IsEnabled, Definition?.Properties.Required ?? false, true); BackgroundColor = colors.Background; BorderColor = colors.Border; TextColor = colors.Foreground; } } }