From 96c9fec521cb0b64ec0e5af6f0f195fb68e7a270 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Sat, 10 Jun 2023 10:06:23 +0200 Subject: [PATCH 1/3] change profile pict ok --- MCTG/Model/Users/User.cs | 12 +++++++-- MCTG/Views/ContentViews/ContainerFlyout.xaml | 11 ++++++-- .../ContentViews/ContainerFlyout.xaml.cs | 26 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/MCTG/Model/Users/User.cs b/MCTG/Model/Users/User.cs index ba77510..c1ec729 100644 --- a/MCTG/Model/Users/User.cs +++ b/MCTG/Model/Users/User.cs @@ -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 _priorities = new List @@ -93,8 +94,15 @@ namespace Model /// For now, we define the ProfilePict as a string which is "PhotoParDefaut" /// when the value is null. /// - [DataMember(Name = "profilepic")] - public string ProfilePict { get; private set; } = "default_picture.png"; + public string ProfilePict + { + get => _profilePict; + set + { + _profilePict = value; + OnPropertyChanged(); + } + } /// /// This is the list of priorities specific tu the user. This list is initiate diff --git a/MCTG/Views/ContentViews/ContainerFlyout.xaml b/MCTG/Views/ContentViews/ContainerFlyout.xaml index 300304b..8917a1d 100644 --- a/MCTG/Views/ContentViews/ContainerFlyout.xaml +++ b/MCTG/Views/ContentViews/ContainerFlyout.xaml @@ -15,14 +15,21 @@ - + Clicked="ProfileButton_Clicked"> + + + + + + diff --git a/MCTG/Views/ContentViews/ContainerFlyout.xaml.cs b/MCTG/Views/ContentViews/ContainerFlyout.xaml.cs index 3cdc8ca..7ddb29b 100644 --- a/MCTG/Views/ContentViews/ContainerFlyout.xaml.cs +++ b/MCTG/Views/ContentViews/ContainerFlyout.xaml.cs @@ -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); + } + } } From 09abdc41fb38cc95ee0e963489a0fc2d99b5d35e Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Sat, 10 Jun 2023 10:44:09 +0200 Subject: [PATCH 2/3] export functionality ok --- MCTG/Views/ContentPages/Home.xaml | 16 +++++++++++++--- MCTG/Views/ContentPages/Home.xaml.cs | 18 ++++++++++++++++++ MCTG/Views/ContentPages/MyPosts.xaml | 12 ++++++++++-- MCTG/Views/ContentPages/MyPosts.xaml.cs | 17 +++++++++++++++++ MCTG/Views/ContentViews/RecipeCase.xaml | 2 ++ MCTG/Views/ContentViews/RecipeCase.xaml.cs | 1 + 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/MCTG/Views/ContentPages/Home.xaml b/MCTG/Views/ContentPages/Home.xaml index 1c3a23c..afe84f7 100644 --- a/MCTG/Views/ContentPages/Home.xaml +++ b/MCTG/Views/ContentPages/Home.xaml @@ -66,7 +66,7 @@ FontSize="24" Padding="15"/> - - + + RecipeTitle="{Binding Title}"> + + + + + + + + + diff --git a/MCTG/Views/ContentPages/Home.xaml.cs b/MCTG/Views/ContentPages/Home.xaml.cs index 506989b..4928d94 100644 --- a/MCTG/Views/ContentPages/Home.xaml.cs +++ b/MCTG/Views/ContentPages/Home.xaml.cs @@ -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"); + } + } } } diff --git a/MCTG/Views/ContentPages/MyPosts.xaml b/MCTG/Views/ContentPages/MyPosts.xaml index fc7bc07..cb2464e 100644 --- a/MCTG/Views/ContentPages/MyPosts.xaml +++ b/MCTG/Views/ContentPages/MyPosts.xaml @@ -50,11 +50,19 @@ BindableLayout.ItemsSource="{Binding RecipesDisplayed}"> - + + RecipeTitle="{Binding Title}"> + + + + + + + diff --git a/MCTG/Views/ContentPages/MyPosts.xaml.cs b/MCTG/Views/ContentPages/MyPosts.xaml.cs index 2feebf1..be3887d 100644 --- a/MCTG/Views/ContentPages/MyPosts.xaml.cs +++ b/MCTG/Views/ContentPages/MyPosts.xaml.cs @@ -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"); + } + } } diff --git a/MCTG/Views/ContentViews/RecipeCase.xaml b/MCTG/Views/ContentViews/RecipeCase.xaml index 49ae6e3..b2f20a1 100644 --- a/MCTG/Views/ContentViews/RecipeCase.xaml +++ b/MCTG/Views/ContentViews/RecipeCase.xaml @@ -17,6 +17,8 @@ Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center" Text="{Binding RecipeTitle, Source={x:Reference rCase}}"/> + + diff --git a/MCTG/Views/ContentViews/RecipeCase.xaml.cs b/MCTG/Views/ContentViews/RecipeCase.xaml.cs index e707ce0..d8fc744 100644 --- a/MCTG/Views/ContentViews/RecipeCase.xaml.cs +++ b/MCTG/Views/ContentViews/RecipeCase.xaml.cs @@ -1,4 +1,5 @@ using Model; +using CommunityToolkit.Maui.Storage; namespace Views; From e8e29015b0ec9c2c37a3705072ac9ea00f0d3848 Mon Sep 17 00:00:00 2001 From: Alexandre Agostinho Date: Sat, 10 Jun 2023 11:04:52 +0200 Subject: [PATCH 3/3] import fonctionnality ok --- MCTG/Views/ContentPages/AddRecipe.xaml | 3 ++- MCTG/Views/ContentPages/AddRecipe.xaml.cs | 29 +++++++++++++++++++++++ MCTG/Views/ContentViews/MiniHeader.xaml | 3 ++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/MCTG/Views/ContentPages/AddRecipe.xaml b/MCTG/Views/ContentPages/AddRecipe.xaml index 1cc23a1..1343be7 100644 --- a/MCTG/Views/ContentPages/AddRecipe.xaml +++ b/MCTG/Views/ContentPages/AddRecipe.xaml @@ -11,7 +11,7 @@ TitleMini="Ajouter une recette" NeedReturn="True" HeightRequest="100"/> -