public TimePickerController(TimePromptConfig config, UIViewController parent) : base(config.Title, parent)
        {
            this.DatePicker = new UIDatePicker
            {
                Mode           = UIDatePickerMode.Time,
                MinuteInterval = config.MinuteInterval
            };
            this.Dismissed += (sender, b) =>
            {
                var time = ((DateTime)this.DatePicker.Date).ToLocalTime().TimeOfDay;
                config.OnResult?.Invoke(new TimePromptResult(b, time));
            };

            this.DoneButtonText = config.OkText;
            if (config.IsCancellable)
            {
                this.CancelButtonText = config.CancelText;
            }
            if (config.SelectedTime != null)
            {
                var time = config.SelectedTime.Value;
                var now  = DateTime.Now;
                var date = new DateTime(now.Year, now.Month, now.Day, time.Hours, time.Minutes, 0, DateTimeKind.Local);
                this.DatePicker.SetDate((NSDate)date, false);
            }
        }
예제 #2
0
        /// <summary> Gets time prompt configuration. </summary>
        /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception>
        /// <param name="config"> The configuration. </param>
        /// <returns> The time prompt configuration. </returns>
        private AcrDialogs.TimePromptConfig GetTimePromptConfig(UserDialogTimePromptConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var result = new AcrDialogs.TimePromptConfig();

            if (config.Title != null)
            {
                result.Title = config.Title;
            }
            if (config.OkText != null)
            {
                result.OkText = config.OkText;
            }
            if (config.CancelText != null)
            {
                result.CancelText = config.CancelText;
            }
            if (config.Use24HourClock != null)
            {
                result.Use24HourClock = config.Use24HourClock;
            }
            if (config.SelectedTime != null)
            {
                result.SelectedTime = config.SelectedTime;
            }
            if (config.OnAction != null)
            {
                result.OnAction = GetTimePromptResultAction(config.OnAction);
            }
            if (config.IsCancellable != null)
            {
                result.IsCancellable = config.IsCancellable.Value;
            }
            if (config.MinimumMinutesTimeOfDay != null)
            {
                result.MinimumMinutesTimeOfDay = config.MinimumMinutesTimeOfDay;
            }
            if (config.MaximumMinutesTimeOfDay != null)
            {
                result.MaximumMinutesTimeOfDay = config.MaximumMinutesTimeOfDay;
            }
            if (config.MinuteInterval != null)
            {
                result.MinuteInterval = config.MinuteInterval.Value;
            }
            if (config.AndroidStyleId != null)
            {
                result.AndroidStyleId = config.AndroidStyleId;
            }

            return(result);
        }
예제 #3
0
        public override IDisposable TimePrompt(TimePromptConfig config)
        {
            var activity = this.TopActivityFunc();

            if (activity is AppCompatActivity act)
            {
                return(this.ShowDialog <TimeAppCompatDialogFragment, TimePromptConfig>(act, config));
            }

            return(this.Show(activity, () => TimePromptBuilder.Build(activity, config)));
        }
        public override IDisposable TimePrompt(TimePromptConfig config)
        {
            var top    = UIApplication.SharedApplication.GetTopViewController();
            var picker = new TimePickerController(config, top)
            {
                ProvidesPresentationContextTransitionStyle = true,
                DefinesPresentationContext = true,
                ModalPresentationStyle     = UIModalPresentationStyle.OverCurrentContext
            };

            return(this.Present(top, picker));
        }
예제 #5
0
        public override IDisposable TimePrompt(TimePromptConfig config)
        {
            var picker = new AI.AIDatePickerController
            {
                Mode             = UIDatePickerMode.Time,
                SelectedDateTime = config.SelectedTime != null?DateTime.Today.Add((TimeSpan)config.SelectedTime) : DateTime.Now,
                                       MinuteInterval = config.MinuteInterval,
                                       OkText         = config.OkText,
                                       CancelText     = config.CancelText,
                                       Ok             = x => config.OnAction?.Invoke(new TimePromptResult(true, x.SelectedDateTime.TimeOfDay)),
                                       Cancel         = x => config.OnAction?.Invoke(new TimePromptResult(false, x.SelectedDateTime.TimeOfDay)),
                                       Use24HourClock = config.Use24HourClock
            };

            return(this.Present(picker));
        }
        public virtual Task <TimePromptResult> TimePromptAsync(TimePromptConfig config, CancellationToken?cancelToken = null)
        {
            var tcs = new TaskCompletionSource <TimePromptResult>();

            config.OnResult = x => tcs.TrySetResult(x);

            var disp = this.TimePrompt(config);

            cancelToken?.Register(() =>
            {
                disp.Dispose();
                tcs.TrySetCanceled();
            });;

            return(tcs.Task);
        }
