Merge pull request 'Integrate Endpoint/API/models for main functionallities' (#50) from models/integration into master
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: ShopNCook/ShopNCook#50pull/51/head
commit
e2df22c858
@ -1,12 +1,46 @@
|
|||||||
using Models;
|
using Models;
|
||||||
|
|
||||||
namespace ShoopNCook.Pages;
|
namespace ShoopNCook.Pages;
|
||||||
|
|
||||||
public partial class FavoritesPage : ContentPage
|
using Endpoint;
|
||||||
{
|
using LocalEndpoint;
|
||||||
public FavoritesPage(Account account, IApp app)
|
using Models;
|
||||||
{
|
using ShoopNCook.Views;
|
||||||
InitializeComponent();
|
using System.Security.Principal;
|
||||||
}
|
|
||||||
|
public partial class FavoritesPage : ContentPage
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly Account account;
|
||||||
|
private readonly IUserNotifier notifier;
|
||||||
|
private IRecipesService service;
|
||||||
|
|
||||||
|
public FavoritesPage(Account account, IUserNotifier notifier, IRecipesService service)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
this.account = account;
|
||||||
|
this.notifier = notifier;
|
||||||
|
this.service = service;
|
||||||
|
|
||||||
|
UpdateFavorites();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateFavorites()
|
||||||
|
{
|
||||||
|
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
|
||||||
|
RecipeViewLayout.Children.Clear();
|
||||||
|
preferences.GetFavorites().ForEach(info =>
|
||||||
|
{
|
||||||
|
RecipeViewLayout.Children.Add(new RecipeView(info, () =>
|
||||||
|
{
|
||||||
|
Recipe recipe = service.GetRecipe(info);
|
||||||
|
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1));
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateFavorites();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,17 +1,42 @@
|
|||||||
using Models;
|
|
||||||
|
|
||||||
namespace ShoopNCook.Pages;
|
namespace ShoopNCook.Pages;
|
||||||
|
using Models;
|
||||||
|
using ShoopNCook.Views;
|
||||||
|
using Endpoint;
|
||||||
|
using LocalEndpoint;
|
||||||
|
|
||||||
public partial class HomePage : ContentPage
|
public partial class HomePage : ContentPage
|
||||||
{
|
{
|
||||||
public HomePage(Account account, IApp app)
|
public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
IRecipesService service = endpoint.RecipesService;
|
||||||
|
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
|
||||||
|
|
||||||
|
|
||||||
|
//TODO this code can be factorised
|
||||||
|
void PushRecipe(Layout layout, RecipeInfo info)
|
||||||
|
{
|
||||||
|
layout.Children.Add(new RecipeView(info, () =>
|
||||||
|
{
|
||||||
|
Recipe recipe = service.GetRecipe(info);
|
||||||
|
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe));
|
||||||
|
preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe));
|
||||||
|
|
||||||
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
|
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
|
||||||
ProfilePictureName.Text = account.User.Name;
|
ProfilePictureName.Text = account.User.Name;
|
||||||
}
|
}
|
||||||
private async void OnSyncButtonClicked(object sender, EventArgs e)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void OnSyncButtonClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Shell.Current.Navigation.PushAsync(new SearchPage());
|
Shell.Current.Navigation.PushAsync(new SearchPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,41 +1,41 @@
|
|||||||
using Models;
|
using Models;
|
||||||
using ShoopNCook.Controllers;
|
using ShoopNCook.Controllers;
|
||||||
|
|
||||||
namespace ShoopNCook.Pages;
|
namespace ShoopNCook.Pages;
|
||||||
|
|
||||||
public partial class MorePage : ContentPage
|
public partial class MorePage : ContentPage
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly MorePageController controller;
|
private readonly MorePageController controller;
|
||||||
|
|
||||||
public MorePage(Account account, MorePageController controller)
|
public MorePage(Account account, MorePageController controller)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
|
ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
|
||||||
ProfileName.Text = account.User.Name;
|
ProfileName.Text = account.User.Name;
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnMyRecipesButtonTapped(object sender, EventArgs e)
|
private void OnMyRecipesButtonTapped(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Shell.Current.Navigation.PushAsync(new MyRecipesPage());
|
controller.GoToMyRecipesPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnEditProfileButtonTapped(object sender, EventArgs e)
|
private void OnEditProfileButtonTapped(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Shell.Current.Navigation.PushAsync(new ProfilePage());
|
controller.GoToProfilePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLogoutButtonTapped(object sender, EventArgs e)
|
private void OnLogoutButtonTapped(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
controller.Logout();
|
controller.Logout();
|
||||||
}
|
}
|
||||||
private async void OnShareButtonClicked(object sender, EventArgs e)
|
private async void OnShareButtonClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Share.RequestAsync(new ShareTextRequest
|
await Share.RequestAsync(new ShareTextRequest
|
||||||
{
|
{
|
||||||
Text = "Voici le texte à partager (à changer)",
|
Text = "Voici le texte à partager (à changer)",
|
||||||
Title = "Partagez ce texte : (à modifier)"
|
Title = "Partagez ce texte : (à modifier)"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +1,44 @@
|
|||||||
|
using Endpoint;
|
||||||
|
using LocalEndpoint;
|
||||||
using Models;
|
using Models;
|
||||||
|
using ShoopNCook.Views;
|
||||||
|
|
||||||
namespace ShoopNCook.Pages;
|
namespace ShoopNCook.Pages;
|
||||||
|
|
||||||
public partial class MyListPage : ContentPage
|
public partial class MyListPage : ContentPage
|
||||||
{
|
{
|
||||||
public MyListPage(Account account, IApp app)
|
|
||||||
{
|
private readonly IAccountRecipesPreferences preferences;
|
||||||
InitializeComponent();
|
private readonly IUserNotifier notifier;
|
||||||
}
|
private readonly IRecipesService service;
|
||||||
|
|
||||||
|
public MyListPage(Account account, IUserNotifier notifier, IRecipesService service)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
this.preferences = service.GetPreferencesOf(account);
|
||||||
|
this.notifier = notifier;
|
||||||
|
this.service = service;
|
||||||
|
|
||||||
|
UpdateMyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateMyList()
|
||||||
|
{
|
||||||
|
RecipesLayout.Children.Clear();
|
||||||
|
preferences.GetWeeklyList().ForEach(tuple =>
|
||||||
|
{
|
||||||
|
RecipeInfo info = tuple.Item1;
|
||||||
|
RecipesLayout.Children.Add(new StoredRecipeView(info, tuple.Item2, amount =>
|
||||||
|
{
|
||||||
|
Recipe recipe = service.GetRecipe(info);
|
||||||
|
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, amount));
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateMyList();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,19 +1,85 @@
|
|||||||
|
using Endpoint;
|
||||||
|
using LocalEndpoint;
|
||||||
|
using Models;
|
||||||
|
using ShoopNCook.Views;
|
||||||
|
|
||||||
namespace ShoopNCook.Pages;
|
namespace ShoopNCook.Pages;
|
||||||
|
|
||||||
public partial class MyRecipesPage : ContentPage
|
public partial class MyRecipesPage : ContentPage
|
||||||
{
|
{
|
||||||
public MyRecipesPage()
|
|
||||||
{
|
private IUserNotifier notifier;
|
||||||
|
private IRecipesService service;
|
||||||
|
private Account account;
|
||||||
|
|
||||||
|
public MyRecipesPage(
|
||||||
|
Account account,
|
||||||
|
IRecipesService service,
|
||||||
|
IUserNotifier notifier)
|
||||||
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
}
|
this.notifier = notifier;
|
||||||
private async void OnBackButtonClicked(object sender, EventArgs e)
|
this.service = service;
|
||||||
|
this.account = account;
|
||||||
|
|
||||||
|
service
|
||||||
|
.GetRecipesOf(account)
|
||||||
|
.GetAccountRecipes()
|
||||||
|
.ForEach(AddRecipeView);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddRecipeView(RecipeInfo info)
|
||||||
{
|
{
|
||||||
await Navigation.PopAsync();
|
RecipesLayout.Children.Add(new OwnedRecipeView(info, () =>
|
||||||
|
{
|
||||||
|
Recipe recipe = service.GetRecipe(info);
|
||||||
|
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
|
||||||
|
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1));
|
||||||
|
},
|
||||||
|
() => RemoveRecipe(info)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
private async void AddRecipeButtonClicked(object sender, EventArgs e)
|
|
||||||
|
private void RemoveRecipe(RecipeInfo info)
|
||||||
{
|
{
|
||||||
await Shell.Current.Navigation.PushAsync(new CreateRecipePage());
|
IAccountOwnedRecipes recipes = service.GetRecipesOf(account);
|
||||||
|
|
||||||
|
if (!recipes.RemoveRecipe(info))
|
||||||
|
{
|
||||||
|
notifier.Error("Could not remove recipe");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach (OwnedRecipeView view in RecipesLayout.Children)
|
||||||
|
{
|
||||||
|
if (view.IsViewing(info))
|
||||||
|
{
|
||||||
|
RecipesLayout.Remove(view);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notifier.Success("Recipe successfully removed");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBackButtonClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
private void OnAddRecipeButtonClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
IAccountOwnedRecipes recipes = service.GetRecipesOf(account);
|
||||||
|
|
||||||
|
var page = new CreateRecipePage(account.User, notifier, recipe =>
|
||||||
|
{
|
||||||
|
if (!recipes.UploadRecipe(recipe))
|
||||||
|
{
|
||||||
|
notifier.Error("Could not upload recipe.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
notifier.Success("Recipe Successfuly uploaded !");
|
||||||
|
AddRecipeView(recipe.Info);
|
||||||
|
Shell.Current.Navigation.PopAsync(); //go back to current recipe page.
|
||||||
|
});
|
||||||
|
Shell.Current.Navigation.PushAsync(page); //display RecipePage editor
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue