sélection d'un livre et la navigation vers la page BookPage + binding principal

master
Lucas Evard 2 years ago
parent 7d7ea4c4a7
commit 957999cce5

@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace MyToolkitMVVM;
@ -17,11 +18,13 @@ public class ObservableObject : INotifyPropertyChanged
if (EqualityComparer<T>.Default.Equals(member, value)) return;
member = value;
OnPropertyChanged(propertyName);
Debug.WriteLine("PropertyChanged "+propertyName);
}
protected void SetProperty<T>(T member, T value,Action<T> action, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(member, value)) return;
action(value);
OnPropertyChanged(propertyName);
Debug.WriteLine("PropertyChanged " + propertyName);
}
}

@ -8,17 +8,12 @@ namespace PocketBook.Applicative_VM
public class NavigatorVM
{
public ICommand Navigateto { get; private set; }
public ICommand SeeDetailPage { get; private set; }
public NavigatorVM()
{
Navigateto = new Command<string>(
async (string page) => await Shell.Current.GoToAsync(page)
);
SeeDetailPage = new Command(
async () => await Shell.Current.GoToAsync("BookDetail")
);
}
}
}

@ -0,0 +1,33 @@
using System;
using System.Diagnostics;
using System.Windows.Input;
using MyToolkitMVVM;
using ViewModel;
namespace PocketBook.Applicative_VM
{
public class TousPageVM : BaseViewModel
{
public ICommand NavigateDetailPage { get; private set; }
public NavigatorVM NavigateCommandBooks { get; private set; }
public ScanMenuVM ScanMenuVM { get; private set; }
public ManagerVM Manager { get; private set; }
public TousPageVM(NavigatorVM navigation,ManagerVM manager, ScanMenuVM scanMenuVM)
{
ScanMenuVM = scanMenuVM;
Manager = manager;
NavigateCommandBooks = navigation;
NavigateDetailPage = new Command<BookVM>(book =>
{
Debug.WriteLine(book.Id);
Manager.LoadBookFromManager(book.Id);
Debug.WriteLine(Manager.SelectedBook.Title);
NavigateCommandBooks.Navigateto.Execute("BookDetail");
});
}
}
}

@ -42,10 +42,11 @@ public static class MauiProgram
});
builder.Services
.AddSingleton<ILibraryManager,LibraryStub>()
.AddSingleton<IUserLibraryManager,UserLibraryStub>()
.AddSingleton<ILibraryManager, LibraryStub>()
.AddSingleton<IUserLibraryManager, UserLibraryStub>()
.AddSingleton<NavigatorVM>()
.AddSingleton<ScanMenuVM>()
.AddSingleton<TousPageVM>()
.AddSingleton<MainPage>()
.AddSingleton<TousPage>()
.AddSingleton<BookDetail>()

