private async void PromptAddUserAgentExecuted()
        {
            LoggingService.Trace("Executing TeamDetailsViewModel.PromptAddUserAgentCommand");

            IsAddingAgent = false;

            var promptResult = await _userDialogs.PromptAsync(new PromptConfig()
            {
                InputType  = InputType.Name,
                OkText     = "Add",
                CancelText = "Cancel",
                Title      = "Agent name",
            });

            if (promptResult.Ok && !string.IsNullOrWhiteSpace(promptResult.Text))
            {
                var result = await _wasabeeApiV1Service.Teams_AddAgentToTeam(Team.Id, promptResult.Text);

                if (result)
                {
                    RefreshCommand.Execute();
                }
                else
                {
                    _userDialogs.Toast("Agent not found or already in team");
                }
            }
        }
Exemplo n.º 2
0
        private async void WriteValueAsync()
        {
            try
            {
                var result =
                    await
                    _userDialogs.PromptAsync("Input a value (as hex whitespace separated)", "Write value",
                                             placeholder : CharacteristicValue);

                if (!result.Ok)
                {
                    return;
                }

                var data = GetBytes(result.Text);

                _userDialogs.ShowLoading("Write characteristic value");
                await Characteristic.WriteAsync(data);

                _userDialogs.HideLoading();

                RaisePropertyChanged(() => CharacteristicValue);
                Messages.Insert(0, $"Wrote value {CharacteristicValue}");
            }
            catch (Exception ex)
            {
                _userDialogs.HideLoading();
                await _userDialogs.AlertAsync(ex.Message);
            }
        }
Exemplo n.º 3
0
        public async Task <(bool, string)> PromptAsync(
            string message,
            string title,
            string okText,
            string cancelText,
            string placeholder,
            string inputText       = null,
            int?maxLength          = null,
            bool inputTypePassword = false)
        {
            PromptConfig config = new PromptConfig
            {
                Message     = message,
                Title       = title,
                Text        = inputText,
                OkText      = okText,
                CancelText  = cancelText,
                Placeholder = placeholder,
                MaxLength   = maxLength,
                InputType   = inputTypePassword ? InputType.Password : InputType.Name,
            };
            var promtResult = await _dialogs.PromptAsync(config);

            var result = (promtResult.Ok, promtResult.Text);

            return(result);
        }
Exemplo n.º 4
0
        private async Task OpenUrl()
        {
            var result = await _userDialogs.PromptAsync("Enter url", inputType : InputType.Url);

            //TODO: Check if the url is valid
            if (!string.IsNullOrWhiteSpace(result.Value))
            {
                var mediaItem = await CrossMediaManager.Current.Play(result.Value);

                await NavigationService.Navigate <PlayerViewModel, IMediaItem>(mediaItem);
            }
        }
        private async Task Login(string password)
        {
            if (String.IsNullOrWhiteSpace(Username) || String.IsNullOrWhiteSpace(password))
            {
                _dialogs.ShowError("Username or password cannot be empty");
                return;
            }

            if (!LoginModel.IsValidUsername(Username))
            {
                _dialogs.ShowError("Invalid username");
                return;
            }

            try {
                CoreApp.StartSession(Username, password, null);
            } catch (CouchbaseLiteException e) {
                if (e.CBLStatus.Code == StatusCode.Unauthorized)
                {
                    var result = await _dialogs.PromptAsync(new PromptConfig {
                        Title         = "Password Changed",
                        OkText        = "Migrate",
                        CancelText    = "Delete",
                        IsCancellable = true,
                        InputType     = Acr.UserDialogs.InputType.Password
                    });

                    if (result.Ok)
                    {
                        CoreApp.StartSession(Username, result.Text, password);
                    }
                    else
                    {
                        Model.DeleteDatabase(Username);
                        Login(password);
                        return;
                    }
                }
                else
                {
                    _dialogs.ShowError($"Login has an error occurred, code = {e.CBLStatus.Code}");
                    return;
                }
            } catch (Exception e) {
                _dialogs.ShowError($"Login has an error occurred, code = {e}");
                return;
            }

            ShowViewModel <TaskListsViewModel>(new { loginEnabled = true });
        }
        public async Task <string> DisplayPromptAync(string title = null, string description = null, string text = null)
        {
            var result = await _userDialogs.PromptAsync(new PromptConfig
            {
                Title      = title,
                InputType  = InputType.Default,
                OkText     = AppResources.Ok,
                CancelText = AppResources.Cancel,
                Message    = description,
                Text       = text
            });

            return(result.Ok ? result.Value ?? string.Empty : null);
        }
