Merge pull request 'fix/app-ready' (#67) from fix/app-ready into dev
continuous-integration/drone/push Build is passing Details

Reviewed-on: #67
dev
Alexandre AGOSTINHO 2 years ago
commit 136d00d431

@ -17,6 +17,7 @@ namespace Model
[DataMember(Name = "name")] private string _name = "";
[DataMember(Name = "surname")] private string _surname = "";
[DataMember(Name = "mail")] private string _mail = "";
[DataMember(Name = "profilepic")] private string _profilePict = "default_picture.png";
[DataMember(Name = "priorities")]
private readonly List<Priority> _priorities = new List<Priority>
@ -93,8 +94,15 @@ namespace Model
/// For now, we define the ProfilePict as a string which is "PhotoParDefaut"
/// when the value is null.
/// </summary>
[DataMember(Name = "profilepic")]
public string ProfilePict { get; private set; } = "default_picture.png";
public string ProfilePict
{
get => _profilePict;
set
{
_profilePict = value;
OnPropertyChanged();
}
}
/// <summary>
/// This is the list of priorities specific tu the user. This list is initiate

@ -11,7 +11,7 @@
TitleMini="Ajouter une recette"
NeedReturn="True"
HeightRequest="100"/>
<Grid ColumnDefinitions="auto, auto"
<Grid ColumnDefinitions="auto, auto, auto"
RowDefinitions="auto,auto,auto,auto,auto,auto, auto, auto, auto,auto"
Margin="50,20,20,20">
<Label Text="Titre de la recette :"/>
@ -28,6 +28,7 @@
<RadioButton x:Name="CheckDessert" Grid.Row="3" Margin="155,0" />
<Label Text="Dessert" Grid.Row="3" Margin="185,20"/>
<Button Text="pick photo" Clicked="PickPhoto" Grid.Row="1" Grid.Column="1"/>
<Button Text="Import recipe (json)" Clicked="Import_Clicked" Grid.Row="1" Grid.Column="2"/>
<Label Text="Type de priorité :" Grid.Row="4" Margin="0,10,0,20"/>
<VerticalStackLayout Grid.Row="5">
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">

@ -175,6 +175,33 @@ namespace Views
DisplayAlert("Liste d'ingrédient vide", "Suppression impossible car la liste des ingrédients est vide.", "Ok");
}
}
private async void Import_Clicked(object sender, EventArgs e)
{
try
{
var result = await FilePicker.Default.PickAsync();
if (result != null)
{
Master.Data.Import<Recipe>(result.FullPath);
// Save data.
Debug.Write($"[ {DateTime.Now:H:mm:ss} ] Saving...\t");
Master.Data.SaveData();
Debug.WriteLine("Done.");
Debug.WriteLine(FileSystem.Current.AppDataDirectory);
await DisplayAlert("Import", "Recipe was successfully imported.", "Ok");
await Navigation.PopModalAsync();
}
}
catch (Exception ex)
{
await DisplayAlert("Import", $"Unable to import file.\n{ex.Message}", "Ok");
}
}
private RecipeType GetSelectedRecipeType()
{
if (CheckEntree.IsChecked)
@ -221,5 +248,7 @@ namespace Views
return Priority.Gourmet;
}
}
}
}

@ -66,7 +66,7 @@
FontSize="24"
Padding="15"/>
<FlexLayout
<FlexLayout x:Name="rc_flex"
Margin="0, 15"
Wrap="Wrap"
JustifyContent="Start"
@ -76,11 +76,21 @@
BindableLayout.ItemsSource="{Binding RecipesDisplayed}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Recipe">
<DataTemplate x:DataType="model:Recipe" x:Name="rc_case">
<local:RecipeCase
CaseImageSource="{Binding Image}"
RecipeTitle="{Binding Title}"/>
RecipeTitle="{Binding Title}">
<FlyoutBase.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Export recipe"
Clicked="ExportRecipe_Clicked"/>
</MenuFlyout>
</FlyoutBase.ContextFlyout>
</local:RecipeCase>
</DataTemplate>
</BindableLayout.ItemTemplate>

@ -1,4 +1,6 @@
using AppException;
using CommunityToolkit.Maui.Storage;
using Microsoft.Maui.Controls;
using Model;
using System.Collections.ObjectModel;
@ -99,5 +101,21 @@ namespace Views
description: "Suggestions",
recipes: Master.Recipe.GetRecipesByPriorityOrder(Master.User.CurrentConnected.Priorities)));
}
private async void ExportRecipe_Clicked(object sender, EventArgs e)
{
var result = await FolderPicker.Default.PickAsync(FileSystem.Current.AppDataDirectory, new CancellationToken());
Master.Recipe.CurrentSelected = (Recipe)(sender as MenuFlyoutItem).BindingContext;
if (result.IsSuccessful)
{
Master.Data.Export(Recipe, Path.Combine(result.Folder.Path, $"{Recipe.Id}.{Recipe.Title.Replace(" ", "")}.json"));
await DisplayAlert("Export", "Recipe was successfully exported.", "Ok");
}
else
{
await DisplayAlert("Export", "Unable to export recipe.", "Ok");
}
}
}
}