@ -6,14 +6,14 @@
Title="Détails du livre"
Shell.ForegroundColor="{StaticResource Primary}"
Shell.BackgroundColor="{StaticResource TopBackgroundGrey}"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
x:Name="root">
<ScrollView>
<StackLayout>
<StackLayout Orientation="Horizontal" Margin="15,0,0,20">
<Image x:Name="bookImage" Source="buveurencre.jpg" Margin="0,0,10,0" WidthRequest="90" HeightRequest="160"/>
<Image Source="{Binding SelectedBook.Image}" Margin="0,0,10,0" WidthRequest="90" HeightRequest="160"/>
<StackLayout Orientation="Vertical">
<Label x:Name="titreBook" FontFamily="Pro-Display-Semibold" FontSize="17" Margin="0,15,0,0"/>
<Label Text="{Binding SelectedBook.Title}" FontFamily="Pro-Display-Semibold" FontSize="17" Margin="0,15,0,0"/>
<local:Stars NbStars="1" Margin="0,90,0,0"/>
</StackLayout>
</StackLayout>
@ -26,12 +26,12 @@
<Line BackgroundColor="{StaticResource LineColor1}"/>
<StackLayout >
<Label Text="Auteur" Style="{StaticResource LabelStyleDetailBook3}"/>
<Label x:Name="bookAuteur" Style="{StaticResource LabelStyleDetailBook4}"/>
<Label Text="{Binding SelectedBook.BookFirstAuthor}" Style="{StaticResource LabelStyleDetailBook4}"/>
</StackLayout>
<Line BackgroundColor="{StaticResource LineColor1}"/>
<StackLayout>
<Label Text="Maison d'édition" Style="{StaticResource LabelStyleDetailBook3}"/>
<Label x:Name="bookEdition" Style="{StaticResource LabelStyleDetailBook4}"/>
<Label Text="{Binding SelectedBook.BookFirstPublisher}" Style="{StaticResource LabelStyleDetailBook4}"/>
</StackLayout>
<Line BackgroundColor="{StaticResource LineColor1}"/>
<StackLayout Margin="0,0,0,10">
@ -44,21 +44,21 @@
<Label Text="Détails" Style="{StaticResource LabelStyleDetailBook3}"/>
<StackLayout Orientation="Horizontal">
<Label Text="Nombre de pages" Style="{StaticResource LabelStyleDetailBook4}"/>
<Label x:Name="bookNbPages" Style="{StaticResource LabelStyleDetailBook2}"/>
<Label Text="{Binding SelectedBook.Nbpages}" Style="{StaticResource LabelStyleDetailBook2}"/>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Langue" Style="{StaticResource LabelStyleDetailBook4}"/>
<Label x:Name="bookLangue" Style="{StaticResource LabelStyleDetailBook2}"/>
<Label Text="{Binding SelectedBook.Language}" Style="{StaticResource LabelStyleDetailBook2}"/>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="ISBN" Style="{StaticResource LabelStyleDetailBook4}"/>
<Label x:Name="bookISBN" Style="{StaticResource LabelStyleDetailBook2}"/>
<Label Text="{Binding SelectedBook.ISBN}" Style="{StaticResource LabelStyleDetailBook2}"/>
</StackLayout>
<Line BackgroundColor="{StaticResource LineColor1}"/>
<Label Text="Statut de lecture" Style="{StaticResource LabelStyleDetailBook3}"/>
<StackLayout Orientation="Horizontal">
<Label Text="Statut" Style="{StaticResource LabelStyleDetailBook4}"/>
<Label x:Name="bookStatus" Style="{StaticResource LabelStyleDetailBook2}"/>
<Label Text="{Binding SelectedBook.BookStatus}" Style="{StaticResource LabelStyleDetailBook2}"/>
</StackLayout>
<Line BackgroundColor="{StaticResource LineColor1}"/>
<Label Text="Bibliothèque" Style="{StaticResource LabelStyleDetailBook3}"/>

@ -5,19 +5,22 @@ namespace PocketBook;
public partial class BookDetail : ContentPage
{
public NavigatorVM NavigateCommandBooks { get; private set; }
public TousPageVM TousPageVM { get; private set; }
public BookDetail(NavigatorVM navigator)
public BookDetail(TousPageVM tousPageVM)
{
NavigateCommandBooks = navigator;
//NavigateCommandBooks = navigator;
InitializeComponent();
titreBook.Text = "La horde du contrevent";
/*titreBook.Text = "La horde du contrevent";
bookAuteur.Text = "Alain Damasio";
bookEdition.Text = "Fayard (2019)";
bookNbPages.Text = "700";
bookISBN.Text = "9854645645456";
bookLangue.Text = "français";
bookStatus.Text = "Non lu";
bookAdd.Text = "15 août 2013";
bookAdd.Text = "15 août 2013";*/
TousPageVM = tousPageVM;
BindingContext = TousPageVM.Manager;
}
}

@ -4,9 +4,6 @@
x:Class="PocketBook.ContentViewBook"
xmlns:local="clr-namespace:PocketBook"
x:Name="root">
<ContentView.GestureRecognizers>
<TapGestureRecognizer CommandParameter="{Binding CommandParameter, Source={x:Reference root}}" Command="{Binding Command, Source={x:Reference root}}"/>
</ContentView.GestureRecognizers>
<VerticalStackLayout Margin="15,0,0,0">
<StackLayout Orientation="Horizontal" Margin="0,5,0,0">
<Image x:Name="bookImage" Source="{Binding BookImage, Source={x:Reference root}}" Margin="0,0,10,0" WidthRequest="75" HeightRequest="110"/>

