parent
9eb96aba78
commit
8a60b12e67
@ -1,112 +1,120 @@
|
||||
using Plugin.Maui.Audio;
|
||||
using MusiLib.Model;
|
||||
|
||||
namespace MusiLib.Views;
|
||||
|
||||
public partial class Accueil : ContentPage, IAllowClick
|
||||
namespace MusiLib.Views
|
||||
{
|
||||
|
||||
public Manager MyManager => (App.Current as App).MyManager;
|
||||
|
||||
private List<Partition> partitionsInitiales;
|
||||
|
||||
public Accueil()
|
||||
{
|
||||
InitializeComponent();
|
||||
chargerPartitions();
|
||||
BindingContext = MyManager;
|
||||
}
|
||||
|
||||
private void GoToFavorisButton(object sender, EventArgs e)
|
||||
public partial class Accueil : ContentPage, IAllowClick
|
||||
{
|
||||
if (!IAllowClick.AllowTap) return;
|
||||
else IAllowClick.AllowTap = false;
|
||||
public Manager MyManager => (App.Current as App).MyManager;
|
||||
|
||||
Navigation.PushAsync(new Favoris());
|
||||
private List<Partition> partitionsInitiales;
|
||||
private List<Partition> partitionsFiltrees;
|
||||
|
||||
IAllowClick.ResumeTap();
|
||||
}
|
||||
public Accueil()
|
||||
{
|
||||
InitializeComponent();
|
||||
partitionsInitiales = MyManager.partitions.ToList();
|
||||
partitionsFiltrees = new List<Partition>(partitionsInitiales);
|
||||
BindingContext = MyManager;
|
||||
chargerPartitions();
|
||||
}
|
||||
|
||||
private void GoToPartitionButton(object sender, EventArgs e)
|
||||
{
|
||||
if (!IAllowClick.AllowTap) return;
|
||||
else IAllowClick.AllowTap = false;
|
||||
private void GoToFavorisButton(object sender, EventArgs e)
|
||||
{
|
||||
if (!IAllowClick.AllowTap) return;
|
||||
else IAllowClick.AllowTap = false;
|
||||
|
||||
var button = (ImageButton)sender;
|
||||
var idAutomation = button.AutomationId;
|
||||
Navigation.PushAsync(new Favoris());
|
||||
|
||||
if (int.TryParse(idAutomation, out int id))
|
||||
{
|
||||
Navigation.PushAsync(new PartitionView(id));
|
||||
IAllowClick.ResumeTap();
|
||||
}
|
||||
|
||||
private void GoToPartitionButton(object sender, EventArgs e)
|
||||
{
|
||||
if (!IAllowClick.AllowTap) return;
|
||||
else IAllowClick.AllowTap = false;
|
||||
|
||||
IAllowClick.ResumeTap();
|
||||
}
|
||||
|
||||
var button = (ImageButton)sender;
|
||||
var idAutomation = button.AutomationId;
|
||||
|
||||
private void chargerPartitions()
|
||||
{
|
||||
partitionsInitiales = MyManager.partitions.ToList();
|
||||
if (int.TryParse(idAutomation, out int id))
|
||||
{
|
||||
Navigation.PushAsync(new PartitionView(id));
|
||||
}
|
||||
|
||||
int imagesParLigne = 3;
|
||||
int indice = 0;
|
||||
IAllowClick.ResumeTap();
|
||||
}
|
||||
|
||||
for (int i = 0; i < MyManager.partitions.Count; i++)
|
||||
private void chargerPartitions()
|
||||
{
|
||||
Model.Partition partitions = MyManager.partitions[i];
|
||||
var imageButtonsToRemove = grille.Children.OfType<ImageButton>().Where(btn => !string.IsNullOrEmpty(btn.AutomationId)).ToList();
|
||||
foreach (var button in imageButtonsToRemove)
|
||||
{
|
||||
grille.Children.Remove(button);
|
||||
}
|
||||
|
||||
ImageButton imageButton = new ImageButton
|
||||
|
||||
int imagesParLigne = 3;
|
||||
int indice = 0;
|
||||
|
||||
foreach (Partition partition in partitionsFiltrees)
|
||||
{
|
||||
Source = partitions.Image[0],
|
||||
WidthRequest = 175,
|
||||
HeightRequest = 175,
|
||||
AutomationId = indice.ToString(),
|
||||
};
|
||||
int indicePartition = MyManager.partitions.IndexOf(partition);
|
||||
|
||||
imageButton.Clicked += GoToPartitionButton;
|
||||
ImageButton imageButton = new ImageButton
|
||||
{
|
||||
Source = partition.Image[0],
|
||||
WidthRequest = 175,
|
||||
HeightRequest = 175,
|
||||
AutomationId = indicePartition.ToString(),
|
||||
};
|
||||
|
||||
int ligne = 1 + (indice / imagesParLigne);
|
||||
int colonne = indice % imagesParLigne;
|
||||
imageButton.Clicked += GoToPartitionButton;
|
||||
|
||||
imageButton.Margin = GetImageButtonMargin(colonne);
|
||||
int ligne = 1 + (indice / imagesParLigne);
|
||||
int colonne = indice % imagesParLigne;
|
||||
|
||||
Grid.SetRow(imageButton, ligne);
|
||||
Grid.SetColumn(imageButton, colonne);
|
||||
grille.Children.Add(imageButton);
|
||||
imageButton.Margin = GetImageButtonMargin(colonne);
|
||||
|
||||
indice++;
|
||||
}
|
||||
}
|
||||
Grid.SetRow(imageButton, ligne);
|
||||
Grid.SetColumn(imageButton, colonne);
|
||||
grille.Children.Add(imageButton);
|
||||
|
||||
private Thickness GetImageButtonMargin(int colonne)
|
||||
{
|
||||
if (colonne == 0)
|
||||
{
|
||||
return new Thickness(30, 0, 0, 0);
|
||||
}
|
||||
else if (colonne == 1)
|
||||
{
|
||||
return new Thickness(90, 0, 0, 0);
|
||||
indice++;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
private Thickness GetImageButtonMargin(int colonne)
|
||||
{
|
||||
return new Thickness(150, 0, 0, 0);
|
||||
if (colonne == 0)
|
||||
{
|
||||
return new Thickness(30, 0, 0, 0);
|
||||
}
|
||||
else if (colonne == 1)
|
||||
{
|
||||
return new Thickness(90, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Thickness(150, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
string texteRecherche = e.NewTextValue;
|
||||
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
string texteRecherche = e.NewTextValue;
|
||||
|
||||
MyManager.partitions.Clear();
|
||||
partitionsFiltrees.Clear();
|
||||
|
||||
foreach (Model.Partition partition in partitionsInitiales)
|
||||
{
|
||||
if (partition.Nom.ToLower().Contains(texteRecherche.ToLower()))
|
||||
foreach (Partition partition in partitionsInitiales)
|
||||
{
|
||||
MyManager.partitions.Add(partition);
|
||||
if (partition.Nom.ToLower().Contains(texteRecherche.ToLower()))
|
||||
{
|
||||
partitionsFiltrees.Add(partition);
|
||||
}
|
||||
}
|
||||
|
||||
chargerPartitions();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue