Affichage de la liste de livres + vue modale pour la saisie de l'isbn

master
Lucas Evard 2 years ago
parent beab4f76c7
commit 7d7ea4c4a7

@ -4,7 +4,10 @@ namespace MyToolkitMVVM
public class BaseViewModel<TModel> : ObservableObject public class BaseViewModel<TModel> : ObservableObject
{ {
public TModel Model { get; private set; } public TModel Model {
get => model;
set => SetProperty(ref model,value);
}
private TModel model; private TModel model;
public BaseViewModel(TModel model) public BaseViewModel(TModel model)

@ -27,7 +27,25 @@ namespace MyToolkitMVVM
{ {
execute((T)parameter); execute((T)parameter);
} }
}
public class RelayCommand : RelayCommand<object>
{
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
: base(execute, canExecute)
{
}
/* public async Task<bool> CanExecuteAsync(object? parameter)
{
if (parameter == null)
return true;
return await CanExecuteInternalAsync((T)parameter);
}*/
public async Task Execute()
{
await Execute();
}
} }
} }

@ -4,16 +4,15 @@ public partial class AppShell : Shell
{ {
public AppShell() public AppShell()
{ {
Routing.RegisterRoute("MainPage/TousPage",typeof(TousPage)); Routing.RegisterRoute("TousPage",typeof(TousPage));
Routing.RegisterRoute("MainPage/StatutPage", typeof(StatutPage)); Routing.RegisterRoute("StatutPage", typeof(StatutPage));
Routing.RegisterRoute("MainPage/SharePage", typeof(SharePage)); Routing.RegisterRoute("SharePage", typeof(SharePage));
Routing.RegisterRoute("MainPage/LaterPage", typeof(SharePage)); Routing.RegisterRoute("LaterPage", typeof(SharePage));
Routing.RegisterRoute("MainPage/LikePage", typeof(LikePage)); Routing.RegisterRoute("LikePage", typeof(LikePage));
Routing.RegisterRoute("MainPage/Auteur", typeof(SharePage)); Routing.RegisterRoute("Auteur", typeof(SharePage));
Routing.RegisterRoute("MainPage/DatePublic", typeof(DatePublic)); Routing.RegisterRoute("DatePublic", typeof(DatePublic));
Routing.RegisterRoute("MainPage/MarkPage", typeof(MarkPage)); Routing.RegisterRoute("MarkPage", typeof(MarkPage));
Routing.RegisterRoute("BookDetail", typeof(BookDetail));
Routing.RegisterRoute("MainPage/TousPage/BookDetail", typeof(BookDetail));
InitializeComponent(); InitializeComponent();
} }
} }

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

@ -16,11 +16,8 @@ namespace PocketBook.Applicative_VM
public bool ScanMenuIsVisible public bool ScanMenuIsVisible
{ {
get { return scanMenuIsVisible; } get => scanMenuIsVisible;
set set => SetProperty(ref scanMenuIsVisible,value);
{
SetProperty(ref scanMenuIsVisible,value);
}
} }
public ScanMenuVM() public ScanMenuVM()

@ -1,6 +1,9 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui; using CommunityToolkit.Maui;
using PocketBook.Applicative_VM; using PocketBook.Applicative_VM;
using ViewModel;
using StubLib;
using Model;
namespace PocketBook; namespace PocketBook;
@ -39,6 +42,8 @@ public static class MauiProgram
}); });
builder.Services builder.Services
.AddSingleton<ILibraryManager,LibraryStub>()
.AddSingleton<IUserLibraryManager,UserLibraryStub>()
.AddSingleton<NavigatorVM>() .AddSingleton<NavigatorVM>()
.AddSingleton<ScanMenuVM>() .AddSingleton<ScanMenuVM>()
.AddSingleton<MainPage>() .AddSingleton<MainPage>()
@ -49,6 +54,7 @@ public static class MauiProgram
.AddSingleton<LaterPage>() .AddSingleton<LaterPage>()
.AddSingleton<MarkPage>() .AddSingleton<MarkPage>()
.AddSingleton<SharePage>() .AddSingleton<SharePage>()
.AddSingleton<ManagerVM>()
.AddSingleton<StatutPage>() .AddSingleton<StatutPage>()
.AddSingleton<Auteur>() .AddSingleton<Auteur>()
; ;

