public DatePickerController(DatePromptConfig config, UIViewController parent) : base(config.Title, parent)
        {
            this.DatePicker = new UIDatePicker
            {
                Mode = UIDatePickerMode.Date
            };
            this.Dismissed += (object sender, bool e) =>
            {
                var date = ((DateTime)this.DatePicker.Date).ToLocalTime();
                config.OnResult?.Invoke(new DatePromptResult(e, date));
            };
            if (config.SelectedDate != null)
            {
                this.DatePicker.Date = this.ToNsDate(config.SelectedDate.Value, config.UnspecifiedDateTimeKindReplacement);
            }

            if (config.IsCancellable)
            {
                this.CancelButtonText = config.CancelText;
            }

            if (config.MaximumDate != null)
            {
                this.DatePicker.MaximumDate = (NSDate)config.MaximumDate.Value;
            }

            if (config.MinimumDate != null)
            {
                this.DatePicker.MinimumDate = (NSDate)config.MinimumDate.Value;
            }
        }
        public override IDisposable DatePrompt(DatePromptConfig config)
        {
            var picker = new AI.AIDatePickerController
            {
#if __IOS__
                Mode            = UIDatePickerMode.Date,
                DatePickerStyle = GetPickerStyle(config),
#endif
                SelectedDateTime = config.SelectedDate ?? DateTime.Now,
                OkText           = config.OkText,
                CancelText       = config.CancelText,
                Ok     = x => config.OnAction?.Invoke(new DatePromptResult(true, x.SelectedDateTime)),
                Cancel = x => config.OnAction?.Invoke(new DatePromptResult(false, x.SelectedDateTime)),
            };

            if (config.MaximumDate != null)
            {
                picker.MaximumDateTime = config.MaximumDate;
            }

            if (config.MinimumDate != null)
            {
                picker.MinimumDateTime = config.MinimumDate;
            }

            return(this.Present(picker));
        }
Пример #3
0
        public override IDisposable DatePrompt(DatePromptConfig config)
        {
            var activity = this.TopActivityFunc();

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

            return(this.Show(activity, () => DatePromptBuilder.Build(activity, config)));
        }
        public override IDisposable DatePrompt(DatePromptConfig config)
        {
            var top    = UIApplication.SharedApplication.GetTopViewController();
            var picker = new DatePickerController(config, top)
            {
                ProvidesPresentationContextTransitionStyle = true,
                DefinesPresentationContext = true,
                ModalPresentationStyle     = UIModalPresentationStyle.OverCurrentContext
            };

            return(this.Present(top, picker));
        }
        public override IDisposable DatePrompt(DatePromptConfig config)
        {
            var date = new DateTimeView()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                MaximumDate       = config.MaximumDate ?? new DateTime(2030, 12, 31),
                MinimumDate       = config.MinimumDate ?? new DateTime(2017, 1, 1),
                DateTime          = config.SelectedDate ?? DateTime.Now,
                DisplayFormat     = "%F",
            };
            XButton positive = new XButton()
            {
                Text = config.OkText
            };
            XButton negative = new XButton()
            {
                Text = config.CancelText
            };
            var layout = new StackLayout
            {
                Children =
                {
                    date,
                },
            };
            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 DatePromptResult(true, date.DateTime));
            };
            negative.Clicked += (s, e) =>
            {
                dialog.Hide();
                config.OnAction?.Invoke(new DatePromptResult(false, date.DateTime));
            };
            return(Show(dialog));
        }
Пример #6
0
        /// <summary> Gets date prompt configuration. </summary>
        /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception>
        /// <param name="config"> The configuration. </param>
        /// <returns> The date prompt configuration. </returns>
        private AcrDialogs.DatePromptConfig GetDatePromptConfig(UserDialogDatePromptConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var result = new AcrDialogs.DatePromptConfig();

            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.SelectedDate != null)
            {
                result.SelectedDate = config.SelectedDate;
            }
            if (config.UnspecifiedDateTimeKindReplacement != null)
            {
                result.UnspecifiedDateTimeKindReplacement = config.UnspecifiedDateTimeKindReplacement.Value;
            }
            if (config.OnAction != null)
            {
                result.OnAction = GetDatePromptResultAction(config.OnAction);
            }
            if (config.IsCancellable != null)
            {
                result.IsCancellable = config.IsCancellable.Value;
            }
            if (config.MinimumDate != null)
            {
                result.MinimumDate = config.MinimumDate;
            }
            if (config.MaximumDate != null)
            {
                result.MaximumDate = config.MaximumDate;
            }
            if (config.AndroidStyleId != null)
            {
                result.AndroidStyleId = config.AndroidStyleId;
            }

            return(result);
        }