예제 #7
0
        public override IDisposable TimePrompt(TimePromptConfig config)
        {
            var picker = new TimePickerControl();

            picker.TimePicker.MinuteIncrement = config.MinuteInterval;

            var popup = this.CreatePopup(picker);

            if (!config.IsCancellable)
            {
                picker.CancelButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                picker.CancelButton.Content = config.CancelText;
                picker.CancelButton.Click  += (sender, args) =>
                {
                    var result = new TimePromptResult(false, picker.TimePicker.Time);
                    config.OnAction?.Invoke(result);
                    popup.IsOpen = false;
                };
            }

            if (config.Use24HourClock == true)
            {
                picker.TimePicker.ClockIdentifier = "24HourClock";
            }

            picker.OkButton.Content = config.OkText;
            picker.OkButton.Click  += (sender, args) =>
            {
                var result = new TimePromptResult(true, picker.TimePicker.Time);
                config.OnAction?.Invoke(result);
                popup.IsOpen = false;
            };
            if (config.SelectedTime != null)
            {
                picker.TimePicker.Time = config.SelectedTime.Value;
            }
            return(this.DispatchAndDispose(
                       //config.UwpSubmitOnEnterKey,
                       //config.UwpCancelOnEscKey,
                       () => popup.IsOpen = true,
                       () => popup.IsOpen = false
                       ));
        }
예제 #8
0
        public override IDisposable TimePrompt(TimePromptConfig config)
        {
#if WINDOWS_PHONE_APP
            throw new NotImplementedException();
#else
            var picker = new TimePickerControl();
            picker.TimePicker.MinuteIncrement = config.MinuteInterval;
            if (config.Use24HourClock.HasValue && config.Use24HourClock.Value)
            {
                picker.TimePicker.ClockIdentifier = "24HourClock";
            }

            var popup = this.CreatePopup(picker);

            if (!config.IsCancellable)
            {
                picker.CancelButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                picker.CancelButton.Content = config.CancelText;
                picker.CancelButton.Click  += (sender, args) =>
                {
                    var result = new TimePromptResult(false, picker.TimePicker.Time);
                    config.OnAction?.Invoke(result);
                    popup.IsOpen = false;
                };
            }

            picker.OkButton.Content = config.OkText;
            picker.OkButton.Click  += (sender, args) =>
            {
                var result = new TimePromptResult(true, picker.TimePicker.Time);
                config.OnAction?.Invoke(result);
                popup.IsOpen = false;
            };
            if (config.SelectedTime != null)
            {
                picker.TimePicker.Time = config.SelectedTime.Value;
            }
            return(this.DispatchAndDispose(
                       () => popup.IsOpen = true,
                       () => popup.IsOpen = false
                       ));
#endif
        }
예제 #9
0
        public virtual async Task <TimePromptResult> TimePromptAsync(TimePromptConfig config, CancellationToken?cancelToken = null)
        {
            if (config.OnAction != null)
            {
                throw new ArgumentException(NO_ONACTION);
            }

            var tcs = new TaskCompletionSource <TimePromptResult>();

            config.OnAction = x => tcs.TrySetResult(x);

            var disp = this.TimePrompt(config);

            using (cancelToken?.Register(() => Cancel(disp, tcs)))
            {
                return(await tcs.Task);
            }
        }