@ -15,7 +15,7 @@
<Label x:Name="autorName" Text="{Binding AutorName, Source={x:Reference root}}" FontFamily="Pro-Text-Semibold" FontSize="12"/> <Label x:Name="autorName" Text="{Binding AutorName, Source={x:Reference root}}" FontFamily="Pro-Text-Semibold" FontSize="12"/>
<Label x:Name="bookStatus" Text="{Binding BookStatus, Source={x:Reference root}}" FontFamily="Pro-Text-Semibold" FontSize="12" TextColor="#AFAFAF"/> <Label x:Name="bookStatus" Text="{Binding BookStatus, Source={x:Reference root}}" FontFamily="Pro-Text-Semibold" FontSize="12" TextColor="#AFAFAF"/>
<StackLayout Orientation="Horizontal" Margin="0,30,0,0"> <StackLayout Orientation="Horizontal" Margin="0,30,0,0">
<local:Stars NbStars="1" Margin="0,0,0,5"/> <local:Stars NbStars="{Binding Nbstars, Source={x:Reference root}}" Margin="0,0,0,5"/>
</StackLayout> </StackLayout>
</StackLayout> </StackLayout>
</StackLayout> </StackLayout>

@ -19,6 +19,9 @@ public partial class ContentViewBook : ContentView
public static readonly BindableProperty CommandProperty = public static readonly BindableProperty CommandProperty =
BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(ContentViewBook)); BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(ContentViewBook));
public static readonly BindableProperty StarsProperty =
BindableProperty.Create(nameof(Nbstars), typeof(int), typeof(ContentViewBook));
public static readonly BindableProperty CommandParameterProperty = public static readonly BindableProperty CommandParameterProperty =
BindableProperty.Create(nameof(CommandParameter), typeof(string), typeof(ContentViewBook)); BindableProperty.Create(nameof(CommandParameter), typeof(string), typeof(ContentViewBook));
@ -28,6 +31,12 @@ public partial class ContentViewBook : ContentView
set { SetValue(CommandProperty, value); } set { SetValue(CommandProperty, value); }
} }
public int Nbstars
{
get { return (int)GetValue(StarsProperty); }
set { SetValue(StarsProperty, value); }
}
public string CommandParameter public string CommandParameter
{ {
get { return (string)GetValue(CommandParameterProperty); } get { return (string)GetValue(CommandParameterProperty); }

@ -6,6 +6,7 @@ public partial class Stars : ContentView
{ {
public static readonly BindableProperty NbStarsProperty = public static readonly BindableProperty NbStarsProperty =
BindableProperty.Create(nameof(NbStars), typeof(int), typeof(Stars), defaultValue: 0, propertyChanged: OnNbStarsChanged); BindableProperty.Create(nameof(NbStars), typeof(int), typeof(Stars), defaultValue: 0, propertyChanged: OnNbStarsChanged);
public int NbStars public int NbStars
{ {
get { return (int)GetValue(NbStarsProperty); } get { return (int)GetValue(NbStarsProperty); }

@ -35,23 +35,23 @@
<Line BackgroundColor="{StaticResource LineColor1}"/> <Line BackgroundColor="{StaticResource LineColor1}"/>
<StackLayout Background="{StaticResource BackgroundMainPage}"> <StackLayout Background="{StaticResource BackgroundMainPage}">
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/TousPage/" FilterImageName="tray_second_fill.png" FilterName="Tous" FilterNum="45"/> <local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="TousPage" FilterImageName="tray_second_fill.png" FilterName="Tous" FilterNum="45"/>
<Line Style="{StaticResource LineStyle2}"/> <Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/SharePage" FilterImageName="person_badge_clock_fill.png" FilterName="En prêt" FilterNum="1"/> <local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="SharePage" FilterImageName="person_badge_clock_fill.png" FilterName="En prêt" FilterNum="1"/>
<Line Style="{StaticResource LineStyle2}"/> <Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/LaterPage" FilterImageName="arrow_forward.png" <local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="LaterPage" FilterImageName="arrow_forward.png"
FilterName="A lire plus tard"/> FilterName="A lire plus tard"/>
<Line Style="{StaticResource LineStyle2}"/> <Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/StatutPage" FilterImageName="eyeglasses.png" <local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="StatutPage" FilterImageName="eyeglasses.png"
FilterName="Statut de lecture"/> FilterName="Statut de lecture"/>
<Line Style="{StaticResource LineStyle2}"/> <Line Style="{StaticResource LineStyle2}"/>
<local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="/MainPage/LikePage" FilterImageName="heart_fill.png" <local:ContentViewFilter Command="{Binding Navigateto}" CommandParameter="LikePage" FilterImageName="heart_fill.png"
FilterName="Favoris"/> FilterName="Favoris"/>
</StackLayout> </StackLayout>
<Line BackgroundColor="{StaticResource LineColor1}"/> <Line BackgroundColor="{StaticResource LineColor1}"/>

@ -5,6 +5,7 @@
x:Class="PocketBook.TousPage" x:Class="PocketBook.TousPage"
Shell.NavBarIsVisible="True" Shell.NavBarIsVisible="True"
Title="Tous" Title="Tous"
x:Name="root"
Shell.ForegroundColor="{StaticResource Primary}"> Shell.ForegroundColor="{StaticResource Primary}">
<ContentPage.Resources> <ContentPage.Resources>
@ -26,21 +27,13 @@
<ScrollView VerticalOptions="StartAndExpand"> <ScrollView VerticalOptions="StartAndExpand">
<VerticalStackLayout> <VerticalStackLayout>
<local:TitledAuthor NameText="Alain Damasio"/> <local:TitledAuthor NameText="Alain Damasio"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="La horde du contrevent" AutorName="Alain Damasio" BookStatus="Non lu"/> <CollectionView ItemsSource="{Binding Manager.Books}">
<Line Style="{StaticResource LineStyle3}"/> <CollectionView.ItemTemplate>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="La zone du dehors" AutorName="Alain Damasio" BookStatus="Terminé"/> <DataTemplate>
<local:TitledAuthor NameText="Cixin Lui"/> <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 Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="L'équateur d'Einstein" AutorName="Cixin Liu" BookStatus="Terminé"/> </DataTemplate>
<Line Style="{StaticResource LineStyle3}"/> </CollectionView.ItemTemplate>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="La forêt sombre" AutorName="Cixin Liu" BookStatus="Terminé"/> </CollectionView>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="Le problème à trois corps" AutorName="Cixin Liu" BookStatus="Terminé"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="L'équateur d'Einstein" AutorName="Cixin Liu" BookStatus="Terminé"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="La forêt sombre" AutorName="Cixin Liu" BookStatus="Terminé"/>
<Line Style="{StaticResource LineStyle3}"/>
<local:ContentViewBook Command="{Binding NavigateCommandBooks.Navigateto}" CommandParameter="/MainPage/TousPage/BookDetail" BookImage="buveurencre.jpg" BookName="Le problème à trois corps" AutorName="Cixin Liu" BookStatus="Terminé"/>
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView> </ScrollView>
</StackLayout> </StackLayout>

@ -1,6 +1,7 @@
using CommunityToolkit.Maui.Core; using CommunityToolkit.Maui.Core;
using CommunityToolkit.Maui.Views; using CommunityToolkit.Maui.Views;
using PocketBook.Applicative_VM; using PocketBook.Applicative_VM;
using ViewModel;
namespace PocketBook; namespace PocketBook;
@ -8,10 +9,12 @@ public partial class TousPage : ContentPage
{ {
public NavigatorVM NavigateCommandBooks { get; private set; } public NavigatorVM NavigateCommandBooks { get; private set; }
public ScanMenuVM ScanMenuVM { get; private set; } public ScanMenuVM ScanMenuVM { get; private set; }
public ManagerVM Manager { get; private set; }
public TousPage(NavigatorVM navigation) public TousPage(NavigatorVM navigation,ScanMenuVM scanMenuVM, ManagerVM manager)
{ {
ScanMenuVM = new ScanMenuVM(); ScanMenuVM = scanMenuVM;
Manager = manager;
NavigateCommandBooks = navigation; NavigateCommandBooks = navigation;
InitializeComponent(); InitializeComponent();
BindingContext = this; BindingContext = this;

@ -213,6 +213,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\MyToolkitMVVM\MyToolkitMVVM.csproj" /> <ProjectReference Include="..\MyToolkitMVVM\MyToolkitMVVM.csproj" />
<ProjectReference Include="..\ViewModel\ViewModel.csproj" />
<ProjectReference Include="..\Stub\Stub.csproj" />
</ItemGroup> </ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadDebuggerTimeoutExceptionPocketBookHideInfoBar="True" /></VisualStudio></ProjectExtensions> <ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadDebuggerTimeoutExceptionPocketBookHideInfoBar="True" /></VisualStudio></ProjectExtensions>

@ -4,11 +4,53 @@ using MyToolkitMVVM;
namespace ViewModel namespace ViewModel
{ {
public class BookVM : BaseViewModel<Book> public class BookVM : BaseViewModel<Book>
{ {
public BookVM() public string Title
{ {
get =>Model.Title;
set =>SetProperty(Model.Title,value,v=>Model.Title=v);
} }
}
public string Image
{
get => Model.ImageLarge;
set { }
}
public Status BookStatus
{
get => Model.Status;
set
{
SetProperty(Model.Status, value, v => Model.Status = v);
}
}
public List<Author> BookAuthors
{
get => Model.Authors;
set
{
SetProperty(Model.Authors, value, v => Model.Authors = v);
}
}
public string BookFirstAuthor { get; private set; }
public BookVM(Book 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";
}
}
} }

@ -2,18 +2,64 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Model; using Model;
using MyToolkitMVVM;
public class ManagerVM public class ManagerVM : BaseViewModel<Manager>
{ {
public Manager model { get; private set; } public ReadOnlyObservableCollection<BookVM> Books { get; set; }
private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>();
public RelayCommand<string> LoadBooks { get; private set; }
public ManagerVM(ILibraryManager libraryManager,IUserLibraryManager userLibraryManager) public ManagerVM(ILibraryManager libraryManager,IUserLibraryManager userLibraryManager)
:this(new Manager(libraryManager,userLibraryManager)) :this(new Manager(libraryManager,userLibraryManager))
{} {}
public ManagerVM(Manager model) public async void LoadBooksFromManager()
{
var result = await Model.GetBooksFromCollection(index, 10, "");
NbBook = (int)result.count;
books.Clear();
foreach (Book book in result.books)
{
books.Add(new BookVM(book));
}
}
public ManagerVM(Manager model) : base(model)
{
Model = model;
LoadBooks = new RelayCommand<string>(o => LoadBooksFromManager());
LoadBooks.Execute();
Books = new ReadOnlyObservableCollection<BookVM>(books);
}
public int Index
{
get => index;
set => SetProperty(ref index, value);
}
private int index;
public int Count
{
get => count;
set => SetProperty(ref count, value);
}
private int count;
public int NbBook
{ {
this.model = model; get => nbBook;
set => SetProperty(ref nbBook, value);
} }
private int nbBook;
} }

Loading…
Cancel
Save