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); } }
public ShowIngredientsPageViewModel( IIngredientsRepository ingredientsRepository, INavigationService navigationService, IUserInteraction userInteraction) : base(navigationService, ingredientsRepository) { this.WhenAnyObservable(vm => vm.Ingredients.ItemChanged) .ObserveOn(RxApp.MainThreadScheduler) .Where(arg => arg.PropertyName == nameof(DrinkIngredientViewModel.TickSelected)) .Select(arg => (DrinkIngredientViewModel)arg.Sender) .Do(ingredient => SelectedDrinkIngredient = ingredient) .Subscribe(async ingredientViewModel => { var selections = new List <string>() { "Edit", "Delete" }; var result = await userInteraction.DisplayActionSheetAsync( $"{ingredientViewModel.Name} selected!", "Cancel", null, selections.ToArray()); if (result == "Edit") { var navigationParameter = new TypedParameter(typeof(DrinkIngredientViewModel), ingredientViewModel); await navigationService.PushAsync <EditIngredientPageViewModel>(navigationParameter); } else if (result == "Delete") { await ingredientsRepository.DeleteAsync(ingredientViewModel.Ingredient); await ActivateAsync(); } else { ExceptionFactory.Get <NotImplementedException>("That selection is not jet implemented!"); } }); }
public async Task <byte[]?> GetPhotoAsync() { var galleryOrCamera = await _userInteraction.DisplayActionSheetAsync("How to pick an image", "cancel", null, "gallery", "camera", "delete image"); MediaFile file = null; switch (galleryOrCamera) { case "gallery": file = await CrossMedia.Current.PickPhotoAsync(); break; case "camera": file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()); break; case "delete image": return(new byte[0]); default: return(null); } if (file == null) { return(null); } using var stream = file.GetStream(); var result = new byte[stream.Length]; stream.Read(result, 0, (int)stream.Length); file.Dispose(); return(result); }