"collectionView" page (Books binding) finie

master
enzoj 2 years ago
parent 83eb9bc198
commit 3d8a15ca87

Binary file not shown.

Binary file not shown.

@ -3,8 +3,8 @@
<PropertyGroup>
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
<ActiveDebugFramework>net7.0-android</ActiveDebugFramework>
<ActiveDebugProfile>Émulateur Android</ActiveDebugProfile>
<SelectedPlatformGroup>Emulator</SelectedPlatformGroup>
<ActiveDebugProfile>Samsung SM-A705FN (Android 11.0 - API 30)</ActiveDebugProfile>
<SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetPlatformIdentifier)'=='iOS'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>

@ -22,17 +22,24 @@
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<StackLayout>
<Label Style="{StaticResource AuteurLivre}" Text="{Binding Auteur}" TextColor="Gray"/>
<Label Style="{StaticResource AuteurLivre}" Text="{Binding Author}" TextColor="Gray"/>
</StackLayout>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.GroupFooterTemplate>
<DataTemplate>
<StackLayout>
<Line X1="20" X2="500"/>
</StackLayout>
</DataTemplate>
</CollectionView.GroupFooterTemplate>
<CollectionView.ItemTemplate >
<DataTemplate>
<StackLayout>
<Comp:Livre ImageComp="{Binding Image}" AuteurComp="{Binding Auteur}" TitreComp="{Binding Title}" NoteComp="{Binding Note}" Margin="15,8,0,15"/>
<Line X1="20" X2="500" IsVisible="{Binding Separateur}" />
<Comp:Livre ImageComp="{Binding ImageMedium}" AuteurComp="{Binding Authors}" UserRatingComp="{Binding UserRating}" TitreComp="{Binding Title}" Margin="15,8,0,15"/>
</StackLayout>
</DataTemplate>

@ -12,8 +12,8 @@ public partial class BooksPage : ContentPage
{
InitializeComponent();
collectionView.ItemsSource = bookViewModel.Books;
collectionView.ItemsSource = bookViewModel.GroupBooks;
}
}
}

@ -5,13 +5,13 @@
<Grid ColumnDefinitions="Auto,*">
<Image x:Name="Image" Grid.Column="0" Style="{StaticResource ImageLivre}" Source="null" />
<Image x:Name="ImageXAML" Grid.Column="0" Style="{StaticResource ImageLivre}" Source="null" />
<Grid Grid.Column="1" RowDefinitions="Auto,Auto,Auto,*,Auto">
<Label x:Name="Titre" Grid.Row="0" Style="{StaticResource TitreLivre}" Text="Title"/>
<Label x:Name="Auteur" Grid.Row="1" Style="{StaticResource AuteurLivreComponent}" Text="Auteur"/>
<Label x:Name="Statut" Grid.Row="2" Style="{StaticResource StatutLivre}" Text="Statut"/>
<Label x:Name="TitreXAML" Grid.Row="0" Style="{StaticResource TitreLivre}" Text="Title"/>
<Label x:Name="AuteurXAML" Grid.Row="1" Style="{StaticResource AuteurLivreComponent}" Text="Auteur"/>
<Label x:Name="StatutXAML" Grid.Row="2" Style="{StaticResource StatutLivre}" Text="Statut"/>
<!--<Label x:Name="Etoile" Grid.Row="4" Style="{StaticResource EtoileLivre}" Text="Etoile"/>-->
<HorizontalStackLayout Grid.Row="4" Style="{StaticResource EtoileLivre}">
<Image x:Name="etoile1" Source="etoilenotfill" Style="{StaticResource EtoileImageLivre}" />
@ -19,7 +19,7 @@
<Image x:Name="etoile3" Source="etoilenotfill" Style="{StaticResource EtoileImageLivre}" />
<Image x:Name="etoile4" Source="etoilenotfill" Style="{StaticResource EtoileImageLivre}" />
<Image x:Name="etoile5" Source="etoilenotfill" Style="{StaticResource EtoileImageLivre}" />
<Label x:Name="Note" IsVisible="false" Text="Default" />
<Label x:Name="NoteXAML" IsVisible="false" Text="Default" />
</HorizontalStackLayout>
</Grid>

