change profile pict ok

pull/67/head
Alexandre AGOSTINHO 2 years ago
parent 3be5ed1972
commit 96c9fec521

@ -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

@ -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);
}
}
}

Loading…
Cancel
Save