public async Task DeviceSelectedAsync(string mac, string name)
        {
            IsBusy = true;

            var connected = await _bluetoothService.ConnectAsync(name, mac);

            if (connected)
            {
                await _userInteraction.DisplayAlertAsync("Info", "Connected to device!", "OK");

                await _navigationService.PopToRootAsync();
            }
            else
            {
                await _userInteraction.DisplayAlertAsync("Info", "You were not able to connect to the device!", "OK");
            }

            IsBusy = false;
        }
Пример #2
0
        protected override async Task CompletedTemplateMethod(IDrinkRecipeBuilder drinkRecipeBuilder,
                                                              IList <DrinkIngredient> ingredients)
        {
            var drink = _drinkRecipeBuilder
                        .Default()
                        .SetName(DrinkName)
                        .SetByteImage(ByteImage)
                        .AddIngredients(ingredients.ToArray())
                        .Build();

            await _drinkRecipesRepository.InsertWithChildrenAsync(drink);

            await _userInteraction.DisplayAlertAsync("Info", "Drink Added to the Database!", "Ok");
        }
        public async Task DrinkSelectedAsync(DrinkRecipeViewModel drinkRecipeViewModel)
        {
            var selection = new List <string>()
            {
                "Edit", "Delete", "Make drink"
            };

            var result = await _userInteraction.DisplayActionSheetAsync($"{drinkRecipeViewModel.Name} selected!",
                                                                        "Cancel", null, selection.ToArray());

            if (result == null)
            {
                return;
            }
            if (result.Equals("Edit"))
            {
                var parmeter = new TypedParameter(typeof(DrinkRecipeViewModel), drinkRecipeViewModel);
                await _navigationService.PushAsync <EditDrinkRecipePageViewModel>(parmeter);
            }
            else if (result.Equals("Delete"))
            {
                await _drinkRecipeRepository.DeleteAsync(drinkRecipeViewModel.DrinkRecipe);

                Drinks.Remove(drinkRecipeViewModel);
            }
            else if (result.Equals("Make drink"))
            {
                if (!_bluetoothService.IsConnected())
                {
                    await _userInteraction
                    .DisplayAlertAsync("Info", "Cannot send data to the cocktail machine. \n" +
                                       "You are not connected with the bluetooth module of the cocktail machine. \n" +
                                       "Navigate back to the welcomepage and connect with the device!", "Ok");

                    return;
                }

                await TransmitAsync(drinkRecipeViewModel);
            }
        }
        protected ConfigureDrinkRecipePageViewModelBase(
            IUserInteraction userInteraction,
            INavigationService navigationService,
            IDrinkRecipeBuilder drinkRecipeBuilder,
            ICrossMediaService crossMediaService,
            ISelectionHost <DrinkIngredientViewModel> selectionHost)
        {
            _userInteraction   = userInteraction;
            _navigationService = navigationService;
            SelectionHost      = selectionHost;

            var addIngredientCanExecute = this.WhenAnyValue(vm => vm.DrinkIngredients.Count,
                                                            i => i < 6);

            addIngredientCanExecute
            .Where(canExecute => !canExecute)
            .SubscribeAsync(async() => await _userInteraction.DisplayAlertAsync("Info",
                                                                                "Cannot have more then 6 ingredients", "Ok"));

            var alreadySelectedParameter = new TypedParameter(typeof(IEnumerable <DrinkIngredientViewModel>), DrinkIngredients);

            AddIngredientCommand = ReactiveCommand.CreateFromTask(async _ =>
                                                                  await _navigationService.PushAsync <SelectIngredientsPageViewModel>(alreadySelectedParameter),
                                                                  addIngredientCanExecute);

            AbortCommand = ReactiveCommand.CreateFromTask(async _ => await _navigationService.PopAsync());

            var completedCommandCanExecute = DrinkIngredients.CountChanged
                                             .Select(count => count != 0);

            completedCommandCanExecute
            .Where(hasIngredients => !hasIngredients)
            .Skip(1)
            .Select(async _ =>
                    await _userInteraction.DisplayAlertAsync("Warning", "Add ingredients or abort the process!", "ok"))
            .Subscribe(_ => {}, ex => throw ex);

            CompleteCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                if (!IsDrinkValid(out StringBuilder msgBuilder))
                {
                    await userInteraction.DisplayAlertAsync("Error", msgBuilder.ToString(), "Ok");
                    return;
                }

                var ingredients = DrinkIngredients
                                  .Select(ivm => ivm.UpdateDrinkIngredientModel())
                                  .ToList();

                await CompletedTemplateMethod(drinkRecipeBuilder, ingredients);
                await navigationService.PopAsync();
            }, completedCommandCanExecute);
            CompleteCommand.ThrownExceptions.Subscribe(exception => throw exception);

            ByteImageTapRecognizerCommand = ReactiveCommand.CreateFromTask(async _ =>
            {
                var photo = await crossMediaService.GetPhotoAsync();
                if (photo != null)
                {
                    ByteImage = photo;
                }
            });
        }