using System; using InABox.Core; using InABox.Mobile; using PRSClasses; namespace PRS.Mobile { public class DigitalFormAddTask : MobileButton, IDigitalFormField { private string? _value; private DFLayoutAddTaskField? _definition; public DFLayoutAddTaskField? Definition { get => _definition; set { _definition = value; Initialize(value ?? new DFLayoutAddTaskField()); } } public string? Value { get => _value; set { _value = value; UpdateUI(); } } public bool IsEmpty => String.IsNullOrWhiteSpace(Value); private bool _readOnly; public bool ReadOnly { get => _readOnly; set { _readOnly = value; UpdateStatus(); } } public void Deserialize(DFLoadStorageEntry entry) => Value = Definition?.Properties.DeserializeValue(entry) ?? string.Empty; public void Serialize(DFSaveStorageEntry entry) => entry.SetValue(Value); public event DigitalFormViewChangedHandler? ValueChanged; public DigitalFormAddTask() { Clicked += (s, e) => { // Create or Display the Task Here }; } private void Initialize(DFLayoutAddTaskField definition) { } private void UpdateUI() { Text = String.IsNullOrWhiteSpace(_value) ? "Edit" : _value.Length > 25 ? _value.Substring(0, 25) + "..." : _value; } 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; } } }