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

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

@ -1,22 +1,40 @@
using LivreLand.Model;
using LivreLand.ViewModel;
namespace LivreLand.View;
public partial class ALirePlusTardView : ContentPage
{
public List<BookModel> ALirePlusTardBooks { get; set; } = new List<BookModel>()
{
new BookModel("La horde du contrevent","Alain Damasio","Non lu", 0),
};
#region Properties
public ALirePlusTardVM ALirePlusTardVM { get; set; }
#endregion
#region Constructor
public ALirePlusTardView()
public ALirePlusTardView(ALirePlusTardVM aLirePlusTardVM)
{
BindingContext = this;
ALirePlusTardVM = aLirePlusTardVM;
InitializeComponent();
BindingContext = this;
}
#endregion
#region Properties
void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//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:view="clr-namespace:LivreLand.View"
xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels"
x:Class="LivreLand.View.FiltrageNoteView"
Title="FiltrageNoteView">
@ -34,51 +35,25 @@
<VerticalStackLayout Grid.Row="2">
<contentView:SeparatorEntireView/>
<!--1 étoile-->
<contentView:HomeButtonView ButtonTitle="1 étoile"
<CollectionView ItemsSource="{Binding FiltrageNoteVM.Manager.AllRatings}"
SelectionChangedCommand="{Binding FiltrageNoteVM.Navigator.NavigationCommand}"
SelectionChangedCommandParameter="/tous">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:RatingsVM">
<VerticalStackLayout>
<contentView:HomeButtonView ButtonTitle="{Binding Average}"
ButtonIcon="book.png"
ButtonNumber="2"
ButtonNumber="{Binding NbBooksWritten}"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2 étoiles-->
<contentView:HomeButtonView ButtonTitle="2 étoiles"
ButtonIcon="book.png"
ButtonNumber="2"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--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>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</Grid>

@ -1,9 +1,34 @@
using LivreLand.ViewModel;
namespace LivreLand.View;
public partial class FiltrageNoteView : ContentPage
{
public FiltrageNoteView()
#region Properties
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 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
#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<AuthorVM> authors = new ObservableCollection<AuthorVM>();
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 long nbBooks;
@ -35,6 +37,16 @@ namespace ViewModels
get => publishDates;
}
public ObservableCollection<RatingsVM> AllRatings
{
get => ratings;
}
public ObservableCollection<BookVM> ToBeReadBooks
{
get => toBeReadBooks;
}
public AuthorVM SelectedAuthor { get; private set; }
public string SearchTitle { get; private set; }
@ -72,6 +84,10 @@ namespace ViewModels
public ICommand GetAllPublishDatesCommand { get; private set; }
public ICommand GetAllRatingsCommand { get; private set; }
public ICommand GetToBeReadBooksCommand { get; private set; }
#endregion
#region Constructor
@ -84,6 +100,8 @@ namespace ViewModels
GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor());
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
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)));
}
@ -163,10 +181,61 @@ namespace ViewModels
foreach (var b in someBooks.Select(b => new BookVM(b)))
{
var date = new PublishDateVM { PublishDate = b.PublishDate };
date.NbBooksWritten++;
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));
}
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
}
}

@ -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