binding des notes sur ficheanime
continuous-integration/drone/push Build is failing Details

pull/29/head
Vianney JOURDY 2 years ago
parent 0c9010aa19
commit 4108d6cfad

@ -4,12 +4,20 @@ using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Xml.Linq;
using System.Runtime.CompilerServices;
namespace MangaMap.Model
{
[DataContract]
public class Oeuvre
public class Oeuvre : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
[DataMember]
public string Nom { get; private set; }
[DataMember]
@ -18,8 +26,20 @@ namespace MangaMap.Model
public string Type { get; private set; }
[DataMember]
public string Description { get; private set; }
[DataMember]
public int Note { get; private set; }
public int Note {
get => note;
set
{
if (note == value)
return;
note = value;
OnPropertyChanged();
}
}
private int note;
[DataMember]
public int NbEpisodes { get; private set; }
[DataMember]

@ -34,7 +34,7 @@
<Grid Margin="20,0,20,20" ColumnDefinitions="*,*,300,300,40">
<ImageButton Grid.Column="0" Source="{Binding Affiche}" Style="{StaticResource ImageAnime}" HorizontalOptions="Start" Clicked="AnimeImageClickedList"/>
<Label Grid.Column="1" Text="{Binding Nom}" TextColor="White" FontSize="Medium" VerticalOptions="Center" Margin="15"/>
<Label Grid.Column="2" Text="4/5" TextColor="White" FontSize="Medium" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Column="2" Text="{Binding Note}" TextColor="White" FontSize="Medium" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Column="3" Text="{Binding NbEpisodes}" TextColor="White" FontSize="Medium" VerticalOptions="Center" HorizontalOptions="End"/>
</Grid>
</DataTemplate>

@ -1,20 +1,18 @@
namespace MangaMap.Views;
using Model;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Input;
using System.Xml.Linq;
public partial class ficheAnime : ContentPage, INotifyPropertyChanged
{
public Manager my_manager => (App.Current as App).MyManager;
public Oeuvre AnimeModel { get; set; }
public ICommand StarCommand => new Command<string>(count => SetNote(uint.Parse(count)));
public ficheAnime()
{
InitializeComponent();
@ -30,7 +28,8 @@ public partial class ficheAnime : ContentPage, INotifyPropertyChanged
InitializeComponent();
BindingContext = this;
SetNote();
}
public async void AjouterListe(object sender, EventArgs e)
@ -81,22 +80,59 @@ public partial class ficheAnime : ContentPage, INotifyPropertyChanged
}
private void SetNote(float note)
private void SetNote()
{
note = (int)note;
var starImages = star.Children.OfType<Image>().Reverse().ToList();
foreach (var img in starImages)
stars.Children.Clear();
for (int i = 0; i < 5; i++)
{
if (note > 0)
if (i < AnimeModel.Note)
{
img.Opacity = 1;
note--;
ImageButton imageButton = new ImageButton
{
Source = "star_full.png",
WidthRequest = 50,
HeightRequest = 50,
AutomationId = i.ToString(),
Margin = 10,
};
imageButton.Clicked += StarClicked;
Grid.SetRow(imageButton, 0);
Grid.SetColumn(imageButton, i);
stars.Children.Add(imageButton);
}
else
{
img.Opacity = 0;
ImageButton imageButton = new ImageButton
{
Source = "star_empty.png",
WidthRequest = 50,
HeightRequest = 50,
AutomationId = i.ToString(),
Margin = 10,
};
imageButton.Clicked += StarClicked;
Grid.SetRow(imageButton, 0);
Grid.SetColumn(imageButton, i);
stars.Children.Add(imageButton);
}
}
}
private async void StarClicked(object sender, EventArgs e)
{
var button = (ImageButton)sender;
var idAutomation = button.AutomationId;
if (int.TryParse(idAutomation, out int id))
{
AnimeModel.Note = id+1;
my_manager.sauvegarder();
SetNote();
}
}
}

@ -26,13 +26,8 @@
<Label Text="{Binding AnimeModel.Genre}" BackgroundColor="{StaticResource Primary}" TextColor="White" Margin="0,0,0,30"/>
<HorizontalStackLayout x:Name="star">
<Image Source="star_full.png" WidthRequest="50" HeightRequest="50" Margin="10"/>
<Image Source="star_full.png" WidthRequest="50" HeightRequest="50" Margin="10"/>
<Image Source="star_full.png" WidthRequest="50" HeightRequest="50" Margin="10"/>
<Image Source="star_full.png" WidthRequest="50" HeightRequest="50" Margin="10"/>
<Image Source="star_empty.png" WidthRequest="50" HeightRequest="50" Margin="10"/>
</HorizontalStackLayout>
<Grid x:Name="stars" ColumnDefinitions="80,80,80,80,80">
</Grid>
<Button Text="Ajouter à la liste"
TextColor="#FFFFFF"

@ -18,7 +18,6 @@
BackgroundColor="#1E1E1E"
Grid.Row="1">
<VerticalStackLayout
Spacing="70"
VerticalOptions="Center">
<SearchBar Placeholder="Recherche"
@ -47,7 +46,9 @@
<ScrollView>
<Grid x:Name="grille">
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>

Loading…
Cancel
Save