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