mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
Fix for TimePicker not displaying default Time Value Updated some "Device" code to the new MAUI "DeviceInfo"
90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
namespace Bit.App.Controls
|
|
{
|
|
public class ExtendedDatePicker : DatePicker
|
|
{
|
|
private string _format;
|
|
|
|
public static readonly BindableProperty PlaceHolderProperty = BindableProperty.Create(
|
|
nameof(PlaceHolder), typeof(string), typeof(ExtendedDatePicker));
|
|
|
|
public string PlaceHolder
|
|
{
|
|
get { return (string)GetValue(PlaceHolderProperty); }
|
|
set { SetValue(PlaceHolderProperty, value); }
|
|
}
|
|
|
|
public static readonly BindableProperty NullableDateProperty = BindableProperty.Create(
|
|
nameof(NullableDate), typeof(DateTime?), typeof(ExtendedDatePicker));
|
|
|
|
public DateTime? NullableDate
|
|
{
|
|
get { return (DateTime?)GetValue(NullableDateProperty); }
|
|
set
|
|
{
|
|
SetValue(NullableDateProperty, value);
|
|
UpdateDate();
|
|
}
|
|
}
|
|
|
|
private void UpdateDate()
|
|
{
|
|
if (NullableDate.HasValue)
|
|
{
|
|
if (_format != null)
|
|
{
|
|
Format = _format;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Format = PlaceHolder;
|
|
}
|
|
}
|
|
|
|
protected override void OnBindingContextChanged()
|
|
{
|
|
base.OnBindingContextChanged();
|
|
if (BindingContext != null)
|
|
{
|
|
_format = Format;
|
|
UpdateDate();
|
|
}
|
|
}
|
|
|
|
protected override void OnPropertyChanged(string propertyName = null)
|
|
{
|
|
base.OnPropertyChanged(propertyName);
|
|
|
|
if (propertyName == DateProperty.PropertyName || (propertyName == IsFocusedProperty.PropertyName &&
|
|
!IsFocused && (Date.ToString("d") ==
|
|
DateTime.Now.ToString("d"))))
|
|
{
|
|
NullableDate = Date;
|
|
UpdateDate();
|
|
}
|
|
|
|
if (propertyName == NullableDateProperty.PropertyName)
|
|
{
|
|
if (NullableDate.HasValue)
|
|
{
|
|
Date = NullableDate.Value;
|
|
if (Date.ToString(_format) == DateTime.Now.ToString(_format))
|
|
{
|
|
UpdateDate();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UpdateDate();
|
|
}
|
|
}
|
|
}
|
|
|
|
//Currently the Disconnect Handler needs to be manually called from the App: https://github.com/dotnet/maui/issues/3604
|
|
public void DisconnectHandler()
|
|
{
|
|
Handler?.DisconnectHandler();
|
|
}
|
|
}
|
|
}
|