ADD : FiltrageNote + ALirePlusTard Pages

commands-19-09
Lou BRODA 1 year ago
parent ad5d0b50df
commit 147193f535

@ -27,6 +27,8 @@ public static class MauiProgram
.AddSingleton<TousView>() .AddSingleton<TousView>()
.AddSingleton<FiltrageAuteurView>() .AddSingleton<FiltrageAuteurView>()
.AddSingleton<FiltrageDateView>() .AddSingleton<FiltrageDateView>()
.AddSingleton<FiltrageNoteView>()
.AddSingleton<ALirePlusTardView>()
.AddSingleton<NavigatorVM>() .AddSingleton<NavigatorVM>()
@ -38,7 +40,9 @@ public static class MauiProgram
.AddSingleton<TousVM>() .AddSingleton<TousVM>()
.AddSingleton<FiltrageAuteurVM>() .AddSingleton<FiltrageAuteurVM>()
.AddSingleton<FiltrageDateVM>(); .AddSingleton<FiltrageDateVM>()
.AddSingleton<FiltrageNoteVM>()
.AddSingleton<ALirePlusTardVM>();
#if DEBUG #if DEBUG
builder.Logging.AddDebug(); builder.Logging.AddDebug();

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:view="clr-namespace:LivreLand.View" xmlns:view="clr-namespace:LivreLand.View"
xmlns:contentView="clr-namespace:LivreLand.View.ContentViews" xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels"
x:Class="LivreLand.View.ALirePlusTardView" x:Class="LivreLand.View.ALirePlusTardView"
Title="ALirePlusTardView"> Title="ALirePlusTardView">
@ -38,12 +39,12 @@
Style="{StaticResource HeaderCollectionViewText}" Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/> Grid.Column="1"/>
</Grid> </Grid>
<CollectionView ItemsSource="{Binding ALirePlusTardBooks}" <CollectionView ItemsSource="{Binding ALirePlusTardVM.Manager.ToBeReadBooks}"
SelectionMode="Single" SelectionMode="Single"
SelectionChanged="OnSelectionChanged" SelectionChanged="OnSelectionChanged"
Grid.Row="2"> Grid.Row="2">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate x:DataType="viewModel:BookVM">
<VerticalStackLayout Margin="10" <VerticalStackLayout Margin="10"
Spacing="20"> Spacing="20">
<VisualStateManager.VisualStateGroups x:Name="SelectionStates"> <VisualStateManager.VisualStateGroups x:Name="SelectionStates">
@ -82,7 +83,7 @@
Stroke="{StaticResource Gray}" Stroke="{StaticResource Gray}"
StrokeShape="RoundRectangle 3" StrokeShape="RoundRectangle 3"
StrokeThickness="3"> StrokeThickness="3">
<Image Source="couverture_la_horde_du_contrevent.png" <Image Source="{Binding ImageSmall}"
Aspect="AspectFill" Aspect="AspectFill"
Grid.Column="0" Grid.Column="0"
Grid.RowSpan="5"/> Grid.RowSpan="5"/>
@ -98,11 +99,11 @@
Style="{StaticResource MasterTitleBookText}" Style="{StaticResource MasterTitleBookText}"
Grid.Column="2" Grid.Column="2"
Grid.Row="0"/> Grid.Row="0"/>
<Label Text="{Binding Author}" <Label Text="Authors"
Style="{StaticResource MasterAuthorBookText}" Style="{StaticResource MasterAuthorBookText}"
Grid.Column="2" Grid.Column="2"
Grid.Row="1"/> Grid.Row="1"/>
<Label Text="{Binding State}" <Label Text="{Binding Status}"
Style="{StaticResource MasterStateBookText}" Style="{StaticResource MasterStateBookText}"
Grid.Column="2" Grid.Column="2"
Grid.Row="2"/> Grid.Row="2"/>

@ -1,22 +1,40 @@
using LivreLand.Model; using LivreLand.Model;
using LivreLand.ViewModel;
namespace LivreLand.View; namespace LivreLand.View;
public partial class ALirePlusTardView : ContentPage public partial class ALirePlusTardView : ContentPage
{ {
public List<BookModel> ALirePlusTardBooks { get; set; } = new List<BookModel>() #region Properties
{
new BookModel("La horde du contrevent","Alain Damasio","Non lu", 0), public ALirePlusTardVM ALirePlusTardVM { get; set; }
};
#endregion
#region Constructor
public ALirePlusTardView() public ALirePlusTardView(ALirePlusTardVM aLirePlusTardVM)
{ {
BindingContext = this; ALirePlusTardVM = aLirePlusTardVM;
InitializeComponent(); InitializeComponent();
BindingContext = this;
} }
#endregion
#region Properties
void OnSelectionChanged(object sender, SelectionChangedEventArgs e) void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
//App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView()); //App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView());
} }
protected override void OnAppearing()
{
base.OnAppearing();
ALirePlusTardVM.Manager.GetToBeReadBooksCommand.Execute(null);
}
#endregion
} }