예제 #10
0
        public override IDisposable TimePrompt(TimePromptConfig config)
        {
            var app        = NSApplication.SharedApplication;
            var controller = new DatePickerController(app.MainWindow?.ContentViewController)
            {
                ElementFlags     = NSDatePickerElementFlags.HourMinute,
                SelectedDateTime = config.SelectedTime != null?DateTime.Today.Add((TimeSpan)config.SelectedTime) : DateTime.Now,
                                       MinuteInterval = config.MinuteInterval,
                                       OkText         = config.OkText,
                                       CancelText     = config.CancelText,
                                       Ok             = x => config.OnAction?.Invoke(new TimePromptResult(true, x.SelectedDateTime.TimeOfDay)),
                                       Cancel         = x => config.OnAction?.Invoke(new TimePromptResult(false, x.SelectedDateTime.TimeOfDay)),
                                       Use24HourClock = config.Use24HourClock ?? false
            };

            app.InvokeOnMainThread(() => app.MainWindow?.ContentViewController.PresentViewControllerAsSheet(controller));
            return(new DisposableAction(() => app.InvokeOnMainThread(() => app.MainWindow?.ContentViewController.DismissViewController(controller))));
        }
예제 #11
0
        public virtual Task <TimePromptResult> TimePromptAsync(TimePromptConfig config, CancellationToken?cancelToken = null)
        {
            if (config.OnAction != null)
            {
                throw new ArgumentException(NO_ONACTION);
            }

            var tcs = new TaskCompletionSource <TimePromptResult>();

            config.OnAction = x => tcs.TrySetResult(x);

            var disp = this.TimePrompt(config);

            cancelToken?.Register(() =>
            {
                disp.Dispose();
                tcs.TrySetCanceled();
            });;

            return(tcs.Task);
        }
예제 #12
0
 public override IDisposable TimePrompt(TimePromptConfig config)
 {
     Dispatch(() =>
     {
         var timePromptControl = new TimePromptControl()
         {
             Use24HourClock = config.Use24HourClock ?? false, Value = config.SelectedTime ?? TimeSpan.Zero
         };
         FormsContentDialog dialog = new FormsContentDialog()
         {
             DataContext              = config,
             Title                    = config.Title,
             Content                  = timePromptControl,
             IsPrimaryButtonEnabled   = true,
             PrimaryButtonText        = config.OkText,
             IsSecondaryButtonEnabled = true,
             SecondaryButtonText      = config.CancelText
         };
         dialog.PrimaryButtonClick   += (s, e) => { HideContentDialog(); config.OnAction(new TimePromptResult(true, timePromptControl.Value)); e.Cancel = true; };
         dialog.SecondaryButtonClick += (s, e) => { HideContentDialog(); config.OnAction(new TimePromptResult(false, timePromptControl.Value)); e.Cancel = true; };
         ShowContentDialog(dialog);
     });
     return(new DisposableAction(HideContentDialog));
 }
예제 #13
0
 public override IDisposable TimePrompt(TimePromptConfig config)
 {
     throw new NotImplementedException();
 }
예제 #14
0
 public abstract IDisposable TimePrompt(TimePromptConfig config);
        public override IDisposable TimePrompt(TimePromptConfig config)
        {
            var time = new DateTimeView()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                DateTime          = config.SelectedTime != null?DateTime.Today.Add((TimeSpan)config.SelectedTime) : DateTime.Now,
            };
            var positive = new XButton
            {
                Text = config.OkText
            };
            var negative = new XButton
            {
                Text = config.CancelText
            };
            var layout = new StackLayout
            {
                Children =
                {
                    time
                },
                Padding = 30
            };

            if (config.Use24HourClock == null)
            {
                time.DisplayFormat = "%T";
            }
            else
            {
                if (config.Use24HourClock.Value)
                {
                    time.DisplayFormat = "%p %T";
                }
                else
                {
                    time.DisplayFormat = "%T";
                }
            }
            var dialog = new Dialog()
            {
                Title = config.Title,
                //Subtitle = config.Message,
                Content          = layout,
                HorizontalOption = LayoutOptions.Center,
                VerticalOption   = LayoutOptions.Center,
                Negative         = negative,
                Positive         = positive
            };

            dialog.OutsideClicked += (s, e) =>
            {
                dialog.Hide();
            };
            positive.Clicked += (s, e) =>
            {
                dialog.Hide();
                config.OnAction?.Invoke(new TimePromptResult(true, time.DateTime.TimeOfDay));
            };
            negative.Clicked += (s, e) =>
            {
                dialog.Hide();
                config.OnAction?.Invoke(new TimePromptResult(false, time.DateTime.TimeOfDay));
            };
            return(Show(dialog));
        }