Exemplo n.º 7
0
        private async Task AddPlaylist()
        {
            var config = new PromptConfig();

            config.Message = GetText("EnterNewName");
            var result = await _userDialogs.PromptAsync(config);

            if (result.Ok && !string.IsNullOrEmpty(result.Value))
            {
                Playlists.Add(new Playlist()
                {
                    Title = result.Value
                });
                await _playlistService.SavePlaylists(Playlists);
            }
        }
Exemplo n.º 8
0
        private async Task AddNewUser()
        {
            var result = await _dialogs.PromptAsync(new PromptConfig {
                Title       = "New User",
                Placeholder = "User Name"
            });

            if (result.Ok)
            {
                try {
                    Model.CreateNewUser(result.Text);
                } catch (Exception e) {
                    _dialogs.Toast(e.Message);
                }
            }
        }
Exemplo n.º 9
0
        private async Task AddPlaylist()
        {
            var config = new PromptConfig();

            config.Message = GetText("EnterNewName");
            var result = await _userDialogs.PromptAsync(config);

            if (result.Ok && !string.IsNullOrEmpty(result.Value))
            {
                var playlist = new Playlist()
                {
                    Title = result.Value
                };
                Playlists.Add(playlist);
                await _mediaManager.Library.AddOrUpdate <IPlaylist>(playlist);
            }
        }
Exemplo n.º 10
0
        private async Task Edit()
        {
            var result = await _dialogs.PromptAsync(new PromptConfig {
                Title       = "Edit Task",
                Text        = Name,
                Placeholder = "Task Name"
            });

            if (result.Ok)
            {
                try {
                    Model.Edit(result.Text);
                } catch (Exception e) {
                    _dialogs.ShowError(e.Message);
                }
            }
        }
Exemplo n.º 11
0
        private async void EndTripCommandHandler()
        {
            EndTime = DateTimeOffset.UtcNow;
            var titleResult = await _userDialogs.PromptAsync("Enter the Trip Name", "Trip Name", "Save", "Discard", "Name", inputType : InputType.Name);

            var navParams = new NavigationParameters();

            if (titleResult.Ok)
            {
                var newTrip = new TripModel
                {
                    Name      = titleResult.Text,
                    StartTime = StartTime,
                    EndTime   = EndTime,
                    Route     = Route.ToList()
                };
                navParams.Add("NewTripDetails", newTrip);
            }

            await _navigationService.GoBackAsync(navParams, useModalNavigation : true);
        }
