Exemplo n.º 1
0
        public static Task <JwtLoginCredentials> GetInputAsync(string title)
        {
            var         context = GetContext();
            var         tcs     = new TaskCompletionSource <JwtLoginCredentials>();
            var         result  = new JwtLoginCredentials();
            AlertDialog dialog  = null;

            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.SetTitle(title);

            var viewInflated  = LayoutInflater.From(context).Inflate(Resource.Layout.login_view, null, false);
            var userInput     = viewInflated.FindViewById <AppCompatEditText>(Resource.Id.input_user);
            var passwordInput = viewInflated.FindViewById <AppCompatEditText>(Resource.Id.input_password);

            builder.SetView(viewInflated);

            builder.SetOnCancelListener(new DialogInterfaceOnCancelListener(() => tcs.TrySetResult(null)));
            builder.SetOnDismissListener(new DialogInterfaceOnDismissListener(() => tcs.TrySetResult(null)));
            builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) =>
            {
                result.User     = userInput.Text;
                result.Password = passwordInput.Text;
                tcs.TrySetResult(result);
                dialog.Dismiss();
            });
            builder.SetNegativeButton(Android.Resource.String.Cancel, (sender, args) =>
            {
                tcs.TrySetResult(null);
                dialog.Cancel();
            });

            dialog = builder.Show();

            return(tcs.Task);
        }