@ -1,15 +1,17 @@
using Model;
using System.Reflection;
using ToolKit;
namespace MVVM.Pages.Component;
public partial class Livre : ContentView
{
public static readonly BindableProperty TitreCompProperty = BindableProperty.Create(nameof(TitreComp), typeof(string), typeof(Livre), string.Empty);
public static readonly BindableProperty ImageCompProperty = BindableProperty.Create(nameof(ImageComp), typeof(string), typeof(Livre), string.Empty);
public static readonly BindableProperty AuteurCompProperty = BindableProperty.Create(nameof(AuteurComp), typeof(string), typeof(Livre), string.Empty);
public static readonly BindableProperty NoteCompProperty = BindableProperty.Create(nameof(NoteComp), typeof(string), typeof(Livre), string.Empty);
public static readonly BindableProperty AuteurCompProperty = BindableProperty.Create(nameof(AuteurComp), typeof(string), typeof(string),null);
public static readonly BindableProperty UserRatingCompProperty = BindableProperty.Create(nameof(UserRatingComp), typeof(float), typeof(Livre), null);
@ -27,39 +29,49 @@ public partial class Livre : ContentView
public string AuteurComp
{
get => (string)GetValue(Livre.AuteurCompProperty);
get
{ /*
List<Author> list = (List<Author>)GetValue(Livre.AuteurCompProperty);
string auth = "";
for(int i = 0 ; i < list.Count;i++)
{
auth += list[i].Name;
if ( i < list.Count - 1)
{
auth += ", ";
}
}
return auth;*/
return (string)GetValue(Livre.AuteurCompProperty);
}
set => SetValue(Livre.AuteurCompProperty, value);
}
public string NoteComp
public float UserRatingComp
{
get
{
string note = (string)GetValue(Livre.NoteCompProperty);
float note = (float)GetValue(Livre.UserRatingCompProperty);
imageStar(note);
return note;
}
set => SetValue(Livre.NoteCompProperty, value);
set => SetValue(Livre.UserRatingCompProperty, value);
}
public Livre()
{
InitializeComponent();
Titre.SetBinding(Label.TextProperty, new Binding(nameof(TitreComp), source: this));
Image.SetBinding(Image.SourceProperty, new Binding(nameof(ImageComp), source: this));
Auteur.SetBinding(Label.TextProperty, new Binding(nameof(AuteurComp), source: this));
Note.SetBinding(Label.TextProperty, new Binding(nameof (NoteComp), source: this));
TitreXAML.SetBinding(Label.TextProperty, new Binding(nameof(TitreComp), source: this));
ImageXAML.SetBinding(Image.SourceProperty, new Binding(nameof(ImageComp), source: this));
AuteurXAML.SetBinding(Label.TextProperty, new Binding(nameof(AuteurComp), source: this));
NoteXAML.SetBinding(Label.TextProperty, new Binding(nameof (UserRatingComp), source: this));
}
private void imageStar(string note)
{
if (note == null || note.Length == 0)
{
return;
}
int tmp = int.Parse(note);
private void imageStar(float note)
{
int tmp = (int)note;
if (tmp > 0 )
{
@ -82,4 +94,43 @@ public partial class Livre : ContentView
etoile5.Source = "etoile";
}
}
/*
public string ImageSmall
{
get { return imageSmall; }
set { imageSmall = value; }
}
private string imageSmall;
public string Title
{
get { return title; }
set { title = value; }
}
private string title;
public string Author
{
get { return author; }
set { author = value; }
}
private string author;
public string Note
{
get { return note; }
set { note = value; }
}
private string note;
public Livre()
{
InitializeComponent();
//ImageXAML.SetBinding(Image.SourceProperty, ImageSmall);
//AuteurXAML.SetBinding(Label.TextProperty, Author);
//NoteXAML.SetBinding (Label.TextProperty, Note);
}*/
}

@ -45,7 +45,7 @@
<DataTemplate>
<StackLayout>
<local:Livre ImageComp="{Binding Image}" AuteurComp="{Binding Auteur}" TitreComp="{Binding Titre}" NoteComp="{Binding Note}" Margin="15,8,0,15"/>
<local:Livre Margin="15,8,0,15"/>
</StackLayout>
</DataTemplate>

@ -44,7 +44,7 @@
<Image Style="{StaticResource IconBibliotheque}" Source="tray_fill" Grid.Column="0"/>
<Label Style="{StaticResource TexteBibliotheque}" Text="Tous" Grid.Column="1" />
<Label Style="{StaticResource NombreBibliotheque}" Text="45" Grid.Column="3"/>
<Label x:Name="NbBookXAML" Style="{StaticResource NombreBibliotheque}" Text="{Binding BooksViewModel.NbBook}" Grid.Column="3"/>
<Image Style="{StaticResource ChevronBibliotheque}" Source="chevron_right" Grid.Column="4" />
</Grid>

@ -1,4 +1,5 @@
using MVVM.VmApplicatif;
using Wrapper;
namespace MVVM.Pages;
@ -6,10 +7,13 @@ public partial class MyLibraryPage : ContentPage
{
public NavigateAndLoadBooks NavigateAndLoadBooks { get; set;}
public MyLibraryPage(NavigateAndLoadBooks navigateAndLoadBooks)
public BooksViewModel BooksViewModel { get; set;}
public MyLibraryPage(NavigateAndLoadBooks navigateAndLoadBooks, BooksViewModel bookViewModel)
{
this.NavigateAndLoadBooks = navigateAndLoadBooks;
//BindingContext = NavigateAndLoadBooks.BooksViewModel.Books;
this.BooksViewModel = bookViewModel;
BindingContext = this;
InitializeComponent();
}

File diff suppressed because one or more lines are too long

@ -1 +1 @@
<?xml version="1.0" encoding="utf-8"?><XamlCompilerSaveState><XamlFeatureControlFlags>EnableXBindDiagnostics, EnableDefaultValidationContextGeneration, EnableWin32Codegen, UsingCSWinRT</XamlFeatureControlFlags><ReferenceAssemblyList><LocalAssembly PathName="e:\home\projet\mvvm\mvvm\mvvm\obj\debug\net7.0-windows10.0.19041.0\win10-x64\intermediatexaml\mvvm.dll" HashGuid="6e4d6e3a-0223-6cc5-b055-27fefc60a96e" /><ReferenceAssembly PathName="e:\home\projet\mvvm\mvvm\stub\bin\debug\net7.0\stub.dll" HashGuid="10dd672d-668a-9ba3-644f-678d5c070457" /><ReferenceAssembly PathName="e:\home\projet\mvvm\mvvm\wrapper\bin\debug\net7.0\wrapper.dll" HashGuid="9edd8573-1736-cc2d-8ada-957a0aed96e8" /></ReferenceAssemblyList><XamlSourceFileDataList><XamlSourceFileData XamlFileName="Platforms\Windows\App.xaml" ClassFullName="MVVM.WinUI.App" GeneratedCodePathPrefix="E:\Home\Projet\MVVM\MVVM\MVVM\obj\Debug\net7.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App" XamlFileTimeAtLastCompileInTicks="638320548352180702" HasBoundEventAssignments="False" /></XamlSourceFileDataList></XamlCompilerSaveState>
<?xml version="1.0" encoding="utf-8"?><XamlCompilerSaveState><XamlFeatureControlFlags>EnableXBindDiagnostics, EnableDefaultValidationContextGeneration, EnableWin32Codegen, UsingCSWinRT</XamlFeatureControlFlags><ReferenceAssemblyList><LocalAssembly PathName="e:\home\projet\mvvm\mvvm\mvvm\obj\debug\net7.0-windows10.0.19041.0\win10-x64\intermediatexaml\mvvm.dll" HashGuid="6e4d6e3a-0223-6cc5-b055-27fefc60a96e" /><ReferenceAssembly PathName="e:\home\projet\mvvm\mvvm\stub\bin\debug\net7.0\stub.dll" HashGuid="10dd672d-668a-9ba3-644f-678d5c070457" /><ReferenceAssembly PathName="e:\home\projet\mvvm\mvvm\wrapper\bin\debug\net7.0\wrapper.dll" HashGuid="3633159c-3027-92c6-f912-678fda755c5e" /></ReferenceAssemblyList><XamlSourceFileDataList><XamlSourceFileData XamlFileName="Platforms\Windows\App.xaml" ClassFullName="MVVM.WinUI.App" GeneratedCodePathPrefix="E:\Home\Projet\MVVM\MVVM\MVVM\obj\Debug\net7.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App" XamlFileTimeAtLastCompileInTicks="638320548352180702" HasBoundEventAssignments="False" /></XamlSourceFileDataList></XamlCompilerSaveState>

@ -21,7 +21,7 @@ public class Book : IEquatable<Book>
public List<Author> Authors { get; set; } = new List<Author>();
public Status Status { get; set; }
public List<string> UserTags { get; set; } = new List<string>();
public float? UserRating { get; set; }
public float? UserRating { get; set; }
public string UserNote { get; set; }
public bool Equals(Book? other)

@ -20,70 +20,91 @@ namespace Wrapper
}
private readonly List<Book> books;*/
public ObservableCollection<Book> Books
{
get => Books;
private set
{
Books = value;
//UpdateGroupBooks();
}
}
public ObservableCollection<Book> Books = new ObservableCollection<Book>();
public ObservableCollection<GroupBooks> GroupBooks { get; private set; } = new ObservableCollection<GroupBooks>();
public BooksViewModel(ILibraryManager libraryManager,IUserLibraryManager userLibraryManager)
{
Books = new ObservableCollection<Book>();
Manager = new Manager(libraryManager, userLibraryManager);
LoadBooks = new RelayCommand<string>(o => LoadBooksFromManager());
Count = 2;
Count = 7;
LoadBooksFromManager();
}
/*
private void UpdateGroupBooks()
{
GroupBooks.Clear();
foreach (Book book in Books)
{
foreach (Author author in book.Authors)
{
int find = -1;
for(int i = 0; i < GroupBooks.Count(); i++)
if (book.Authors.Count != 0)
{
foreach (Author author in book.Authors)
{
if (GroupBooks[i].Author == author.Name )
{
find = i;
break;
}
Console.WriteLine(author.Name);
int find = -1;
for (int i = 0; i < GroupBooks.Count(); i++)
{
if (GroupBooks[i].Author == author.Name)
{
find = i;
break;
}
}
Console.WriteLine("l - 55");
if (find != -1)
{
Console.WriteLine("l - 58");
GroupBooks[find].Add(book);
}
else
{
Console.WriteLine("l - 63");
GroupBooks.Add(new GroupBooks(author.Name, new List<Book> { book }));
}
}
if ( find != -1 )
}
else
{
int index = -1;
for ( int i = 0; i < GroupBooks.Count(); i++)
{
GroupBooks[find].Add(book);
if (GroupBooks[i].Author == "Inconnu")
{
index = i;
break;
}
}
else
if (index == -1)
{
GroupBooks.Add(new GroupBooks(author.Name, new List<Book>{book}));
GroupBooks.Add(new GroupBooks("Inconnu", new List<Book> { book }));
} else
{
GroupBooks[index].Add(book);
}
}
}
Console.WriteLine(GroupBooks.Count);
}*/
}
private void LoadBooksFromManager()
{
var result = Manager.GetBooksFromCollection(index,count,"");
if (result.Result.count == 0 ) { return ; }
if (result.Result.books.Count() == 0 ) { return ; }
Books.Clear();
foreach (Book book in result.Result.books)
{
Books.Add(book);
}
NbBook = result.Result.count;
UpdateGroupBooks();
}
public int Index {
@ -109,5 +130,16 @@ namespace Wrapper
}
private int count;
public long NbBook
{
get { return nbBook; }
private set
{
setProperty(ref nbBook, value);
}
}
private long nbBook;
}
}
Loading…
Cancel
Save