using System; using InABox.Core; using InABox.Mobile; namespace PRS.Mobile { public class DigitalFormStringPopup : MobileButton, IDigitalFormField { private DFLayoutStringField _definition; public DFLayoutStringField Definition { get => _definition; set { _definition = value; Initialize(value ?? new DFLayoutStringField()); } } private string _value; public string Value { get => _value; set { _value = value; UpdateButtonText(value); } } public bool IsEmpty => String.IsNullOrWhiteSpace(Value); private bool _readOnly; public bool ReadOnly { get => _readOnly; set { _readOnly = value; UpdateStatus(); } } public void Deserialize(string serialized) => Value = serialized; public string Serialize() => 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 UpdateButtonText(string value) { Text = String.IsNullOrWhiteSpace(value) ? "Edit" : value.Length > 25 ? value.Substring(0, 25) + "..." : value; } 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; } } }