@ -4,6 +4,7 @@
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:view="clr-namespace:LivreLand.View" xmlns:view="clr-namespace:LivreLand.View"
xmlns:contentView="clr-namespace:LivreLand.View.ContentViews" xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels"
x:Class="LivreLand.View.FiltrageNoteView" x:Class="LivreLand.View.FiltrageNoteView"
Title="FiltrageNoteView"> Title="FiltrageNoteView">
@ -34,50 +35,24 @@
<VerticalStackLayout Grid.Row="2"> <VerticalStackLayout Grid.Row="2">
<contentView:SeparatorEntireView/> <contentView:SeparatorEntireView/>
<!--1 étoile--> <CollectionView ItemsSource="{Binding FiltrageNoteVM.Manager.AllRatings}"
<contentView:HomeButtonView ButtonTitle="1 étoile" SelectionChangedCommand="{Binding FiltrageNoteVM.Navigator.NavigationCommand}"
ButtonIcon="book.png" SelectionChangedCommandParameter="/tous">
ButtonNumber="2" <CollectionView.ItemTemplate>
ButtonRedIconVisible="True" <DataTemplate x:DataType="viewModel:RatingsVM">
ButtonBlackIconVisible="False"/> <VerticalStackLayout>
<contentView:HomeButtonView ButtonTitle="{Binding Average}"
<contentView:SeparatorBigCutStartView/> ButtonIcon="book.png"
ButtonNumber="{Binding NbBooksWritten}"
<!--2 étoiles--> ButtonRedIconVisible="True"
<contentView:HomeButtonView ButtonTitle="2 étoiles" ButtonBlackIconVisible="False"/>
ButtonIcon="book.png"
ButtonNumber="2" <contentView:SeparatorBigCutStartView/>
ButtonRedIconVisible="True" <contentView:SeparatorBigCutStartView/>
ButtonBlackIconVisible="False"/> </VerticalStackLayout>
</DataTemplate>
<contentView:SeparatorBigCutStartView/> </CollectionView.ItemTemplate>
</CollectionView>
<!--3 étoiles-->
<contentView:HomeButtonView ButtonTitle="3 étoiles"
ButtonIcon="book.png"
ButtonNumber="2"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--4 étoiles-->
<contentView:HomeButtonView ButtonTitle="4 étoiles"
ButtonIcon="book.png"
ButtonNumber="2"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--5 étoiles-->
<contentView:HomeButtonView ButtonTitle="5 étoiles"
ButtonIcon="book.png"
ButtonNumber="2"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView> </ScrollView>
</Grid> </Grid>

@ -1,9 +1,34 @@
using LivreLand.ViewModel;
namespace LivreLand.View; namespace LivreLand.View;
public partial class FiltrageNoteView : ContentPage public partial class FiltrageNoteView : ContentPage
{ {
public FiltrageNoteView() #region Properties
{
InitializeComponent(); public FiltrageNoteVM FiltrageNoteVM { get; set; }
}
#endregion
#region Constructor
public FiltrageNoteView(FiltrageNoteVM filtrageNoteVM)
{
FiltrageNoteVM = filtrageNoteVM;
InitializeComponent();
BindingContext = this;
}
#endregion
#region Methods
protected override void OnAppearing()
{
base.OnAppearing();
FiltrageNoteVM.Manager.GetAllRatingsCommand.Execute(null);
}
#endregion
} }

@ -11,19 +11,6 @@ public partial class TousView : ContentPage
public TousVM TousVM { get; set; } public TousVM TousVM { get; set; }
public List<BookModel> DamasioBooks { get; set; } = new List<BookModel>()
{
new BookModel("La horde du contrevent","Alain Damasio","Non lu", 0),
new BookModel("La zone du dehors","Alain Damasio","Terminé", 0),
};
public List<BookModel> LiuBooks { get; set; } = new List<BookModel>()
{
new BookModel("L'équateur d'Einstein","Cixin Liu","Terminé", 0),
new BookModel("La forêt sombre","Cixin Liu","Terminé", 0),
new BookModel("Le problème à trois corps","Cixin Liu","Terminé", 0)
};
#endregion #endregion
#region Constructor #region Constructor