Пример #7
0
        public override IDisposable DatePrompt(DatePromptConfig config)
        {
            var picker = new DatePickerControl();

            if (config.MinimumDate != null)
            {
                picker.DatePicker.MinDate = config.MinimumDate.Value;
            }

            if (config.MaximumDate != null)
            {
                picker.DatePicker.MaxDate = config.MaximumDate.Value;
            }

            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 DatePromptResult(false, this.GetDateForCalendar(picker.DatePicker));
                    config.OnAction?.Invoke(result);
                    popup.IsOpen = false;
                };
            }

            picker.OkButton.Content = config.OkText;
            picker.OkButton.Click  += (sender, args) =>
            {
                var result = new DatePromptResult(true, this.GetDateForCalendar(picker.DatePicker));
                config.OnAction?.Invoke(result);
                popup.IsOpen = false;
            };
            if (config.SelectedDate != null)
            {
                picker.DatePicker.SelectedDates.Add(config.SelectedDate.Value);
                picker.DatePicker.SetDisplayDate(config.SelectedDate.Value);
            }
            return(this.DispatchAndDispose(
                       //config.UwpSubmitOnEnterKey,
                       //config.UwpCancelOnEscKey,
                       () => popup.IsOpen = true,
                       () => popup.IsOpen = false
                       ));
        }
Пример #8
0
        public override IDisposable DatePrompt(DatePromptConfig config)
        {
#if WINDOWS_PHONE_APP
            throw new NotImplementedException();
#else
            var picker = new DatePickerControl();
            if (config.MinimumDate != null)
            {
                picker.DatePicker.MinDate = config.MinimumDate.Value;
            }

            if (config.MaximumDate != null)
            {
                picker.DatePicker.MaxDate = config.MaximumDate.Value;
            }

            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 DatePromptResult(false, this.GetDateForCalendar(picker.DatePicker));
                    config.OnResult?.Invoke(result);
                    popup.IsOpen = false;
                };
            }

            picker.OkButton.Content = config.OkText;
            picker.OkButton.Click  += (sender, args) =>
            {
                var result = new DatePromptResult(true, this.GetDateForCalendar(picker.DatePicker));
                config.OnResult?.Invoke(result);
                popup.IsOpen = false;
            };
            if (config.SelectedDate != null)
            {
                picker.DatePicker.SelectedDates.Add(config.SelectedDate.Value);
                picker.DatePicker.SetDisplayDate(config.SelectedDate.Value);
            }
            return(this.DispatchAndDispose(
                       () => popup.IsOpen = true,
                       () => popup.IsOpen = false
                       ));
#endif
        }
        protected iOSDatePickerStyle GetPickerStyle(DatePromptConfig config)
        {
            var iOSConfig = (config as IiOSStyleDialogConfig);

            if (iOSConfig == null)
            {
                return(iOSDatePickerStyle.Auto);
            }

            if (!iOSConfig.iOSDatePickerStyle.HasValue)
            {
                return(iOSDatePickerStyle.Auto);
            }

            return(iOSConfig.iOSDatePickerStyle.Value);
        }
        public virtual Task <DatePromptResult> DatePromptAsync(DatePromptConfig config, CancellationToken?cancelToken = null)
        {
            var tcs = new TaskCompletionSource <DatePromptResult>();

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

            var disp = this.DatePrompt(config);

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

            return(tcs.Task);
        }
