//using Android.Media; using DataPersistence; using Model; using Model.Managers; using System.Collections.ObjectModel; using System.ComponentModel; namespace Views { public partial class Home : ContentPage { public MasterManager MasterMgr => (App.Current as App).MasterMgr; public User? user => (App.Current as App).CurrentUser; public RecipeCollection AllRecipe => (App.Current as App).AllRecipes; private readonly RecipeCollection _recipesDisplayed; public ReadOnlyObservableCollection RecipesDisplayed { get; private set; } public static readonly BindableProperty IsNotConnectedProperty = BindableProperty.Create("IsNotConnected", typeof(bool), typeof(bool)); public bool IsNotConnected { get => (bool)GetValue(IsNotConnectedProperty); set => SetValue(IsNotConnectedProperty, value); } public static readonly BindableProperty NeedReturnProperty = BindableProperty.Create("NeedReturn", typeof(bool), typeof(bool)); public bool NeedReturn { get => (bool)GetValue(NeedReturnProperty); set => SetValue(NeedReturnProperty, value); } public Home() { _recipesDisplayed = (RecipeCollection)AllRecipe.Clone(); RecipesDisplayed = new ReadOnlyObservableCollection(_recipesDisplayed); InitializeComponent(); BindingContext = this; IsNotConnected = true; NeedReturn = false; } public Home(RecipeCollection recipesDisplayed) { _recipesDisplayed = recipesDisplayed; InitializeComponent(); BindingContext = this; IsNotConnected = true; NeedReturn = true; } private void ModifyRecipesDisplayed(RecipeCollection recipes) { _recipesDisplayed.Clear(); _recipesDisplayed.Description = recipes.Description; foreach (Recipe recipe in recipes) { _recipesDisplayed.Add(recipe); } } private void SearchBar_SearchButtonPressed(object sender, EventArgs e) { string searchStr = (sender as SearchBar).Text; ModifyRecipesDisplayed(AllRecipe.ResearchByName(searchStr)); } public void OnImageClicked(object sender, EventArgs e) { (App.Current as App).CurrentRecipe = (Recipe)(sender as ImageButton).BindingContext; Navigation.PushModalAsync(new ViewRecette()); } private void Entrees_Clicked(object sender, EventArgs e) { ModifyRecipesDisplayed(new RecipeCollection("Entrées", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Starter).ToArray())); } private void Plats_Clicked(object sender, EventArgs e) { ModifyRecipesDisplayed(new RecipeCollection("Plats", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Dish).ToArray())); } private void Desserts_Clicked(object sender, EventArgs e) { ModifyRecipesDisplayed(new RecipeCollection("Desserts", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Dessert).ToArray())); } private void AllRecipes_Clicked(object sender, EventArgs e) { ModifyRecipesDisplayed(AllRecipe); } } }