diff --git a/LivreLand/MauiProgram.cs b/LivreLand/MauiProgram.cs index 5844d00..102e094 100644 --- a/LivreLand/MauiProgram.cs +++ b/LivreLand/MauiProgram.cs @@ -27,7 +27,7 @@ public static class MauiProgram builder.Services .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -58,7 +58,8 @@ public static class MauiProgram .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton(); #if DEBUG builder.Logging.AddDebug(); diff --git a/LivreLand/Resources/Images/star.png b/LivreLand/Resources/Images/star.png new file mode 100644 index 0000000..6f38ded Binary files /dev/null and b/LivreLand/Resources/Images/star.png differ diff --git a/LivreLand/Resources/Images/star_fill.png b/LivreLand/Resources/Images/star_fill.png new file mode 100644 index 0000000..17a3a8a Binary files /dev/null and b/LivreLand/Resources/Images/star_fill.png differ diff --git a/LivreLand/Resources/Images/star_fill.svg b/LivreLand/Resources/Images/star_fill.svg deleted file mode 100644 index ac2baa3..0000000 --- a/LivreLand/Resources/Images/star_fill.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/LivreLand/View/ContentViews/StarNotationView.xaml b/LivreLand/View/ContentViews/StarNotationView.xaml index 51b7752..668c732 100644 --- a/LivreLand/View/ContentViews/StarNotationView.xaml +++ b/LivreLand/View/ContentViews/StarNotationView.xaml @@ -1,24 +1,67 @@ - - + + + + + + + + + + + + WidthRequest="20" + Grid.Column="0" + IsVisible="{Binding StarNotationVM.Star1IsVisible}"/> + + + WidthRequest="20" + Grid.Column="1" + IsVisible="{Binding StarNotationVM.Star2IsVisible}"/> + + + WidthRequest="20" + Grid.Column="2" + IsVisible="{Binding StarNotationVM.Star3IsVisible}"/> + + + WidthRequest="20" + Grid.Column="3" + IsVisible="{Binding StarNotationVM.Star4IsVisible}"/> + - + WidthRequest="20" + Grid.Column="4" + IsVisible="{Binding StarNotationVM.Star5IsVisible}"/> + + diff --git a/LivreLand/View/ContentViews/StarNotationView.xaml.cs b/LivreLand/View/ContentViews/StarNotationView.xaml.cs index 9f1ff37..a7912e5 100644 --- a/LivreLand/View/ContentViews/StarNotationView.xaml.cs +++ b/LivreLand/View/ContentViews/StarNotationView.xaml.cs @@ -1,9 +1,30 @@ +using LivreLand.ViewModel; + namespace LivreLand.View.ContentViews; public partial class StarNotationView : ContentView { - public StarNotationView() + #region Properties + + public static readonly BindableProperty StarNotationProperty = BindableProperty.Create(nameof(StarNotation), typeof(StarNotationVM), typeof(StarNotationView), Application.Current.Handler.MauiContext.Services.GetService()); + + public StarNotationVM StarNotation + { + get { return (StarNotationVM)GetValue(StarNotationProperty); } + set { SetValue(StarNotationProperty, value); } + } + + public StarNotationVM StarNotationVM { get; private set; } + + #endregion + + #region Constructor + + public StarNotationView() { + StarNotationVM = StarNotation; InitializeComponent(); } + + #endregion } \ No newline at end of file diff --git a/LivreLand/View/DetailsLivreView.xaml b/LivreLand/View/DetailsLivreView.xaml index 2e705eb..af1ec09 100644 --- a/LivreLand/View/DetailsLivreView.xaml +++ b/LivreLand/View/DetailsLivreView.xaml @@ -8,6 +8,7 @@ xmlns:model="clr-namespace:Model;assembly=Model" x:Class="LivreLand.View.DetailsLivreView" Title="DetailsLivreView"> + diff --git a/LivreLand/ViewModel/StarNotationVM.cs b/LivreLand/ViewModel/StarNotationVM.cs new file mode 100644 index 0000000..63bbbf1 --- /dev/null +++ b/LivreLand/ViewModel/StarNotationVM.cs @@ -0,0 +1,61 @@ +using Model; +using PersonalMVVMToolkit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using ViewModels; + +namespace LivreLand.ViewModel +{ + public class StarNotationVM : BaseViewModel + { + #region Properties + + public bool Star1IsVisible { get; private set; } + + public bool Star2IsVisible { get; private set; } + + public bool Star3IsVisible { get; private set; } + + public bool Star4IsVisible { get; private set; } + + public bool Star5IsVisible { get; private set; } + + public ManagerVM Manager { get; private set; } + + public ICommand StarRatingConverterCommand { get; private set; } + + #endregion + + #region Constructor + + public StarNotationVM(ManagerVM managerVM) + { + Manager = managerVM; + StarRatingConverterCommand = new RelayCommand(() => StarRatingConverter()); + } + + #endregion + + #region Methods + + private void StarRatingConverter() + { + var bookRating = Manager.SelectedBook.UserRating; + + for (int i = 1; i <= 5; i++) + { + if (bookRating >= i) + { + var starProperty = typeof(StarNotationVM).GetProperty($"Star{i}IsVisible"); + starProperty?.SetValue(this, true); + } + } + } + + #endregion + } +} diff --git a/LivreLand/ViewModel/TousVM.cs b/LivreLand/ViewModel/TousVM.cs index f1ba534..8ef21dc 100644 --- a/LivreLand/ViewModel/TousVM.cs +++ b/LivreLand/ViewModel/TousVM.cs @@ -41,6 +41,18 @@ namespace LivreLand.ViewModel { var result = new DetailsLivreVM(Manager, Navigator, bookVM); App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView(result)); + + var bookRating = bookVM.UserRating; + StarNotationVM starNotationVM = new StarNotationVM(this.Manager); + + for (int i = 1; i <= 5; i++) + { + if (bookRating >= i) + { + var starProperty = typeof(StarNotationVM).GetProperty($"Star{i}IsVisible"); + starProperty?.SetValue(starNotationVM, true); + } + } } }