add images work !

pull/66/head
Alexandre AGOSTINHO 2 years ago
parent c27eb0ea73
commit f955fd809f

@ -13,6 +13,9 @@ namespace Views
private Ingredient ingredient; private Ingredient ingredient;
private PreparationStep preparationStep; private PreparationStep preparationStep;
private string titleRecipe; private string titleRecipe;
public FileResult ImageSource { get; private set; } = null;
public string? ImageSourcePath { get; private set; } = null;
public MasterManager Master => (Application.Current as App).Master; public MasterManager Master => (Application.Current as App).Master;
public User CurrentUser => Master.User.CurrentConnected; public User CurrentUser => Master.User.CurrentConnected;
public Recipe RecipeToAdd{ get=> recipeToAdd; set => recipeToAdd = value; } public Recipe RecipeToAdd{ get=> recipeToAdd; set => recipeToAdd = value; }
@ -38,20 +41,30 @@ namespace Views
IngredientList = new List<Ingredient>(); IngredientList = new List<Ingredient>();
PreparationStepList = new List<PreparationStep>(); PreparationStepList = new List<PreparationStep>();
} }
private void PickPhoto(object sender, EventArgs e) private async void PickPhoto(object sender, EventArgs e)
{ {
MediaPicker.PickPhotoAsync(); ImageSource = await MediaPicker.Default.PickPhotoAsync();
} }
private void AddRecipeValidation(object sender, EventArgs e) private async void AddRecipeValidation(object sender, EventArgs e)
{ {
if (string.IsNullOrWhiteSpace(TitleRecipe)) if (string.IsNullOrWhiteSpace(TitleRecipe))
{ {
DisplayAlert("Erreur", "Entrez un nom de recette.", "Ok"); await DisplayAlert("Erreur", "Entrez un nom de recette.", "Ok");
return; return;
} }
if (ImageSource != null)
{
// save the file into local storage
ImageSourcePath = Path.Combine(FileSystem.Current.AppDataDirectory, $"{TitleRecipe}.{ImageSource.FileName}");
using Stream sourceStream = await ImageSource.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(ImageSourcePath);
await sourceStream.CopyToAsync(localFileStream);
}
RecipeType newRecipeType = GetSelectedRecipeType(); RecipeType newRecipeType = GetSelectedRecipeType();
Priority selectedPriority = GetSelectedPriority(); Priority selectedPriority = GetSelectedPriority();
string authorMail = CurrentUser.Mail; string authorMail = CurrentUser.Mail;
@ -62,7 +75,8 @@ namespace Views
newRecipeType, newRecipeType,
selectedPriority, selectedPriority,
null, null,
authorMail authorMail,
ImageSourcePath
); );
newRecipe.PreparationSteps.AddRange(PreparationStepList); newRecipe.PreparationSteps.AddRange(PreparationStepList);
newRecipe.Ingredients.AddRange(IngredientList); newRecipe.Ingredients.AddRange(IngredientList);
@ -70,18 +84,18 @@ namespace Views
bool isRecipeSave = Master.Recipe.AddRecipeToData(newRecipe); bool isRecipeSave = Master.Recipe.AddRecipeToData(newRecipe);
if (isRecipeSave) if (isRecipeSave)
{ {
DisplayAlert("Succès", "La recette a été ajoutée avec succès", "OK"); await DisplayAlert("Succès", "La recette a été ajoutée avec succès", "OK");
} }
else else
{ {
DisplayAlert("Echec", "La recette n'a pas été ajoutée", "OK"); await DisplayAlert("Echec", "La recette n'a pas été ajoutée", "OK");
} }
newRecipe = new Recipe("Nouvelle Recette"); newRecipe = new Recipe("Nouvelle Recette");
PreparationStepList.Clear(); PreparationStepList.Clear();
IngredientList.Clear(); IngredientList.Clear();
Navigation.PopAsync(); await Navigation.PopAsync();
} }
private void AddStepRecipe(object sender, EventArgs e) private void AddStepRecipe(object sender, EventArgs e)
@ -115,6 +129,12 @@ namespace Views
private void AddIngredient(object sender, EventArgs e) private void AddIngredient(object sender, EventArgs e)
{ {
if (nameIngredient.Text is null || quantityNumber.Text is null)
{
DisplayAlert("Warning", "some values are null, please provide correct values.", "Ok");
return;
}
string ingredientName = nameIngredient.Text; string ingredientName = nameIngredient.Text;
int numberQuantity = Convert.ToInt32(quantityNumber.Text); int numberQuantity = Convert.ToInt32(quantityNumber.Text);
Unit unitQuantity = (Unit)UnitPicker.SelectedItem; Unit unitQuantity = (Unit)UnitPicker.SelectedItem;

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:model="clr-namespace:Model;assembly=Model"
xmlns:local="clr-namespace:Views" xmlns:local="clr-namespace:Views"
x:Class="Views.MyPosts" x:Class="Views.MyPosts"
Title="MyPosts"> Title="MyPosts">
@ -8,26 +9,36 @@
<local:ContainerBase <local:ContainerBase
NeedReturn="True"> NeedReturn="True">
<!-- Flyout -->
<local:ContainerBase.MyFlyoutContent> <local:ContainerBase.MyFlyoutContent>
<Grid RowDefinitions="250, *, *" VerticalOptions="Fill"> <Grid RowDefinitions="Auto, *, *" VerticalOptions="Center">
<VerticalStackLayout Grid.Row="1"> <VerticalStackLayout Grid.Row="1">
<Button Text="Mes informations" ImageSource="person_default.png" Style="{StaticResource button1}" Grid.Row="1"/> <Button Text="Mes informations"
<Button Text="Modifier" ImageSource="settings_icon.png" Style="{StaticResource button1}" Grid.Row="2"/> ImageSource="person_default.png"
Style="{StaticResource button1}"
Grid.Row="1"
Clicked="MyInformations_Clicked"/>
<Button Text="Ajouter une recette"
ImageSource="add_icon.png"
Style="{StaticResource button1}"
Grid.Row="2"
Clicked="AddRecipe_Clicked"/>
</VerticalStackLayout> </VerticalStackLayout>
</Grid> </Grid>
</local:ContainerBase.MyFlyoutContent> </local:ContainerBase.MyFlyoutContent>
<!-- Master -->
<local:ContainerBase.MyContent> <local:ContainerBase.MyContent>
<ScrollView> <ScrollView>
<StackLayout> <StackLayout MinimumWidthRequest="400">
<Label Text="Mon profil" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}" <Label
FontAttributes="Bold" Text="{Binding RecipesDisplayed.Description}"
FontSize="24" Padding="15, 15, 20, 5"/> TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}"
<Label Text="Mes publications" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}" FontSize="24"
FontSize="20" Padding="15"/> Padding="15"/>
<FlexLayout <FlexLayout
Margin="0, 15" Margin="0, 15"
@ -35,18 +46,22 @@
JustifyContent="Start" JustifyContent="Start"
AlignItems="Center" AlignItems="Center"
AlignContent="SpaceEvenly" AlignContent="SpaceEvenly"
HorizontalOptions="Center"> HorizontalOptions="Center"
BindableLayout.ItemsSource="{Binding RecipesDisplayed}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Recipe">
<local:RecipeCase CaseImageSource="room_service_icon.png"/> <local:RecipeCase
<local:RecipeCase CaseImageSource="room_service_icon.png"/> CaseImageSource="{Binding Image}"
<local:RecipeCase CaseImageSource="room_service_icon.png"/> RecipeTitle="{Binding Title}"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/> </DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout> </FlexLayout>
</StackLayout> </StackLayout>
</ScrollView> </ScrollView>
</local:ContainerBase.MyContent> </local:ContainerBase.MyContent>
</local:ContainerBase> </local:ContainerBase>