@ -13,24 +13,23 @@
<ContentPage.ToolbarItems>
<ToolbarItem Text="Ajouter" Priority="1"
Order="Primary" IconImageSource="plus.png" Command="{Binding ScanMenuVM.ShowScanMenu}"/>
Order="Primary" IconImageSource="plus.png" Command="{Binding TousPageVM.ScanMenuVM.ShowScanMenu}"/>
<ToolbarItem Text="Order" Priority="2"
Order="Primary" IconImageSource="arrows.png"/>
</ContentPage.ToolbarItems>
<AbsoluteLayout>
<local:ScanMenuView Command="{Binding ScanMenuVM.ModalISBN}" x:Name="scanMenu" IsVisible="{Binding ScanMenuVM.ScanMenuIsVisible}"
<local:ScanMenuView Command="{Binding TousPageVM.ScanMenuVM.ModalISBN}" x:Name="scanMenu" IsVisible="{Binding TousPageVM.ScanMenuVM.ScanMenuIsVisible}"
Margin="0, 8, 8, 0"
AbsoluteLayout.LayoutBounds="1, 0"
AbsoluteLayout.LayoutFlags="PositionProportional" ZIndex="1"/>
<StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<ScrollView VerticalOptions="StartAndExpand">
<VerticalStackLayout>
<local:TitledAuthor NameText="Alain Damasio"/>
<CollectionView ItemsSource="{Binding Manager.Books}">
<CollectionView.ItemTemplate>
<CollectionView x:Name="collection" IsGrouped="True" GroupHeaderTemplate="{StaticResource groupHeaderTemplate}" SelectionMode="Single" SelectionChangedCommand="{Binding TousPageVM.NavigateDetailPage, Source={x:Reference root}}" SelectionChangedCommandParameter="{Binding SelectedItem, Source={x:Reference collection}}" ItemsSource="{Binding TousPageVM.Manager.GroupedBooks}">
<CollectionView.ItemTemplate>
<DataTemplate>
<local:ContentViewBook Margin="0,5,0,0" Nbstars="1" Command="{Binding NavigateCommandBooks.SeeDetailPage, Source={x:Reference root}}" BookImage="{Binding Image}" BookName="{Binding Title}" AutorName="{Binding BookFirstAuthor}" BookStatus="{Binding BookStatus}"/>
<local:ContentViewBook Margin="0,5,0,0" Nbstars="2" BookImage="{Binding Image}" BookName="{Binding Title}" AutorName="{Binding BookFirstAuthor}" BookStatus="{Binding BookStatus}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

@ -1,3 +1,4 @@
using System.Diagnostics;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Views;
using PocketBook.Applicative_VM;
@ -7,15 +8,11 @@ namespace PocketBook;
public partial class TousPage : ContentPage
{
public NavigatorVM NavigateCommandBooks { get; private set; }
public ScanMenuVM ScanMenuVM { get; private set; }
public ManagerVM Manager { get; private set; }
public TousPageVM TousPageVM { get; private set; }
public TousPage(NavigatorVM navigation,ScanMenuVM scanMenuVM, ManagerVM manager)
public TousPage(TousPageVM tousPageVM)
{
ScanMenuVM = scanMenuVM;
Manager = manager;
NavigateCommandBooks = navigation;
TousPageVM = tousPageVM;
InitializeComponent();
BindingContext = this;
}

@ -25,6 +25,10 @@
<Color x:Key="selectorBackgroundDark">#323137</Color>
<Color x:Key="scanMenuBackgroundLight">#F4F4F4</Color>
<Color x:Key="scanMenuBackgroundDark">#262626</Color>
<Color x:Key="groupHeaderLabelLight">#807F84</Color>
<Color x:Key="groupHeaderLabelDark">#9998A0</Color>
<Color x:Key="groupHeaderBackgroundLight">#F1F1F6</Color>
<Color x:Key="groupHeaderBackgroundDark">#1C1C1E</Color>
<Color x:Key="scanMenuTitleLight">#C8C8C8</Color>
<Color x:Key="scanMenuTitleDark">#9E9F13</Color>
<Color x:Key="scanMenuDividerLight">#C8C8C8</Color>

@ -13,6 +13,25 @@
<Setter Property="SelectedIndicatorColor" Value="{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray100}}"/>
</Style>
<Style TargetType="Label" x:Key="groupHeaderLabel">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource groupHeaderLabelLight}, Dark={StaticResource groupHeaderLabelDark}}"/>
<Setter Property="FontFamily" Value="Pro-Display-Semibold"/>
<Setter Property="FontAttributes" Value="Bold"/>
<Setter Property="VerticalOptions" Value="Center"/>
<Setter Property="Margin" Value="16,0"/>
<Setter Property="FontSize" Value="14"/>
</Style>
<DataTemplate x:Key="groupHeaderTemplate">
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource groupHeaderBackgroundLight}, Dark={StaticResource groupHeaderBackgroundDark}}"
HorizontalOptions="Fill"
RowDefinitions="30">
<Label Text="{Binding Key}" Style="{StaticResource groupHeaderLabel}"/>
</Grid>
</DataTemplate>
<Style TargetType="Border" x:Key="BorderStyle">
<Setter Property="Stroke" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray500}}" />
<Setter Property="StrokeShape" Value="Rectangle"/>

