|
|
@ -1,4 +1,5 @@
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
|
|
using System.Dynamic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using Connected.Annotations;
|
|
|
|
using Connected.Annotations;
|
|
|
@ -14,11 +15,13 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
private const string format24Hours = "HH:mm";
|
|
|
|
private const string format24Hours = "HH:mm";
|
|
|
|
private const string format12Hours = "hh:mm tt";
|
|
|
|
private const string format12Hours = "hh:mm tt";
|
|
|
|
|
|
|
|
|
|
|
|
public TimePicker() : base(new DefaultConverter<TimeSpan?>())
|
|
|
|
|
|
|
|
|
|
|
|
public TimePicker() : base()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Converter.GetFunc = OnGet;
|
|
|
|
_timeFormat = format24Hours;
|
|
|
|
Converter.SetFunc = OnSet;
|
|
|
|
|
|
|
|
((DefaultConverter<TimeSpan?>)Converter).Format = format24Hours;
|
|
|
|
Converter = new LambdaConverter<TimeSpan?, string>((e) => OnSet(e), (e) => OnGet(e));
|
|
|
|
|
|
|
|
|
|
|
|
AdornmentIcon = Icons.Material.Filled.AccessTime;
|
|
|
|
AdornmentIcon = Icons.Material.Filled.AccessTime;
|
|
|
|
AdornmentAriaLabel = "Open Time Picker";
|
|
|
|
AdornmentAriaLabel = "Open Time Picker";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -30,7 +33,7 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
|
|
|
|
|
|
|
var time = DateTime.Today.Add(timespan.Value);
|
|
|
|
var time = DateTime.Today.Add(timespan.Value);
|
|
|
|
|
|
|
|
|
|
|
|
return time.ToString(((DefaultConverter<TimeSpan?>)Converter).Format, Culture);
|
|
|
|
return time.ToString(_timeFormat, Culture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private TimeSpan? OnGet(string value)
|
|
|
|
private TimeSpan? OnGet(string value)
|
|
|
@ -38,7 +41,7 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParseExact(value, ((DefaultConverter<TimeSpan?>)Converter).Format, Culture, DateTimeStyles.None, out var time))
|
|
|
|
if (DateTime.TryParseExact(value, _timeFormat, Culture, DateTimeStyles.None, out var time))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return time.TimeOfDay;
|
|
|
|
return time.TimeOfDay;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -105,13 +108,10 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
|
|
|
|
|
|
|
_amPm = value;
|
|
|
|
_amPm = value;
|
|
|
|
|
|
|
|
|
|
|
|
if (Converter is DefaultConverter<TimeSpan?> defaultConverter && string.IsNullOrWhiteSpace(_timeFormat))
|
|
|
|
_timeFormat = AmPm ? format12Hours : format24Hours;
|
|
|
|
{
|
|
|
|
|
|
|
|
defaultConverter.Format = AmPm ? format12Hours : format24Hours;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Touched = true;
|
|
|
|
Modified = true;
|
|
|
|
SetTextAsync(Converter.Set(_value), false).AndForget();
|
|
|
|
SetTextAsync(Converter.Convert(_value), false).AndForget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -129,11 +129,9 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
_timeFormat = value;
|
|
|
|
_timeFormat = value;
|
|
|
|
if (Converter is DefaultConverter<TimeSpan?> defaultConverter)
|
|
|
|
|
|
|
|
defaultConverter.Format = _timeFormat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Touched = true;
|
|
|
|
Modified = true;
|
|
|
|
SetTextAsync(Converter.Set(_value), false).AndForget();
|
|
|
|
SetTextAsync(Converter.Convert(_value), false).AndForget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -155,7 +153,7 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
TimeIntermediate = time;
|
|
|
|
TimeIntermediate = time;
|
|
|
|
_value = time;
|
|
|
|
_value = time;
|
|
|
|
if (updateValue)
|
|
|
|
if (updateValue)
|
|
|
|
await SetTextAsync(Converter.Set(_value), false);
|
|
|
|
await SetTextAsync(Converter.Convert(_value), false);
|
|
|
|
UpdateTimeSetFromTime();
|
|
|
|
UpdateTimeSetFromTime();
|
|
|
|
await TimeChanged.InvokeAsync(_value);
|
|
|
|
await TimeChanged.InvokeAsync(_value);
|
|
|
|
BeginValidate();
|
|
|
|
BeginValidate();
|
|
|
@ -170,9 +168,9 @@ public partial class TimePicker : Picker<TimeSpan?>
|
|
|
|
|
|
|
|
|
|
|
|
protected override Task StringValueChanged(string value)
|
|
|
|
protected override Task StringValueChanged(string value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Touched = true;
|
|
|
|
Modified = true;
|
|
|
|
// Update the time property (without updating back the Value property)
|
|
|
|
// Update the time property (without updating back the Value property)
|
|
|
|
return SetTimeAsync(Converter.Get(value), false);
|
|
|
|
return SetTimeAsync(Converter.ConvertBack(value), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//The last line cannot be tested
|
|
|
|
//The last line cannot be tested
|
|
|
|