Exemple #1
0
 public AddDrinkRecipePageViewModel(
     IUserInteraction userInteraction,
     INavigationService navigationService,
     IDrinkRecipeBuilder drinkRecipeBuilder,
     IDrinkRecipesRepository drinkRecipesRepository,
     ICrossMediaService crossMediaService,
     ISelectionHost <DrinkIngredientViewModel> selectionHost)
     : base(userInteraction, navigationService, drinkRecipeBuilder, crossMediaService, selectionHost)
 {
     _userInteraction        = userInteraction;
     _drinkRecipeBuilder     = drinkRecipeBuilder;
     _drinkRecipesRepository = drinkRecipesRepository;
 }
Exemple #2
0
        public EditDrinkRecipePageViewModel(
            IUserInteraction userInteraction,
            IDrinkRecipeBuilder drinkRecipeBuilder,
            INavigationService navigationService,
            IDrinkRecipesRepository drinkRecipesRepository,
            ICrossMediaService crossMediaService,
            ISelectionHost <DrinkIngredientViewModel> selectionHost,
            DrinkRecipeViewModel drinkRecipeViewModel)
            : base(userInteraction, navigationService, drinkRecipeBuilder, crossMediaService, selectionHost)
        {
            _userInteraction        = userInteraction;
            _drinkRecipeBuilder     = drinkRecipeBuilder;
            _drinkRecipesRepository = drinkRecipesRepository;
            _drinkIngredient        = drinkRecipeViewModel;

            DrinkName = drinkRecipeViewModel.Name;
            ByteImage = drinkRecipeViewModel.ByteImage;
            DrinkIngredients.AddRange(drinkRecipeViewModel.IngredientViewModels);
        }
Exemple #3
0
        public SelectIngredientsPageViewModel(
            IIngredientsRepository ingredientsRepository,
            INavigationService navigationService,
            ISelectionHost <DrinkIngredientViewModel> selectionHost,
            IEnumerable <DrinkIngredientViewModel> alreadySelected) : base(navigationService, ingredientsRepository)
        {
            _excludedIngredients = alreadySelected;
            _navigationService   = navigationService;
            _selectionHost       = selectionHost;

            this.WhenAnyValue(vm => vm.SelectedDrinkIngredient)
            .Where(ingredient => ingredient != null)
            .ManySelect(async ingredientViewModel =>
            {
                selectionHost.Selection = await ingredientViewModel;
                await Observable.FromAsync(async _ => await _navigationService.PopAsync())
                .ObserveOn(RxApp.MainThreadScheduler);
            })
            .Subscribe();

            var navigationPop = Observable.FromAsync(_ => _navigationService.PopAsync());

            this.WhenAnyValue(vm => vm.SelectedDrinkIngredient)
            .Where(ingredient => ingredient != null)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Do(ingredient => _selectionHost.Selection = ingredient)
            .Select(_ => navigationPop)
            .Switch()
            .Subscribe();


            //this.WhenAnyValue(vm => vm.SelectedDrinkIngredient)
            //	.Where(ingredient => ingredient != null)
            //	.ObserveOn(RxApp.MainThreadScheduler)
            //	.Do(ingredient => selectionHost.Selection = ingredient)
            //	.Select(_ => _navigationService.PopAsync().ToObservable())
            //	.Switch()
            //	.Subscribe();
        }
        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;
                }
            });
        }