Exemplo n.º 12
0
        private async Task ExecuteAddNewtItem()
        {
            var result = await _dialogs.PromptAsync(
                message : "Name of ToDo Item",
                title : "Add New Item");

            var newItemTitle = result.Value;

            bool makeActive = true;

            if (this.TodoLists.Any(x => x.IsActive))
            {
                makeActive = await _dialogs.ConfirmAsync(
                    $"Do you want to make list '{result.Value}' your active list?",
                    "Active List",
                    okText : "Yes",
                    cancelText : "No");
            }

            _dialogs.ShowLoading(string.Empty);

            var created = await _repo.AddList(new Models.TodoList
            {
                Title = newItemTitle
            });

            // if user wants to make it active, activate this one,
            // calling the repo method will deactivate all other lists
            if (makeActive)
            {
                await _repo.ActivateList(created.Id);
            }

            TodoLists.Add(created);

            _dialogs.HideLoading();

            // navigate to the new list
            SelectItem.Execute(created);
        }
        private async Task EditTeamNameExecuted(Team team)
        {
            var promptResult = await _userDialogs.PromptAsync(new PromptConfig()
            {
                InputType  = InputType.Name,
                OkText     = "Ok",
                CancelText = "Cancel",
                Title      = "Change team name",
            });

            if (promptResult.Ok && !string.IsNullOrWhiteSpace(promptResult.Text))
            {
                var result = await _wasabeeApiV1Service.Teams_RenameTeam(team.Id, promptResult.Text);

                if (result)
                {
                    RefreshCommand.Execute();
                }
                else
                {
                    _userDialogs.Toast("Rename failed");
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Callback method for starting connection
        /// </summary>
        async void OnConnectionStarted()
        {
            // Bail if the user has already started a connection
            if (IsAttemptingConnection())
            {
                return;
            }

            try
            {
                // Connect to IP
                bool success = connection.Connect(IPAddress);

                if (!success)
                {
                    if (!QTMNetworkConnection.QTMVersionSupported)
                    {
                        // QTM is not supported
                        userDialogs.Alert("Please make sure that you are connecting to a Windows PC with " +
                                          "a Qualisys Track Manager software version of at least 2.16", "Attention", "Dismiss");
                    }
                    else
                    {
                        // There was an error with the connection
                        notificationService.Show("Attention", "There was a connection error, please check IP address");
                    }

                    return;
                }
                else if (connection.HasPassword())
                {
                    // NOTE: A new propmt configuration has to be created everytime we run it
                    // if we do not do this the acr library will add an action to it and since
                    // it is async it does not expect that and will thus throw an error
                    PromptResult result = await userDialogs
                                          .PromptAsync(
                        new PromptConfig()
                        .SetTitle("Please enter password (blank for slave mode)")
                        .SetOkText("Connect"));

                    if (!result.Ok)
                    {
                        return;
                    }

                    // Connect to host
                    connection.Connect(IPAddress, result.Text);

                    if (!connection.TakeControl() && result.Text != "")
                    {
                        ToastAction toastAction = new ToastAction().SetText("Retry").SetAction(() => OnConnectionStarted());
                        ToastConfig toastConfig = new ToastConfig("Incorrect Password")
                                                  .SetAction(toastAction);

                        userDialogs.Toast(toastConfig);
                        return;
                    }
                }

                // Send connection instance to settings service
                if (!SettingsService.Initialize())
                {
                    // There was a problem when attempting to establish the connection
                    userDialogs.Alert("There was a communication mismatch with QTM, please make sure you are running the" +
                                      " latest version of this application and that you have the QTM version specified in" +
                                      " the requirements", "Error", "Dismiss");

                    connection.Disconnect();
                    return;
                }

                // Show loading screen whilst connecting
                // This loading screen is disabled in the CameraPageViewModel constructor
                Task.Run(() => userDialogs.ShowLoading("Establishing connection..."));

                // Fetch information from system and fill structures accordingly
                CameraManager.GenerateCameras();

                // Connection was successfull
                // Navigate to camera page
                NavigationParameters navigationParams = new NavigationParameters();
                navigationParams.Add(Helpers.Constants.NAVIGATION_DEMO_MODE_STRING, false);
                Device.BeginInvokeOnMainThread(() => navigationService.NavigateAsync("CameraPage", navigationParams));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                notificationService.Show("Attention", "Please make sure that QTM is up and running and that the cameras are plugged in");

                Task.Run(() => userDialogs.HideLoading());

                return;
            }
        }
Exemplo n.º 15
0
        public PeripheralViewModel(ICentralManager centralManager, IUserDialogs dialogs)
        {
            this.SelectCharacteristic = ReactiveCommand.Create <GattCharacteristicViewModel>(x => x.Select());

            this.ConnectionToggle = ReactiveCommand.Create(() =>
            {
                // don't cleanup connection - force user to d/c
                if (this.peripheral.Status == ConnectionState.Disconnected)
                {
                    this.peripheral.Connect();
                }
                else
                {
                    this.peripheral.CancelConnection();
                }
            });

            this.PairToDevice = ReactiveCommand.Create(() =>
            {
                if (!centralManager.Features.HasFlag(BleFeatures.PairingRequests))
                {
                    dialogs.Toast("Pairing is not supported on this platform");
                }
                else if (this.peripheral.PairingStatus == PairingState.Paired)
                {
                    dialogs.Toast("Peripheral is already paired");
                }
                else
                {
                    this.peripheral
                    .PairingRequest()
                    .Subscribe(x =>
                    {
                        var txt = x ? "Peripheral Paired Successfully" : "Peripheral Pairing Failed";
                        dialogs.Toast(txt);
                        this.RaisePropertyChanged(nameof(this.PairingText));
                    });
                }
            });

            this.RequestMtu = ReactiveCommand.CreateFromTask(
                async x =>
            {
                if (!centralManager.Features.HasFlag(BleFeatures.MtuRequests))
                {
                    dialogs.Alert("MTU Request not supported on this platform");
                }
                else
                {
                    var result = await dialogs.PromptAsync(new PromptConfig()
                                                           .SetTitle("MTU Request")
                                                           .SetMessage("Range 20-512")
                                                           .SetInputMode(InputType.Number)
                                                           .SetOnTextChanged(args =>
                    {
                        var len = args.Value?.Length ?? 0;
                        if (len > 0)
                        {
                            if (len > 3)
                            {
                                args.Value = args.Value.Substring(0, 3);
                            }
                            else
                            {
                                var value    = Int32.Parse(args.Value);
                                args.IsValid = value >= 20 && value <= 512;
                            }
                        }
                    })
                                                           );
                    if (result.Ok)
                    {
                        var actual = await this.peripheral.RequestMtu(Int32.Parse(result.Text));
                        dialogs.Toast("MTU Changed to " + actual);
                    }
                }
            },
                this.WhenAny(
                    x => x.ConnectText,
                    x => x.GetValue().Equals("Disconnect")
                    )
                );
        }
        private async Task OnAddActivity()
        {
            var fileData = await CrossFilePicker.Current.PickFile();

            await Task.Delay(TimeSpan.FromSeconds(1));

            if (fileData == null || !fileData.FileName.EndsWith("gpx"))
            {
                return;
            }

            var result = await _dialogs.PromptAsync(new PromptConfig
            {
                Title   = "Agregar actividad",
                Message = "Ingresa el nombre de la actividad",
                OkText  = "Aceptar"
            });

            var dbConnection  = App.SqliteCon;
            var document      = new XmlDocument();
            var base64Encoded = Convert.ToBase64String(fileData.DataArray);;

            using (var stream = new MemoryStream(fileData.DataArray))
            {
                document.Load(stream);
            }

            var recorrido = new Recorrido()
            {
                Nombre     = result.Value,
                Fecha_hora = GpxParser.GetDateTime()
            };
            int idRecorrido = await dbConnection.InsertRecorridoAsync(recorrido);

            GpxParser.SetCurrentDoc(document);
            var points = GpxParser.ParseDoc(idRecorrido);

            foreach (var punto in points)
            {
                dbConnection.InsertPunto(punto);
            }

            var json = JsonConvert.SerializeObject(new
            {
                User            = Preferences.Get(Config.UserId, "mvega", Config.SharedName),
                Nombre          = result.Value,
                IdTipoActividad = 1,
                Recorrido       = base64Encoded,
                Fecha           = GpxParser.GetDateTime(),
                Duracion        = GpxParser.GetTotalTime(points),
                Kilometros      = GpxParser.PointsToDistanceInKm(points),
                EsEvento        = false
            });

            var response = await Connection.Post(Urls.Actividades, json, 120);

            if (!response.Succeeded)
            {
                _dialogs.Alert("Ocurrió un error al sincronizar datos");
            }

            _dialogs.Toast("Actividad sincronizada correctamente");
        }