123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.Globalization;
- using System.Net;
- using Syncfusion.XForms.Core;
- using Syncfusion.XForms.PopupLayout;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.Resources.Typography;
- namespace InABox.Mobile
- {
-
- public class TimeButtonChangedArgs : EventArgs
- {
- public TimeSpan Time { get; private set; }
- public TimeButtonChangedArgs(TimeSpan time)
- {
- Time = time;
- }
- }
-
- public delegate void TimeButtonChanged(object sender, TimeButtonChangedArgs args);
- public class TimeSpanFormatter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if ((value is TimeSpan time) && (time != TimeSpan.Zero))
- return $"{DateTime.Today.Add(time):hh\\:mm tt}";
- return "--";
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class MobileTimeButton
- {
- private SfPopupLayout popup;
-
- public event TimeButtonChanged Changed;
-
- public static readonly BindableProperty TimeProperty = BindableProperty.Create(
- nameof(Time),
- typeof(TimeSpan),
- typeof(MobileTimeButton));
-
- public TimeSpan Time
- {
- get => (TimeSpan)GetValue(TimeProperty);
- set => SetValue(TimeProperty,value);
- }
-
- public static readonly BindableProperty TextColorProperty = BindableProperty.Create(
- nameof(TextColor),
- typeof(Color),
- typeof(MobileTimeButton),
- XF.Material.Forms.Material.Color.OnSecondary);
- public Color TextColor
- {
- get => (Color)GetValue(TextColorProperty);
- set => SetValue(TextColorProperty, value);
- }
-
- public static readonly BindableProperty TypeScaleProperty = BindableProperty.Create(
- nameof(TypeScale),
- typeof(MaterialTypeScale),
- typeof(MobileTimeButton),
- MaterialTypeScale.Button);
-
- public MaterialTypeScale TypeScale
- {
- get => (MaterialTypeScale)GetValue(TypeScaleProperty);
- set => SetValue(TypeScaleProperty, value);
- }
-
- public static readonly BindableProperty ButtonColorProperty = BindableProperty.Create(
- nameof(ButtonColor),
- typeof(Color),
- typeof(MobileTimeButton),
- XF.Material.Forms.Material.Color.Secondary);
- public Color ButtonColor
- {
- get => (Color)GetValue(ButtonColorProperty);
- set => SetValue(ButtonColorProperty, value);
- }
- public static readonly BindableProperty BorderColorProperty = BindableProperty.Create(
- nameof(BorderColor),
- typeof(Color),
- typeof(MobileTimeButton),
- XF.Material.Forms.Material.Color.SecondaryVariant);
- public Color BorderColor
- {
- get => (Color)GetValue(BorderColorProperty);
- set => SetValue(BorderColorProperty, value);
- }
-
- // public static readonly BindableProperty PaddingProperty = BindableProperty.Create(
- // nameof(Padding),
- // typeof(Thickness),
- // typeof(TimeButton),
- // new Thickness(5));
- //
- // public new Thickness Padding
- // {
- // get => (Thickness)GetValue(PaddingProperty);
- // set => SetValue(PaddingProperty, value);
- // }
-
- public MobileTimeButton()
- {
- InitializeComponent();
- popup = new SfPopupLayout();
- }
-
- private void _frame_OnClicked(object sender, EventArgs e)
- {
-
- popup.PopupView.WidthRequest = 300;
- popup.PopupView.HeightRequest = 500;
- popup.PopupView.ShowHeader = false;
- popup.PopupView.ShowFooter = false;
- //popup.PopupView.PopupStyle.HasShadow = false;
- popup.PopupView.PopupStyle.CornerRadius = 5;
- //popup.PopupView.Background = new SolidColorBrush(Color.White);
- MobileTimeSelector popupContent = new MobileTimeSelector();
- popupContent.Time = Time;
- popupContent.Changed += (o, args) =>
- {
- Time = args.Time;
- DoChanged();
- popup.Closing -= RestrictClose;
- popup.Dismiss();
- };
- popupContent.Cancelled += (o, args) =>
- {
- popup.Closing -= RestrictClose;
- popup.Dismiss();
- };
- popup.Closing += RestrictClose;
- popupContent.Margin = new Thickness(10);
- popupContent.HorizontalOptions = LayoutOptions.Fill;
- popupContent.VerticalOptions = LayoutOptions.Fill;
- popup.PopupView.ContentTemplate = new DataTemplate(() => popupContent);
-
- popup.Show();
- }
- protected virtual void DoChanged()
- {
- Changed?.Invoke(this,new TimeButtonChangedArgs(Time));
- }
- private void RestrictClose(object sender, CancelEventArgs e)
- {
- e.Cancel = true;
- }
- }
- }
|