123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System;
- using InABox.Core;
- using InABox.Mobile;
- namespace PRS.Mobile
- {
- public class DigitalFormTimeEntry : MobileTimeButton, IDigitalFormField<DFLayoutTimeField, DFLayoutTimeFieldProperties, TimeSpan, TimeSpan?>
- {
- 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;
- }
-
- }
- }
|