Пример #11
0
        public virtual async Task <DatePromptResult> DatePromptAsync(DatePromptConfig config, CancellationToken?cancelToken = null)
        {
            if (config.OnAction != null)
            {
                throw new ArgumentException(NO_ONACTION);
            }

            var tcs = new TaskCompletionSource <DatePromptResult>();

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

            var disp = this.DatePrompt(config);

            using (cancelToken?.Register(() => Cancel(disp, tcs)))
            {
                return(await tcs.Task);
            }
        }
Пример #12
0
        public override IDisposable DatePrompt(DatePromptConfig config)
        {
            var app        = NSApplication.SharedApplication;
            var controller = new DatePickerController(app.MainWindow?.ContentViewController)
            {
                ElementFlags     = NSDatePickerElementFlags.YearMonthDate,
                SelectedDateTime = config.SelectedDate ?? DateTime.Now,
                OkText           = config.OkText,
                CancelText       = config.CancelText,
                Ok              = x => config.OnAction?.Invoke(new DatePromptResult(true, x.SelectedDateTime)),
                Cancel          = x => config.OnAction?.Invoke(new DatePromptResult(false, x.SelectedDateTime)),
                MinimumDateTime = config.MinimumDate,
                MaximumDateTime = config.MaximumDate
            };

            app.InvokeOnMainThread(() => app.MainWindow?.ContentViewController.PresentViewControllerAsSheet(controller));
            return(new DisposableAction(() => app.InvokeOnMainThread(() => app.MainWindow?.ContentViewController.DismissViewController(controller))));
        }
Пример #13
0
 public override IDisposable DatePrompt(DatePromptConfig config)
 {
     Dispatch(() =>
     {
         var calendar = new System.Windows.Controls.Calendar()
         {
             DisplayDateStart = config.MinimumDate,
             DisplayDateEnd   = config.MaximumDate,
             DisplayMode      = System.Windows.Controls.CalendarMode.Month,
             SelectionMode    = System.Windows.Controls.CalendarSelectionMode.SingleDate
         };
         if (config.SelectedDate != null)
         {
             DateTime selectedDate = DateTime.Today;
             if (selectedDate > (config.SelectedDate ?? DateTime.MaxValue))
             {
                 selectedDate = config.SelectedDate ?? DateTime.MaxValue;
             }
             if (selectedDate < (config.SelectedDate ?? DateTime.MinValue))
             {
                 selectedDate = config.SelectedDate ?? DateTime.MinValue;
             }
             calendar.SelectedDate = selectedDate;
         }
         FormsContentDialog dialog = new FormsContentDialog()
         {
             Title   = config.Title,
             Content = new System.Windows.Controls.Viewbox()
             {
                 Stretch          = System.Windows.Media.Stretch.Uniform,
                 StretchDirection = System.Windows.Controls.StretchDirection.UpOnly,
                 Child            = calendar,
             },
             IsPrimaryButtonEnabled   = true,
             PrimaryButtonText        = config.OkText,
             IsSecondaryButtonEnabled = config.IsCancellable,
             SecondaryButtonText      = config.CancelText
         };
         dialog.PrimaryButtonClick   += (s, e) => { HideContentDialog(); config.OnAction(new DatePromptResult(true, calendar.SelectedDate ?? DateTime.Today)); e.Cancel = true; };
         dialog.SecondaryButtonClick += (s, e) => { HideContentDialog(); config.OnAction(new DatePromptResult(false, calendar.SelectedDate ?? DateTime.Today)); e.Cancel = true; };
         ShowContentDialog(dialog);
     });
     return(new DisposableAction(HideContentDialog));
 }
Пример #14
0
        public virtual Task <DatePromptResult> DatePromptAsync(DatePromptConfig config, CancellationToken?cancelToken = null)
        {
            if (config.OnAction != null)
            {
                throw new ArgumentException(NO_ONACTION);
            }

            var tcs = new TaskCompletionSource <DatePromptResult>();

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

            var disp = this.DatePrompt(config);

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

            return(tcs.Task);
        }
Пример #15
0
 public override IDisposable DatePrompt(DatePromptConfig config)
 {
     throw new NotImplementedException();
 }
Пример #16
0
 public abstract IDisposable DatePrompt(DatePromptConfig config);