@ -12,12 +12,36 @@ namespace ViewModel
set =>SetProperty(Model.Title,value,v=>Model.Title=v);
}
public int Nbpages
{
get => Model.NbPages;
set => SetProperty(Model.NbPages, value, v => Model.NbPages = v);
}
public Languages Language
{
get => Model.Language;
set => SetProperty(Model.Language, value, v => Model.Language = v);
}
public string Id
{
get => Model.Id;
set => SetProperty(Model.Id, value, v => Model.Id = v);
}
public string Image
{
get => Model.ImageLarge;
set { }
}
public string ISBN
{
get => Model.ISBN13;
set => SetProperty(Model.ISBN13, value, v => Model.ISBN13 = v);
}
public Status BookStatus
{
get => Model.Status;
@ -27,6 +51,15 @@ namespace ViewModel
}
}
public List<string> BookPublishers
{
get => Model.Publishers;
set
{
SetProperty(Model.Publishers, value, v => Model.Publishers = v);
}
}
public List<Author> BookAuthors
{
get => Model.Authors;
@ -38,18 +71,22 @@ namespace ViewModel
public string BookFirstAuthor { get; private set; }
public BookVM(Book book)
public string BookFirstPublisher { get; private set; }
public BookVM(Book book): base(book)
{
Model = book;
Title = book.Title;
BookStatus = book.Status;
BookAuthors = book.Authors;
Image = book.ImageLarge;
if (BookAuthors.Count() > 0)
{
BookFirstAuthor = BookAuthors.First().Name;
}
else BookFirstAuthor = "Unknow";
else BookFirstAuthor = "Unknown";
if (BookPublishers.Count() > 0)
{
BookFirstPublisher = BookPublishers.First();
}
else BookFirstPublisher = "Unknown";
}
}
}

@ -12,13 +12,23 @@ public class ManagerVM : BaseViewModel<Manager>
public RelayCommand<string> LoadBooks { get; private set; }
public IEnumerable<IGrouping<string, BookVM>> GroupedBooks => Books.GroupBy(b => b.BookFirstAuthor).OrderBy(group => group.Key);
public BookVM SelectedBook
{
get => selectedBook;
set => SetProperty(ref selectedBook, value);
}
private BookVM selectedBook;
public ManagerVM(ILibraryManager libraryManager,IUserLibraryManager userLibraryManager)
:this(new Manager(libraryManager,userLibraryManager))
{}
public async void LoadBooksFromManager()
{
var result = await Model.GetBooksFromCollection(index, 10, "");
var result = await Model.GetBooksFromCollection(index, 40, "");
NbBook = (int)result.count;
books.Clear();
@ -28,9 +38,14 @@ public class ManagerVM : BaseViewModel<Manager>
}
}
public async void LoadBookFromManager(string id)
{
var result = await Model.GetBookById(id);
SelectedBook = new BookVM(result);
}
public ManagerVM(Manager model) : base(model)
{
Model = model;
LoadBooks = new RelayCommand<string>(o => LoadBooksFromManager());
LoadBooks.Execute();
Books = new ReadOnlyObservableCollection<BookVM>(books);

Loading…
Cancel
Save