@ -0,0 +1,31 @@
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ViewModels;
namespace LivreLand.ViewModel
{
public class ALirePlusTardVM : BaseViewModel
{
#region Properties
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
#endregion
#region Constructor
public ALirePlusTardVM(NavigatorVM navigatorVM, ManagerVM managerVM)
{
Navigator = navigatorVM;
Manager = managerVM;
}
#endregion
}
}

@ -0,0 +1,31 @@
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ViewModels;
namespace LivreLand.ViewModel
{
public class FiltrageNoteVM : BaseViewModel
{
#region Properties
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
#endregion
#region Constructor
public FiltrageNoteVM(NavigatorVM navigatorVM, ManagerVM managerVM)
{
Navigator = navigatorVM;
Manager = managerVM;
}
#endregion
}
}

@ -13,6 +13,8 @@ namespace ViewModels
private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>(); private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>();
private readonly ObservableCollection<AuthorVM> authors = new ObservableCollection<AuthorVM>(); private readonly ObservableCollection<AuthorVM> authors = new ObservableCollection<AuthorVM>();
private readonly ObservableCollection<PublishDateVM> publishDates = new ObservableCollection<PublishDateVM>(); private readonly ObservableCollection<PublishDateVM> publishDates = new ObservableCollection<PublishDateVM>();
private readonly ObservableCollection<RatingsVM> ratings = new ObservableCollection<RatingsVM>();
private readonly ObservableCollection<BookVM> toBeReadBooks = new ObservableCollection<BookVM>();
private int index; private int index;
private long nbBooks; private long nbBooks;
@ -35,6 +37,16 @@ namespace ViewModels
get => publishDates; get => publishDates;
} }
public ObservableCollection<RatingsVM> AllRatings
{
get => ratings;
}
public ObservableCollection<BookVM> ToBeReadBooks
{
get => toBeReadBooks;
}
public AuthorVM SelectedAuthor { get; private set; } public AuthorVM SelectedAuthor { get; private set; }
public string SearchTitle { get; private set; } public string SearchTitle { get; private set; }
@ -72,6 +84,10 @@ namespace ViewModels
public ICommand GetAllPublishDatesCommand { get; private set; } public ICommand GetAllPublishDatesCommand { get; private set; }
public ICommand GetAllRatingsCommand { get; private set; }
public ICommand GetToBeReadBooksCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -84,6 +100,8 @@ namespace ViewModels
GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor()); GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor());
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors()); GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates()); GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates());
GetAllRatingsCommand = new RelayCommand(() => GetAllRatings());
GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks());
//GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book))); //GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book)));
} }
@ -163,10 +181,61 @@ namespace ViewModels
foreach (var b in someBooks.Select(b => new BookVM(b))) foreach (var b in someBooks.Select(b => new BookVM(b)))
{ {
var date = new PublishDateVM { PublishDate = b.PublishDate }; var date = new PublishDateVM { PublishDate = b.PublishDate };
date.NbBooksWritten++;
publishDates.Add(date); publishDates.Add(date);
foreach (var p in publishDates)
{
if (date.PublishDate.Year == p.PublishDate.Year && !date.Equals(p))
{
p.NbBooksWritten++;
publishDates.Remove(date);
}
}
} }
OnPropertyChanged(nameof(AllPublishDates)); OnPropertyChanged(nameof(AllPublishDates));
} }
private async Task GetAllRatings()
{
var result = await Model.GetBooksFromCollection(0, 20);
IEnumerable<Book> someBooks = result.books;
books.Clear();
ratings.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b)))
{
var rating = new RatingsVM { Average = b.UserRating};
if (rating.Average != null)
{
rating.NbBooksWritten++;
ratings.Add(rating);
foreach (var r in ratings)
{
if (rating.Average == r.Average && !rating.Equals(r))
{
r.NbBooksWritten++;
ratings.Remove(rating);
}
}
}
}
OnPropertyChanged(nameof(AllRatings));
}
private async Task GetToBeReadBooks()
{
var result = await Model.GetBooksFromCollection(0, 20);
IEnumerable<Book> someBooks = result.books;
books.Clear();
toBeReadBooks.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b)))
{
if (b.Status == Status.ToBeRead)
{
toBeReadBooks.Add(b);
}
}
}
#endregion #endregion
} }
} }

@ -0,0 +1,46 @@
using Model;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels
{
public class RatingsVM
{
#region Fields
private int nbBooksWritten { get; set; }
#endregion
#region Properties
public float? Average { get; set; }
public int Count { get; set; }
public int NbBooksWritten
{
get => nbBooksWritten;
set
{
nbBooksWritten = value;
}
}
#endregion
#region Constructor
public RatingsVM()
{
}
#endregion
}
}
Loading…
Cancel
Save