Example #1
0
        public Task <Tuple <string, string> > NewPasswordInputDialog(string msgContent, bool hasOld, string oldPwdContent = null, string newPwdContent = null)
        {
            var complete = new TaskCompletionSource <Tuple <string, string> >();
            var content  = new LinearLayout(ActivityContext);

            content.Orientation = Orientation.Vertical;

            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent);

            layoutParams.SetMargins(20, 5, 20, 5);

            var msg = new TextView(ActivityContext);

            msg.Text = msgContent;
            content.AddView(msg, layoutParams);

            EditText oldPassword = null;

            if (hasOld)
            {
                oldPassword           = new EditText(ActivityContext);
                oldPassword.InputType = Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextVariationPassword;
                oldPassword.Hint      = "Old Password";
                oldPassword.Text      = oldPwdContent;
                content.AddView(oldPassword, layoutParams);
            }

            var newPwd = new EditText(ActivityContext);

            newPwd.InputType = Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextVariationPassword;
            newPwd.Hint      = "New Password";
            newPwd.Text      = newPwdContent;
            content.AddView(newPwd, layoutParams);

            var repeatPwd = new EditText(ActivityContext);

            repeatPwd.InputType = newPwd.InputType;
            repeatPwd.Hint      = "Repeat Password";
            repeatPwd.Text      = newPwdContent;
            content.AddView(repeatPwd, layoutParams);

            var dialog = new ConfirmationDialog(ActivityContext);

            dialog.Title    = "Change Password";
            dialog.Positive = "Change";
            dialog.Content  = content;

            dialog.OnPositive += async() =>
            {
                await Task.Delay(150);

                if (newPwd.Text == repeatPwd.Text)
                {
                    HideKeyboard();
                    if (hasOld)
                    {
                        complete.SetResult(new Tuple <string, string>(oldPassword.Text, newPwd.Text));
                    }
                    else
                    {
                        complete.SetResult(new Tuple <string, string>(null, newPwd.Text));
                    }
                }
                else
                {
                    msg.Text = "Passwords don't match!";
                    dialog.Reshow();
                }
            };

            dialog.OnNegative += () =>
            {
                HideKeyboard();
                complete.SetResult(null);
            };

            dialog.Show();

            return(complete.Task);
        }