예제 #1
0
        /// <summary>
        /// Displays information to the user.
        /// </summary>
        /// <param name="contentView">The custom content view to be shown to the user.</param>
        /// <param name="title">The title of the dialog box. This may be null.</param>
        /// <param name="confirmButtonText">The text shown in the "confirm" button
        /// in the dialog box. If left null, the button will be invisible.</param>
        /// <param name="neutralButtonText">The text shown in the "neutral" button
        /// in the dialog box. If left null, the button will be invisible.</param>
        /// <param name="cancelButtonText">The text shown in the "cancel" button
        /// in the dialog box. If left null, the button will be invisible.</param>
        /// <param name="canceledOnTouchOutside">Whether the dialog box is canceled when
        /// touched outside the window's bounds. </param>
        /// <param name="clickCallback">A callback that should be executed after
        /// the dialog box is closed by the user. The callback method will get a boolean
        /// parameter indicating if the "confirm" button (true) or the "cancel" button
        /// (false) was pressed by the user.</param>
        /// <returns>A AlertDialog.</returns>
        public static async Task <AlertDialogView> ShowMessage(
            View contentView,
            string title,
            string neutralButtonText,
            string cancelButtonText,
            string confirmButtonText,
            bool canceledOnTouchOutside,
            Action <int> clickCallback)
        {
            AlertDialogVM viewModel = new AlertDialogVM();

            viewModel.Title.Value                  = title;
            viewModel.ConfirmButtonText.Value      = confirmButtonText;
            viewModel.NeutralButtonText.Value      = neutralButtonText;
            viewModel.CancelButtonText.Value       = cancelButtonText;
            viewModel.CanceledOnTouchOutside.Value = canceledOnTouchOutside;
            viewModel.Click = clickCallback;

            UIManager       locator = GetUIViewLocator();
            AlertDialogView window  = (await locator.OpenAsync <AlertDialogView>()) as AlertDialogView;
            AlertDialog     dialog  = new AlertDialog(window, contentView, viewModel);

            dialog.Show();
            return(window);
        }
예제 #2
0
        public static async Task <AlertDialog> ShowMessage(
            string message,
            string title,
            string confirmButtonText    = null,
            string neutralButtonText    = null,
            string cancelButtonText     = null,
            bool canceledOnTouchOutside = true,
            Action <int> clickCallback  = null)
        {
            AlertDialogVM viewModel = new AlertDialogVM();

            viewModel.Message.Value                = message;
            viewModel.Title.Value                  = title;
            viewModel.ConfirmButtonText.Value      = confirmButtonText;
            viewModel.NeutralButtonText.Value      = neutralButtonText;
            viewModel.CancelButtonText.Value       = cancelButtonText;
            viewModel.CanceledOnTouchOutside.Value = canceledOnTouchOutside;
            viewModel.Click = clickCallback;

            return(await ShowMessage(viewModel));
        }
예제 #3
0
        /// <summary>
        /// Displays information to the user.
        /// </summary>
        /// <param name="viewName">The view name of the dialog box,if it is null, use the default view name</param>
        /// <param name="contentViewName">The custom content view name to be shown to the user.</param>
        /// <param name="viewModel">The view model of the dialog box</param>
        /// <returns>A AlertDialog.</returns>
        public static async Task <AlertDialog> ShowMessage(AlertDialogVM viewModel)
        {
            AlertDialogView view = null;

            try
            {
                UIManager locator = GetUIViewLocator();
                view = await locator.OpenAsync <AlertDialogView>() as AlertDialogView;

                AlertDialog dialog = new AlertDialog(view, null, viewModel);
                dialog.Show();
                return(dialog);
            }
            catch (Exception e)
            {
                if (view != null)
                {
                    UIManager.Ins.Close(view);
                }
                Log.Error(e);
                throw;
            }
        }
예제 #4
0
        protected override void OnVmChange()
        {
            vm = ViewModel as AlertDialogVM;
            if (this.Message != null)
            {
                if (!string.IsNullOrEmpty(vm.Message))
                {
                    this.Message.gameObject.SetActive(true);
                    this.Message.text = this.vm.Message;
                }
                else
                {
                    this.Message.gameObject.SetActive(false);
                }
            }

            if (this.Title != null)
            {
                if (!string.IsNullOrEmpty(vm.Title))
                {
                    this.Title.gameObject.SetActive(true);
                    this.Title.text = this.vm.Title;
                }
                else
                {
                    this.Title.gameObject.SetActive(false);
                }
            }

            if (this.ConfirmButton != null)
            {
                if (!string.IsNullOrEmpty(vm.ConfirmButtonText))
                {
                    this.ConfirmButton.gameObject.SetActive(true);
                    this.ConfirmButton.onClick.AddListener(() => { this.Button_OnClick(AlertDialog.BUTTON_POSITIVE); });
                    Text text = this.ConfirmButton.GetComponentInChildren <Text>();
                    if (text != null)
                    {
                        text.text = this.vm.ConfirmButtonText;
                    }
                }
                else
                {
                    this.ConfirmButton.gameObject.SetActive(false);
                }
            }

            if (this.CancelButton != null)
            {
                if (!string.IsNullOrEmpty(this.vm.CancelButtonText))
                {
                    this.CancelButton.gameObject.SetActive(true);
                    this.CancelButton.onClick.AddListener(() => { this.Button_OnClick(AlertDialog.BUTTON_NEGATIVE); });
                    Text text = this.CancelButton.GetComponentInChildren <Text>();
                    if (text != null)
                    {
                        text.text = this.vm.CancelButtonText;
                    }
                }
                else
                {
                    this.CancelButton.gameObject.SetActive(false);
                }
            }

            if (this.NeutralButton != null)
            {
                if (!string.IsNullOrEmpty(this.vm.NeutralButtonText))
                {
                    this.NeutralButton.gameObject.SetActive(true);
                    this.NeutralButton.onClick.AddListener(() => { this.Button_OnClick(AlertDialog.BUTTON_NEUTRAL); });
                    Text text = this.NeutralButton.GetComponentInChildren <Text>();
                    if (text != null)
                    {
                        text.text = this.vm.NeutralButtonText;
                    }
                }
                else
                {
                    this.NeutralButton.gameObject.SetActive(false);
                }
            }

            this.CanceledOnTouchOutside = this.vm.CanceledOnTouchOutside;
            if (this.OutsideButton != null && this.CanceledOnTouchOutside)
            {
                this.OutsideButton.gameObject.SetActive(true);
                this.OutsideButton.interactable = true;
                this.OutsideButton.onClick.AddListener(() => { this.Button_OnClick(AlertDialog.BUTTON_NEGATIVE); });
            }
        }
예제 #5
0
 public AlertDialog(AlertDialogView view, View contentView, AlertDialogVM viewModel)
 {
     this.View        = view;
     this.contentView = contentView;
     this.ViewModel   = viewModel;
 }
예제 #6
0
 public AlertDialog(AlertDialogView view, AlertDialogVM viewModel) : this(view, null, viewModel)
 {
 }