Exemplo n.º 1
0
        private void AddComputerButtonOnClick(object sender, EventArgs eventArgs)
        {
            var dialogBuilder = new MaterialDialog.Builder(this)
                                .Title(Resource.String.app_addcomputer_title)
                                .CustomView(Resource.Layout.dialog_addcomputer, true)
                                .PositiveText(Resource.String.app_addcomputer_connect)
                                .NegativeText(Resource.String.app_addcomputer_cancel)
                                .OnPositive((dialog, w) =>
            {
                IpAddresses.Add(new ComputerModel(
                                    dialog.CustomView.FindViewById <EditText>(Resource.Id.ipAddress).Text,
                                    dialog.CustomView.FindViewById <EditText>(Resource.Id.password).Text));
                BlobCache.UserAccount.InsertObject("ipaddresses", IpAddresses);
            }).Build();

            var positiveAction = dialogBuilder.GetActionButton(DialogAction.Positive);
            var ipControl      = dialogBuilder.CustomView.FindViewById <EditText>(Resource.Id.ipAddress);
            var token          = new CancellationTokenSource();

            positiveAction.Enabled = false;

            ipControl.TextChanged += (o, args) =>
            {
                token.Cancel();
                token = new CancellationTokenSource();
                if (ValidateIPv4(ipControl.Text) && IpAddresses.All(i => i.Ip != ipControl.Text))
                {
                    Task.Factory.StartNew(
                        async() => positiveAction.Enabled = await Scanner.CheckHostForVlc(ipControl.Text),
                        token.Token);
                }
                else
                {
                    positiveAction.Enabled = false;
                }
            };

            dialogBuilder.Show();
        }