@ -50,11 +50,19 @@
BindableLayout.ItemsSource="{Binding RecipesDisplayed}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Recipe">
<DataTemplate x:DataType="model:Recipe" x:Name="rc_case">
<local:RecipeCase
CaseImageSource="{Binding Image}"
RecipeTitle="{Binding Title}"/>
RecipeTitle="{Binding Title}">
<FlyoutBase.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Export recipe"
Clicked="ExportRecipe_Clicked"/>
</MenuFlyout>
</FlyoutBase.ContextFlyout>
</local:RecipeCase>
</DataTemplate>
</BindableLayout.ItemTemplate>

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Storage;
using Model;
namespace Views;
@ -31,4 +32,20 @@ public partial class MyPosts : ContentPage
{
Navigation.PushModalAsync(new AddRecipe());
}
private async void ExportRecipe_Clicked(object sender, EventArgs e)
{
var result = await FolderPicker.Default.PickAsync(FileSystem.Current.AppDataDirectory, new CancellationToken());
Master.Recipe.CurrentSelected = (Recipe)(sender as MenuFlyoutItem).BindingContext;
if (result.IsSuccessful)
{
Master.Data.Export(Recipe, Path.Combine(result.Folder.Path, $"{Recipe.Id}.{Recipe.Title.Replace(" ", "")}.json"));
await DisplayAlert("Export", "Recipe was successfully exported.", "Ok");
}
else
{
await DisplayAlert("Export", "Unable to export recipe.", "Ok");
}
}
}

@ -15,14 +15,21 @@
<local:ReturnButton NeedReturn="{Binding NeedReturn, Source={x:Reference fl}}" Grid.Row="0"
HorizontalOptions="Start" Padding="10, 10, 0, 0"/>
<!-- Header -->
<ImageButton Source="person_default.png" HorizontalOptions="Center"
<ImageButton Source="{Binding CurrentConnected.ProfilePict}" HorizontalOptions="Center"
BackgroundColor="{StaticResource Secondary}"
WidthRequest="100" HeightRequest="100"
CornerRadius="50" Margin="0, 30, 0, 10"
BorderWidth="5" BorderColor="Black"
IsVisible="{Binding CurrentConnected, Converter={toolkit:IsNotNullConverter}}"
Grid.RowSpan="2"
Clicked="ProfileButton_Clicked"/>
Clicked="ProfileButton_Clicked">
<FlyoutBase.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Change profile picture"
Clicked="ChangeProfilePict_Clicked"/>
</MenuFlyout>
</FlyoutBase.ContextFlyout>
</ImageButton>
</Grid>
<!-- Connection button -->

@ -1,5 +1,6 @@
using DataPersistence;
using Model;
using System.Diagnostics;
namespace Views;
@ -50,4 +51,29 @@ public partial class ContainerFlyout : ContentView
Master.User.LogOut();
Navigation.PopModalAsync();
}
public async void ChangeProfilePict_Clicked(object sender, EventArgs e)
{
FileResult photo = await MediaPicker.Default.PickPhotoAsync();
if (photo != null)
{
// save the file into local storage
string localFilePath = Path.Combine(FileSystem.Current.AppDataDirectory, $"{Master.User.CurrentConnected.Mail}.{photo.FileName}");
using Stream sourceStream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
Master.User.CurrentConnected.ProfilePict = localFilePath;
// Save data.
Debug.Write($"[ {DateTime.Now:H:mm:ss} ] Saving...\t");
Master.Data.SaveData();
Debug.WriteLine("Done.");
Debug.WriteLine(FileSystem.Current.AppDataDirectory);
}
}
}

@ -18,8 +18,9 @@
HorizontalTextAlignment="Center"
VerticalOptions="Center"
HorizontalOptions="Center" />
<ImageButton Grid.Column="2"
Source="person_default.svg"
Source="{Binding ProfilePict}"
WidthRequest="80" HeightRequest="80"
CornerRadius="50"
BorderWidth="4" BorderColor="Black"

@ -17,6 +17,8 @@
Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center"
Text="{Binding RecipeTitle, Source={x:Reference rCase}}"/>
</Grid>
</Border>
</ContentView>

@ -1,4 +1,5 @@
using Model;
using CommunityToolkit.Maui.Storage;
namespace Views;

Loading…
Cancel
Save