@ -1,9 +1,34 @@
using Model;
namespace Views; namespace Views;
public partial class MyPosts : ContentPage public partial class MyPosts : ContentPage
{ {
public MasterManager Master => (Application.Current as App).Master;
private readonly RecipeCollection _recipesDisplayed;
public ReadOnlyObservableRecipeCollection RecipesDisplayed { get; private set; }
public Recipe Recipe => Master.Recipe.CurrentSelected;
public MyPosts() public MyPosts()
{ {
_recipesDisplayed = Master.Recipe.GetRecipeByAuthor(Master.User.CurrentConnected.Mail);
RecipesDisplayed = new ReadOnlyObservableRecipeCollection(_recipesDisplayed);
InitializeComponent(); InitializeComponent();
BindingContext = this;
}
private void MyInformations_Clicked(object sender, EventArgs e)
{
Navigation.PopModalAsync();
}
private void AddRecipe_Clicked(object sender, EventArgs e)
{
Navigation.PushModalAsync(new AddRecipe());
} }
} }

@ -18,8 +18,8 @@
Style="{StaticResource button1}" Style="{StaticResource button1}"
Grid.Row="1" Grid.Row="1"
Clicked="OnMyRecipeClicked"/> Clicked="OnMyRecipeClicked"/>
<Button Text="Ajouter Recette" <Button Text="Ajouter une recette"
ImageSource="settings_icon.png" ImageSource="add_icon.png"
Style="{StaticResource button1}" Style="{StaticResource button1}"
Grid.Row="2" Grid.Row="2"
Clicked="OnAddRecipeClicked"/> Clicked="OnAddRecipeClicked"/>

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 -960 960 960" width="48"><path d="M450-200v-250H200v-60h250v-250h60v250h250v60H510v250h-60Z"/></svg>

After

Width:  |  Height:  |  Size: 163 B

Loading…
Cancel
Save