You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
using BookApp.Model;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace BookApp.Pages;
|
|
|
|
public partial class DetailBook : ContentPage
|
|
{
|
|
private int maxStars = 5;
|
|
private int currentRating = 0;
|
|
|
|
public Book BookDetail { get; set; }
|
|
|
|
public DetailBook(Book ItemBook)
|
|
{
|
|
InitializeComponent();
|
|
|
|
for (int i = 1; i <= maxStars; i++)
|
|
{
|
|
var star = new Image
|
|
{
|
|
Source = "empty_star.svg", // image d'une étoile vide
|
|
WidthRequest = 25,
|
|
HeightRequest = 25
|
|
};
|
|
|
|
int currentStar = i;
|
|
|
|
star.GestureRecognizers.Add(
|
|
new TapGestureRecognizer { Command = new Command(() => StarTapped(currentStar)), }
|
|
);
|
|
StarLayout.Children.Add(star);
|
|
}
|
|
|
|
UpdateStars();
|
|
BookDetail = ItemBook;
|
|
BindingContext = this;
|
|
}
|
|
|
|
private void StarTapped(int rating)
|
|
{
|
|
if (rating > maxStars)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine("Erreur : rating trop élevé!");
|
|
return;
|
|
}
|
|
|
|
currentRating = rating;
|
|
UpdateStars();
|
|
RatingLabel.Text = $"Note: {currentRating}/{maxStars}";
|
|
}
|
|
|
|
private void UpdateStars()
|
|
{
|
|
for (int i = 0; i < maxStars; i++)
|
|
{
|
|
var star = (Image)StarLayout.Children[i];
|
|
if (i < currentRating)
|
|
star.Source = "filled_star.svg"; // image d'une étoile remplie
|
|
else
|
|
star.Source = "empty_star.svg";
|
|
}
|
|
}
|
|
|
|
async void BackButton(object sender, EventArgs args)
|
|
{
|
|
await Shell.Current.Navigation.PopAsync();
|
|
}
|
|
}
|