using System; using InABox.Core; using InABox.Mobile; namespace PRS.Mobile { public class DigitalFormStringPopup : MobileButton, IDigitalFormField { private string _value = ""; private DFLayoutStringField? _definition; public DFLayoutStringField? Definition { get => _definition; set { _definition = value; Initialize(value ?? new DFLayoutStringField()); } } 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 DigitalFormStringPopup() { Clicked += (s, e) => { PopupEditor edt = new PopupEditor(Value); edt.OnPopupEdtSaved += (text) => { Value = text; ValueChanged?.Invoke(this, new DigitalFormViewChangedArgs(Definition,Value)); }; Navigation.PushAsync(edt); }; } private void Initialize(DFLayoutStringField 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; } } }