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;
|
||||
|
||||
namespace ShoopNCook.Pages;
|
||||
|
||||
public partial class FavoritesPage : ContentPage
|
||||
{
|
||||
public FavoritesPage(Account account, IApp app)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
namespace ShoopNCook.Pages;
|
||||
|
||||
using Endpoint;
|
||||
using LocalEndpoint;
|
||||
using Models;
|
||||
using ShoopNCook.Views;
|
||||
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;
|
||||
using Models;
|
||||
using ShoopNCook.Views;
|
||||
using Endpoint;
|
||||
using LocalEndpoint;
|
||||
|
||||
public partial class HomePage : ContentPage
|
||||
{
|
||||
public HomePage(Account account, IApp app)
|
||||
public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint)
|
||||
{
|
||||
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);
|
||||
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 ShoopNCook.Controllers;
|
||||
|
||||
namespace ShoopNCook.Pages;
|
||||
|
||||
public partial class MorePage : ContentPage
|
||||
{
|
||||
|
||||
private readonly MorePageController controller;
|
||||
|
||||
public MorePage(Account account, MorePageController controller)
|
||||
{
|
||||
InitializeComponent();
|
||||
ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
|
||||
ProfileName.Text = account.User.Name;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
private async void OnMyRecipesButtonTapped(object sender, EventArgs e)
|
||||
{
|
||||
await Shell.Current.Navigation.PushAsync(new MyRecipesPage());
|
||||
}
|
||||
|
||||
private async void OnEditProfileButtonTapped(object sender, EventArgs e)
|
||||
{
|
||||
await Shell.Current.Navigation.PushAsync(new ProfilePage());
|
||||
}
|
||||
|
||||
private void OnLogoutButtonTapped(object sender, EventArgs e)
|
||||
{
|
||||
controller.Logout();
|
||||
}
|
||||
private async void OnShareButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
await Share.RequestAsync(new ShareTextRequest
|
||||
{
|
||||
Text = "Voici le texte à partager (à changer)",
|
||||
Title = "Partagez ce texte : (à modifier)"
|
||||
});
|
||||
}
|
||||
namespace ShoopNCook.Pages;
|
||||
|
||||
public partial class MorePage : ContentPage
|
||||
{
|
||||
|
||||
private readonly MorePageController controller;
|
||||
|
||||
public MorePage(Account account, MorePageController controller)
|
||||
{
|
||||
InitializeComponent();
|
||||
ProfileImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
|
||||
ProfileName.Text = account.User.Name;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
private void OnMyRecipesButtonTapped(object sender, EventArgs e)
|
||||
{
|
||||
controller.GoToMyRecipesPage();
|
||||
}
|
||||
|
||||
private void OnEditProfileButtonTapped(object sender, EventArgs e)
|
||||
{
|
||||
controller.GoToProfilePage();
|
||||
}
|
||||
|
||||
private void OnLogoutButtonTapped(object sender, EventArgs e)
|
||||
{
|
||||
controller.Logout();
|
||||
}
|
||||
private async void OnShareButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
await Share.RequestAsync(new ShareTextRequest
|
||||
{
|
||||
Text = "Voici le texte à partager (à changer)",
|
||||
Title = "Partagez ce texte : (à modifier)"
|
||||
});
|
||||
}
|
||||
}
|
@ -1,11 +1,44 @@
|
||||
using Endpoint;
|
||||
using LocalEndpoint;
|
||||
using Models;
|
||||
using ShoopNCook.Views;
|
||||
|
||||
namespace ShoopNCook.Pages;
|
||||
|
||||
public partial class MyListPage : ContentPage
|
||||
{
|
||||
public MyListPage(Account account, IApp app)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
namespace ShoopNCook.Pages;
|
||||
|
||||
public partial class MyListPage : ContentPage
|
||||
{
|
||||
|
||||
private readonly IAccountRecipesPreferences preferences;
|
||||
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;
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
private async void OnBackButtonClicked(object sender, EventArgs e)
|
||||
this.notifier = notifier;
|
||||
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